%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/uaclient/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/uaclient/__pycache__/livepatch.cpython-312.pyc

�

��>fh3�
�.�ddlZddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
ddlmZm
Z
mZmZmZddlmZmZmZmZmZmZddlmZddlmZdZd	Zd
ZdZej@�Z!ejDejFe$��Z%ejLGd�d
ejN��Z(Gd�de�Z)Gd�de�Z*Gd�de�Z+Gd�de�Z,de	e+fd�Z-de	e.de	e(fd�Z/Gd�dej`�Z1de	e(fd�Z2de.de.de.d e.de
e3e	e3ff
d!�Z4de.de.de.d e.d"e	ejde	e(fd#�Z5ed�$�de(fd%��Z6	d/d&e.d'e	ee7ddfd(�Z8			d0d)e	e.d*e	e.d'e	ee7ddfd+�Z9d,e.de	e.fd-�Z:de3fd.�Z;y)1�N)�	lru_cache)�List�Optional�Tuple)�event_logger�
exceptions�messages�system�util)�
BoolDataValue�
DataObject�Field�IncorrectTypeError�StringDataValue�	data_list)�state_files)�
serviceclientz
http-proxyzhttps-proxyz/snap/bin/canonical-livepatchz/v1/api/kernels/supportedc�R�eZdZe�Ze�Ze�Ze�Ze�Zy)�LivepatchSupportN)	�__name__�
__module__�__qualname__�object�	SUPPORTED�KERNEL_UPGRADE_REQUIRED�
KERNEL_EOL�UNSUPPORTED�UNKNOWN���4/usr/lib/python3/dist-packages/uaclient/livepatch.pyrr s&����I�$�h����J��(�K��h�Gr rc�X�eZdZededd��ededd��gZdeedee	fd�Z
y)	�LivepatchPatchFixStatus�nameF�Name��required�dict_key�patched�Patchedc� �||_||_y�N)r$r))�selfr$r)s   r!�__init__z LivepatchPatchFixStatus.__init__/s��
��	���r N)rrrrrr�fieldsr�str�boolr.rr r!r#r#)sD��
�f�o���G�
�i����K��F�
��s�m���$��r r#c��eZdZededd��edee�dd��ededd��gZdee	dee
edee	fd	�Zy
)�LivepatchPatchStatus�stateF�Stater&�fixes�Fixes�version�Versionc�.�||_||_||_yr,)r4r6r8)r-r4r6r8s    r!r.zLivepatchPatchStatus.__init__Ds����
���
���r N)rrrrrrr#r/rr0rr.rr r!r3r38su��
�g����I�
���-�.���		
�	�i��5�9�M�	�F����}����4�5�6���#��	r r3c�x�eZdZededd��ededd��ededd��gZdeedeedeefd	�Z	y
)�LivepatchStatusStatus�kernelF�Kernelr&�	livepatch�	Livepatch�	supported�	Supportedc�.�||_||_||_yr,)r=r?rA)r-r=r?rAs    r!r.zLivepatchStatusStatus.__init__`s�����"���"��r N)
rrrrrr3r/rr0r.rr r!r<r<Osp��
�h��%�(�K�
�� �� �		
�	���� �		
��F� #���
�#��0�1�#��C�=�	#r r<c�J�eZdZedee�dd��gZdeeefd�Z	y)�LivepatchStatus�statusF�Statusr&c��||_yr,)rF)r-rFs  r!r.zLivepatchStatus.__init__us����r N)
rrrrrr<r/rrr.rr r!rErEks;��
���+�,���		
��F����3�4�5�r rE�returnc��t�stjd�y	tjt
ddddg�\}}	tj|�}	tj|�}|j �t#|j �dkrtjd�y|j d
S#tj$rP}d|jvr$tj|j�Yd}~ytjd|��|�d}~wwxYw#tj$r"}tjd	||��Yd}~yd}~wwxYw#t$rtjd
|�YywxYw)Nz$canonical-livepatch is not installedrFz	--verbosez--format�jsonzMachine is not enabledz;canonical-livepatch returned error when checking status:
%s)�exc_infozPJSONDecodeError while parsing livepatch status, returning None. output was: "%s"z<canonical-livepatch status returned unexpected structure: %s�z!canonical-livepatch has no statusr)�is_livepatch_installed�LOG�debugr
�subp�
LIVEPATCH_CMDr�ProcessExecutionError�stderr�warningrK�loads�JSONDecodeErrorrE�	from_dictrrF�len)�out�_�e�status_json�status_roots     r!rFrF|s\��!�#��	�	�8�9������
�H�k�:�v�F�
���Q�	��j�j��o���%�/�/��<�����!�S��);�);�%<�q�%@��	�	�5�6�����a� � ��I�+�+�
�$�q�x�x�/��K�K����!�����J��	�	
����
���������
���		�	
����������J��	
���sG�!B8�D�E�8D�-D�=D�D�E�1E�E�E8�7E8�
status_strc���|dk(rtjS|dk(rtjS|dk(rtjS|dk(rtjS|dk(rtj
Sy)NrAzkernel-upgrade-requiredzkernel-end-of-life�unsupported�unknown)rrrrrr)r_s r!�(_convert_str_to_livepatch_support_statusrc�sm���[� ��)�)�)��.�.��7�7�7��)�)��*�*�*��]�"��+�+�+��Y���'�'�'�r c
�P�eZdZdZdededededeejdeefd�Zy	)
�UALivepatchClient�
livepatch_urlr8�flavor�arch�codename�
build_daterIc�D�|||||�|j�ndd�}|j�}	|jt||��}|jdk7r5t
j
d�t
j
|j�y|jjd�}
|
�t|
t�r"|
rtjStjSt!|
�S#t$r4}	t
j
d�t
j
|	�Yd}	~	yd}	~	wwxYw)Nrb)zkernel-version�flavour�architectureriz
build-date)�query_params�headersz4error while checking livepatch supported kernels API��z0livepatch supported kernels API was unsuccessfulrB)�	isoformatro�request_url�"LIVEPATCH_API_V1_KERNELS_SUPPORTED�	ExceptionrOrU�code�body�	json_dict�get�
isinstancer1rrrrc)r-r8rgrhrirjrnro�responser\�api_supported_vals           r!�is_kernel_supportedz%UALivepatchClient.is_kernel_supported�s��&�� � �*4�*@�
�$�$�&�i�

