Current File : //usr/lib/python3/dist-packages/cloudinit/config/__pycache__/cc_ubuntu_pro.cpython-312.pyc
�

Ӈg�6�
�r�UdZddlZddlZddlZddlmZmZddlmZddl	m
Z
mZmZddl
mZddlmZddlmZdd	lmZed
dg�Zdd
gedgee�zd�Zeed<ej4e�ZdZdZdZde fd�Z!de fd�Z"d$defd�Z#d$d�Z$defd�Z%de de&fd�Z'de fd�Z(de fd�Z)d e*d!eded"eddf
d#�Z+y)%z1ubuntu_pro: Configure Ubuntu Pro support services�N)�Any�List)�urlparse)�performance�subp�util)�Cloud)�Config)�
MetaSchema)�PER_INSTANCEzubuntu-advantage�ubuntu_advantage�
cc_ubuntu_pro�ubuntu�
ubuntu_pro)�id�distros�	frequency�activate_by_schema_keys�meta�REDACTEDzUUnable to determine if this is an Ubuntu Pro instance. Fallback to normal Pro attach.)�
http_proxy�https_proxy�global_apt_http_proxy�global_apt_https_proxy�ua_apt_http_proxy�ua_apt_https_proxy�pro_sectionc�L�d|vry|d}t|t�s8dt|�j��}tj|�t
|��d|vry|d}t|t�s8dt|�j��}tj|�t
|��y)N�featuresz.'ubuntu_pro.features' should be a dict, not a �disable_auto_attachzB'ubuntu_pro.features.disable_auto_attach' should be a bool, not a )�
isinstance�dict�type�__name__�LOG�error�RuntimeError�bool)rr�msgr s    �@/usr/lib/python3/dist-packages/cloudinit/config/cc_ubuntu_pro.py�validate_schema_featuresr+*s�����$���:�&�H��h��%���X��'�'�(�
*�	�	�	�	�#���3����H�,��"�#8�9���)�4�0���/�0�9�9�:�
<�	�	�	�	�#���3���
1��
pro_configc��g}t|j��D]U\}}|tvrtj	d|��%|��(	t|�}|jdvr|jd|����W|r)tdjdj|����y#ttf$r|jd|���Y��wxYw)a�Validate user-provided ua:config option values.

    This function supplements flexible jsonschema validation with specific
    value checks to aid in triage of invalid user-provided configuration.

    Note: It does not log/raise config values as they could be urls containing
    sensitive auth info.

    @param pro_config: Dictionary of config value under 'ubuntu_pro'.

    @raises: ValueError describing invalid values provided.
    z4Not validating unknown ubuntu_pro.config.%s propertyN)�http�httpsz-Expected URL scheme http/https for ua:config:zExpected a URL for ua:config:z$Invalid ubuntu_pro configuration:
{}�
)�sorted�items�KNOWN_PRO_CONFIG_PROPSr%�warningr�scheme�append�AttributeError�
ValueError�format�join)r-�errors�key�value�
parsed_urls     r*�supplemental_schema_validationr@Es����F��Z�-�-�/�0�A�
��U��,�,��K�K�F��
�
�
�]��	A�!�%��J�� � �(9�9��
�
�C�C�5�I���A�&��3�:�:�4�9�9�V�;L�M�
�	
����
�+�	A��M�M�9�#��?�@�	A�s�-B � #C�Cc�Z�|�yt|t�s"tdt|�j�d���t|�g}t
|j��D]�\}}d}i}|�tjd|�ddd|g}nd|�d�}tjd|�tjd	|�r|�d
tj|���}n|�d
|��}ddd|g}d|dd
|gzi}	tj|fi|����|rQ|D]\}
}tj'd|
|��tdj)dj+d�|D�����y#tj$rA}t|�}	|�|	j!|t"�}	|j%||	f�Yd}~��Id}~wwxYw)Nz+ubuntu_pro: config should be a dict, not a z%; skipping enabling config parameterszDisabling Pro config for %s�pro�config�unsetz	=REDACTEDzEnabling Pro config %sz\s�=�set�	logstring���z#Failure enabling/disabling "%s":
%sz3Failure enabling/disabling Ubuntu Pro config(s): {}�, c3�DK�|]\}}dj|����y�w)z"{}"N)r:)�.0�param�_s   r*�	<genexpr>z!set_pro_config.<locals>.<genexpr>�s����M�8�5�!�&�-�-��.�M�s� )r!r"r'r#r$r@r2r3r%�debug�re�search�escaper�ProcessExecutionError�str�replacerr7r5r:r;)r-�
enable_errorsr=r>�redacted_key_value�subp_kwargs�
config_cmd�	key_value�e�err_msgrLr&s            r*�set_pro_configr]ls�������j�$�'����z�"�+�+�,�-3�
3�
�	
�
#�:�.��M��Z�-�-�/�0�1�
��U�!�����=��I�I�3�S�9���7�C�8�J�$'�5�	�!2���I�I�.�0B�C��y�y���&�"�e�1�R�Y�Y�u�%5�$6�7�	�"�e�1�U�G�,�	���5�)�<�J�&�
�3�B��;M�:N�(N�O�K�	1��I�I�j�0�K�0�!1�,�)�	N�L�E�5��K�K�>��u�M�	N��A�H�H��	�	�M�}�M�M�
�
�	
����)�)�	1��!�f�G�!�-�!�/�/�%��:��� � �#�w��0�0��		1�s�*E�F*�)6F%�%F*c�0�|�g}ndt|t�rtjd�|g}n;t|t�s+tjdt|�j�g}|rddd|g}ndd|g}|ddtgz}tjdd	j|��	tj|d
dh|��|sygd�|z}	tj|dd
dh��\}}		t!j"|�}
g}|
j'dg�D]5}|ddk(rtjd|d��%|j)|��7|r~g}|D]Z}|j'd�}
|
�|j)|
�d|
�d|d��}nd|d�d|d��}tjt|��\tddj|�z��y#tj$rO}t|�j|t�}d
|��}tjt|�t|�|�d}~wwxYw#tj$r#}tddj|�z�|�d}~wwxYw#t j$$r}td|���|�d}~wwxYw) z=Call ua command line client to attach and/or enable services.NzNubuntu_pro: enable should be a list, not a string; treating as a single enablezIubuntu_pro: enable should be a list, not a %s; skipping enabling servicesrB�attachz--no-auto-enablerHzAttaching to Ubuntu Pro. %s� r�)�rcsrGzFailure attaching Ubuntu Pro:
)rB�enablez--assume-yesz--format�jsonT�)�capturerbz!Error while enabling service(s): rIzPro response was not json: r<�message_codezservice-already-enabledzService `%s` already enabled.�servicezFailure enabling `z`: �messagezFailure of type `r#z(Failure enabling Ubuntu Pro service(s): )r!rTr%r5�listr#r$rrOr;rrSrUr�logexcr'rd�loads�JSONDecodeError�getr7)�tokenrc�
attach_cmd�redacted_cmdr[�errr)�cmd�
enable_stdoutrM�enable_resprV�error_servicesrhs              r*�
configure_prorw�s���
�~���	�F�C�	 ����
5�	
����
���
%����
0���L�!�!�	
�
����X�'9�5�A�
��X�u�-�
��c�r�?�h�Z�/�L��I�I�+�S�X�X�l�-C�D�'��	�	�*�1�a�&�L�A���
?�&�
H�C���9�9�S�$�Q��F�C��
�q���j�j��/��<!#�M����x��,�"���~��";�;��I�I�5�s�9�~�F�����S�!�	"��$&�� �	"�C��g�g�i�(�G��"��%�%�g�.�*�7�)�3�s�9�~�6F�G��)�#�f�+��c�#�i�.�9I�J���K�K��S�!�	"��6��i�i��'�
(�
�	
���o�%�%�'��!�f�n�n�U�H�-��/��u�5�����C����3��Q�&��	'���%�%���/�$�)�)�F�2C�C�
��	���������)�-��9�
��	���sI�+G�H5�.I.�H2�#A
H-�-H2�5I+�I&�&I+�.J�J�J�cloudc�@�tjd�ry	|jj�	|jjdg�y#t$rtjtd��wxYw#t$rtjtd��wxYw)z.Install ubuntu-advantage-tools if not present.rBNzPackage update failedzubuntu-advantage-toolsz(Failed to install ubuntu-advantage-tools)	r�which�distro�update_package_sources�	Exceptionrrkr%�install_packages)rxs r*�maybe_install_ua_toolsr�s����z�z�%����
���+�+�-��
���%�%�'?�&@�A��	�����C�0�1�
���
�����C�C�D�
��s�A�A8�%A5�8%B�returnc��t|jdi�jdd��}|ryddlm}ddlm}	t
jdd�	�5|�}ddd�|j
S#1swYj
SxYw#|$r9}tjd
|�tjt�Yd}~yd}~wwxYw)Nrr Fr)�UserFacingError)�should_auto_attachz6Checking if the instance can be attached to Ubuntu Pro�always��log_modez%Error during `should_auto_attach`: %s)r(rn�uaclient.api.exceptionsr��4uaclient.api.u.pro.attach.auto.should_auto_attach.v1r�r�Timedr%rOr5�ERROR_MSG_SHOULD_AUTO_ATTACH)rr r�r��result�exs      r*�_should_auto_attachr�s�������
�B�'�+�+�,A�5�I�����8��	�
�
�
�D��
�	*�(�)�F�		*��$�$�$�	*��$�$�$��	���	�	�9�2�>����0�1����s5�B�A/�B�/B�4B�B�C�/B?�?Cc��|jd�}|s"d}tj|�t|��|jd�}|r%tj	ddj|��t
||jd���y)Nroz8`ubuntu_pro.token` required in non-Pro Ubuntu instances.�enable_betaz<Ignoring `ubuntu_pro.enable_beta` services in Pro attach: %srIrc)rorc)rnr%r&r'rOr;rw)rror)r�s    r*�_attachr�(so���O�O�G�$�E��H���	�	�#���3����/�/�-�0�K���	�	�J��I�I�k�"�	
���k�o�o�h�&?�@r,c��ddlm}m}ddlm}m}|j
d�}|j
d�}|||��}	tjdd�	�5||�
�ddd�y#1swYyxYw#|$r|�|�tjd�YyYy|$r5}d|j��}	tj|	�t|	�|�d}~wwxYw)
Nr)�AlreadyAttachedErrorr�)�FullAutoAttachOptions�full_auto_attachrcr�)rcr�zAttaching to Ubuntu Pror�r�)�optionsz�The instance is already attached to Pro. Leaving enabled services untouched. Ignoring config directives ubuntu_pro: enable and enable_betaz!Error during `full_auto_attach`: )r�r�r��2uaclient.api.u.pro.attach.auto.full_auto_attach.v1r�r�rnrr�r%r5r)r&r')
rr�r�r�r�rcr�r�r�r)s
          r*�_auto_attachr�7s���N���_�_�X�
&�F��/�/�-�0�K�#����G�(�
�
�
�8�8�
L�	.��W�-�	.�	.�	.�����"�f�&8��K�K�6�
�'9��(�1�"�&�&��:���	�	�#���3��R�'��(�s;�A4�
A(�A4�(A1�-A4�1A4�4C�C�0C
�
C�name�cfg�argsc�F�d}ttj|��}|rXt|�dkDrt	ddj|�z��tjddj|��||d}d|vr |rtjd|d�|d}|�tjd|�yt|t�s8d	t|�j��}tj|�t	|��d
|vr"d}tj|�t	|��t|�t|j!d��t#|�tjd
�t%|�rt'|�y|j)�dhkst+|�yy)NrezLUnable to configure Ubuntu Pro. Multiple deprecated config keys provided: %srIz^Deprecated configuration key(s) provided: %s. Expected "ubuntu_pro"; will attempt to continue.rrz;Ignoring deprecated key %s and preferring ubuntu_pro configz=Skipping module named %s, no 'ubuntu_pro' configuration foundz%'ubuntu_pro' should be a dict, not a �commandszPDeprecated configuration "ubuntu-advantage: commands" provided. Expected "token"rCzETo discover more log info, please check /var/log/ubuntu-advantage.logr)rj�DEPRECATED_KEYS�intersection�lenr'r;r%r5rOr!r"r#r$r&rr]rnr+r�r��keysr�)r�r�rxr�r�
deprecatedr)s       r*�handler�Ys����K��o�2�2�3�7�8�J���z�?�Q���%�'+�y�y��'<�=��
�	���
@��I�I�j�!�	
�
�*�Q�-�(���s����K�K�M��1�
�
��,�'�����	�	�K��	
�	�
��T�
*���[�!�*�*�+�
-�	�	�	�	�#���3����[� �
 �	�	�	�	�#���3����5�!��;�?�?�8�,�-��[�)��I�I�O���;�'��[�!��
�
�
�J�<�
/����0r,)N),�__doc__rd�loggingrP�typingrr�urllib.parser�	cloudinitrrr�cloudinit.cloudr	�cloudinit.configr
�cloudinit.config.schemar�cloudinit.settingsrrFr�rjr�__annotations__�	getLoggerr$r%rr�r4r"r+r@r]rwrr(r�r�r�rTr��r,r*�<module>r�s&��8���	��!�-�-�!�#�.�+��)�+=�>�?����z�� ,�~��_�0E�E�	��j���g����!����&���� �$� �6$
�t�$
�N)
�s�)
�Xa
�H
�%�
� %�T�%�d�%�8A��A�(�d�(�DB��B�6�B�%�B�t�B��Br,