���,�,�.��		��'�'�2�)��(��H��=�=�C���K�K�J�K��K�K��
�
�&��$�.�.�2�2�;�?���$�
�3D�d�(K� �'�1�1�1�#�/�/�/�7�8I�J�J��#�	��K�K�N�O��K�K��N���	�s�C"�"	D�+*D�DN)	rrr�cfg_url_base_attrr0r�datetimerr|rr r!rere�s_��'��)K��)K��)K��	)K�
�)K��X�.�.�/�
)K�
�"�	#�)Kr rec�z�	t�}|�yt|j�S#tj$rYywxYwr,)rFrrSrcrA)�	lp_statuss r!�_on_supported_kernel_clir��sD����H�	����3�I�4G�4G�H�H���+�+����s�
$�:�:r8rgrhric��	tjj�}|��tjjtjj�t	jd��z
}t|j|kD|j|k(|j|k(|j|k(|j|k(g�r/|j�t j#d�d|jfSy#t$rd}Y��wxYw)zOCheck local cache of kernel support

    :return: (is_cache_valid, result)
    N�)�daysz-livepatch kernel support cache has None valueT)FN)r�livepatch_support_cache�readrtr~�now�timezone�utc�	timedelta�all�	cached_atr8rgrhrirArOrU)r8rgrhri�
cache_data�one_week_agos      r!�_on_supported_kernel_cacher��s���� �8�8�=�=�?�
����(�(�,�,����!�!�
����A�&�'����$�$�|�3��"�"�g�-��!�!�V�+����4�'��#�#�x�/�
�
��#�#�+����K�L��*�.�.�/�/���'���
��s�C1�1C?�>C?rjc��t�j|||||��}d}|tjk(rd}n|tjk(rd}t
jjtj|||||tjjtjj����|�tjd�|S)N)r8rgrhrirjTF)r8rgrhrirAr�z3livepatch kernel support API response was ambiguous)rer|rrrrr��write�LivepatchSupportCacheDatar~r�r�r�rOrU)r8rgrhrirjrA�cache_supporteds       r!�_on_supported_kernel_apir�s���"�#�7�7���
���8��I��O��$�.�.�.���	�&�2�2�	2����'�'�-�-��-�-�����%��'�'�+�+�H�,=�,=�,A�,A�B�
	
�	������I�J��r )�maxsizec�2�t�}|�tjd�|Stj�}|j
�|j�|j�%tjd�tjStj|j�}tj�j}dj!|j|j��}t#||j
||�\}}|rKtjd�|�tjS|rtj$S|stj&Stjd�t)||j
|||j*�}|�tjS|S)z�
    Checks CLI, local cache, and API in that order for kernel support
    If all checks fail to return an authoritative answer, we return None
    zusing livepatch cli for supportzHunable to determine enough kernel information to check livepatch supportz{major}.{minor})�major�minorzusing livepatch support cachezusing livepatch support api)r�rOrPr
�get_kernel_inforgr�r�rUrrr�standardize_arch_name�uname_machine_arch�get_release_info�series�formatr�rrr�rj)�cli_says�kernel_inforhri�lp_api_kernel_ver�is_cache_valid�
cache_says�api_sayss        r!�on_supported_kernelr�:sw��(�)�H����	�	�3�4����(�(�*�K����"����$����$����
&�	
� �'�'�'��%�%�k�&D�&D�E�D��&�&�(�/�/�H�)�0�0����{�'8�'8�1���
"<��;�-�-�t�X�"��N�J���	�	�1�2���#�+�+�+��#�-�-�-��#�/�/�/��I�I�+�,�'�����������H����'�'�'��Or �
protocol_type�retry_sleepsc�t�t�sytjtddj	|�g|��y)a�
    Unset livepatch configuration settings for http and https proxies.

    :param protocol_type: String either http or https
    :param retry_sleeps: Optional list of sleep lengths to apply between
        retries. Specifying a list of [0.5, 1] tells subp to retry twice
        on failure; sleeping half a second before the first retry and 1 second
        before the second retry.
    N�configz	{}-proxy=�r�)rNr
rQrRr�)r�r�s  r!�unconfigure_livepatch_proxyr�vs1��"�#��
�K�K�	��+�"4�"4�]�"C�D�!�r �
http_proxy�https_proxyc�P�ddlm}|s|r=tjtj
j
|j���|r-tjtddj
|�g|��|r.tjtddj
|�g|��yy)	a�
    Configure livepatch to use http and https proxies.

    :param http_proxy: http proxy to be used by livepatch. If None, it will
                       not be configured
    :param https_proxy: https proxy to be used by livepatch. If None, it will
                        not be configured
    :@param retry_sleeps: Optional list of sleep lengths to apply between
                               snap calls
    r)�LivepatchEntitlement)�servicer�z
http-proxy={}r�zhttps-proxy={}N)�uaclient.entitlementsr��event�infor	�SETTING_SERVICE_PROXYr��titler
rQrR)r�r�r�r�s    r!�configure_livepatch_proxyr��s���;��[�
�
�
��*�*�1�1�,�2�2�
2�
�	
�����
�H�o�&<�&<�Z�&H�I�%�	
�
����
�H�&6�&=�&=�k�&J�K�%�	
�r �keyc�*�tjtdg�\}}tjdj|�|tj�}|r|jd�nd}|rtjdd|�}|r|j�SdS)z�
    Gets the config value from livepatch.
    :param key: can be any valid livepatch config option
    :return: the value of the livepatch config option, or None if not set
    r�z
^{}: (.*)$rMNz\"(.*)\"z\g<1>)
r
rQrR�re�searchr��	MULTILINE�group�sub�strip)r�rZr[�match�values     r!�get_config_option_valuer��su���[�[�-��2�
3�F�C���I�I�l�)�)�#�.��R�\�\�B�E�#�E�K�K��N��E�����{�H�e�4��!�5�;�;�=�+�t�+r c�8�tjt�duSr,)r
�whichrRrr r!rNrN�s���<�<�
�&�d�2�2r r,)NNN)<r~�enumrK�loggingr��	functoolsr�typingrrr�uaclientrrr	r
r�uaclient.data_typesrr
rrrr�uaclient.filesr�
uaclient.httpr�HTTP_PROXY_OPTION�HTTPS_PROXY_OPTIONrRrs�get_event_loggerr��	getLogger�replace_top_level_logger_namerrO�unique�Enumrr#r3r<rErFr0rc�UAServiceClientrer�r1r�r�r��floatr�r�r�rNrr r!�<module>r�sk������	��(�(�E�E���'�'� ��"��/�
�%@�"�%��%�%�'���g���:��:�:�8�D�E������t�y�y��
���j���:��.#�J�#�8�j��"-!��.�/�-!�`
���
�
�
���
� ,K�
�5�5�,K�^I�(�+;�"<�I��
����%(��47��
�4��$��� ��>"�
�"��"��"��	"�
��*�*�+�"����
"�J�4��8�-�8��8�x?C����&.�t�E�{�&;��	��*!%�!%�*.�"
���
�"
��#��"
��4��;�'�"
�
�	"
�J,��,��#��,�3��3r 

Zerion Mini Shell 1.0