HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_ubuntu_pro.cpython-38.pyc
U

Ӈg�6�@sLUdZddlZddlZddlZddlmZmZddlmZddl	m
Z
mZmZddl
mZddlmZddlmZdd	lmZed
dg�Zdd
gedgee�d�Zeed<e�e�ZdZdZdZe d�dd�Z!e d�dd�Z"d+ed�dd�Z#d,dd�Z$ed�dd �Z%e e&d!�d"d#�Z'e d�d$d%�Z(e d�d&d'�Z)e*eeedd(�d)d*�Z+dS)-z1ubuntu_pro: Configure Ubuntu Pro support services�N)�Any�List)�urlparse)�performance�subp�util)�Cloud)�Config)�
MetaSchema)�PER_INSTANCEzubuntu-advantageZubuntu_advantageZ
cc_ubuntu_proZubuntu�
ubuntu_pro)�idZdistrosZ	frequencyZactivate_by_schema_keys�meta�REDACTEDzUUnable to determine if this is an Ubuntu Pro instance. Fallback to normal Pro attach.)Z
http_proxyZhttps_proxyZglobal_apt_http_proxyZglobal_apt_https_proxyZua_apt_http_proxyZua_apt_https_proxy)�pro_sectioncCs�d|krdS|d}t|t�s@dt|�j��}t�|�t|��d|krLdS|d}t|t�s�dt|�j��}t�|�t|��dS)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�r�@/usr/lib/python3/dist-packages/cloudinit/config/cc_ubuntu_pro.py�validate_schema_features*s 
�

�
r)�
pro_configc
Cs�g}t|���D]z\}}|tkr0t�d|�qn
|dkr:qz&t|�}|jdkr^|�d|���Wqtt	fk
r�|�d|���YqXq|r�t	d�
d�|����dS)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)ZhttpZhttpsz-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�warningrZscheme�append�AttributeError�
ValueError�format�join)r�errors�key�valueZ
parsed_urlrrr�supplemental_schema_validationEs,
�
��r-cCs�|dkrdSt|t�s,tdt|�j�d���t|�g}t|���D�]\}}d}i}|dkrxt�	d|�ddd|g}nh|�d�}t�	d|�t
�d	|�r�|�d
t
�|���}n|�d
|��}ddd|g}d|dd
�|gi}zt
j
|f|�WqDt
jk
�rD}z0t|�}	|dk	�r&|	�|t�}	|�||	f�W5d}~XYqDXqD|�r�|D]\}
}t�d|
|��qRtd�d�dd�|D�����dS)Nz+ubuntu_pro: config should be a dict, not a z%; skipping enabling config parameterszDisabling Pro config for %s�pro�configZunsetz	=REDACTEDzEnabling Pro config %sz\s�=�set�	logstring���z#Failure enabling/disabling "%s":
%sz3Failure enabling/disabling Ubuntu Pro config(s): {}�, css|]\}}d�|�VqdS)z"{}"N)r()�.0�param�_rrr�	<genexpr>�sz!set_pro_config.<locals>.<genexpr>)rrrrrr-r!r"r�debug�re�search�escaper�ProcessExecutionError�str�replacerr%r$r(r))r�
enable_errorsr+r,Zredacted_key_valueZsubp_kwargsZ
config_cmd�	key_value�e�err_msgr6rrrr�set_pro_configlsH
�

"��rDc
Csz|dkrg}n<t|t�r*t�d�|g}n t|t�sJt�dt|�j�g}|r\ddd|g}n
dd|g}|dd�tg}t�dd	�	|��zt
j
|d
dh|d�WnTt
jk
r�}z4t|��|t�}d
|��}t
�t|�t|�|�W5d}~XYnX|�sdSdddddg|}zt
j
|dd
dhd�\}}	Wn:t
jk
�rj}ztdd�	|��|�W5d}~XYnXzt�|�}
Wn6tjk
�r�}ztd|���|�W5d}~XYnXg}|
�dg�D]2}|ddk�r�t�d|d��q�|�|��q�|�rvg}|D]^}|�d�}
|
dk	�r<|�|
�d|
�d|d��}nd |d!�d|d��}t
�t|��qtd"d�	|���dS)#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 servicesr.Zattachz--no-auto-enabler3zAttaching to Ubuntu Pro. %s� r�)�rcsr2zFailure attaching Ubuntu Pro:
�enablez--assume-yesz--format�jsonT�)ZcapturerGz!Error while enabling service(s): r4zPro response was not json: r*Zmessage_codezservice-already-enabledzService `%s` already enabled.�servicezFailure enabling `z`: �messagezFailure of type `rz(Failure enabling Ubuntu Pro service(s): )rr>rr$�listrrrr9r)rr=r?r�logexcrrI�loadsZJSONDecodeError�getr%)�tokenrHZ
attach_cmdZredacted_cmdrB�errr�cmdZ
enable_stdoutr7Zenable_respr@Zerror_servicesrKrrr�
configure_pro�s�
�
�

����


��rT��cloudcCszt�d�rdSz|j��Wn"tk
r>t�td��YnXz|j�dg�Wn"tk
rtt�td��YnXdS)z.Install ubuntu-advantage-tools if not present.r.NzPackage update failedzubuntu-advantage-toolsz(Failed to install ubuntu-advantage-tools)	rZwhichZdistroZupdate_package_sources�	ExceptionrrNrZinstall_packagesrUrrr�maybe_install_ua_tools�s
rX)r�returnc
Cs�t|�di��dd��}|r dSddlm}ddlm}z$tjddd	��|�}W5QRXWn>|k
r�}z t�	d
|�t�
t�WY�dSd}~XYnX|jS)NrrFr)�UserFacingError)�should_auto_attachz6Checking if the instance can be attached to Ubuntu Pro�always�Zlog_modez%Error during `should_auto_attach`: %s)rrP�uaclient.api.exceptionsrZZ4uaclient.api.u.pro.attach.auto.should_auto_attach.v1r[r�Timedrr9r$�ERROR_MSG_SHOULD_AUTO_ATTACH)rrrZr[�result�exrrr�_should_auto_attachs$��
rccCsZ|�d�}|s$d}t�|�t|��|�d�}|rDt�dd�|��t||�d�d�dS)NrQz8`ubuntu_pro.token` required in non-Pro Ubuntu instances.�enable_betaz<Ignoring `ubuntu_pro.enable_beta` services in Pro attach: %sr4rH)rQrH)rPrrrr9r)rT)rrQrrdrrr�_attach(s


�rec

Cs�ddlm}m}ddlm}m}|�d�}|�d�}|||d�}z(tjddd	��||d
�W5QRXWnn|k
r�|dk	s�|dk	r�t	�
d�YnB|k
r�}z$d|j��}	t	�|	�t
|	�|�W5d}~XYnXdS)
Nr)�AlreadyAttachedErrorrZ)�FullAutoAttachOptions�full_auto_attachrHrd)rHrdzAttaching 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^rfrZZ2uaclient.api.u.pro.attach.auto.full_auto_attach.v1rgrhrPrr_rr$rrr)
rrfrZrgrhrHrdrirbrrrr�_auto_attach7s(

��
rj)�name�cfgrV�argsrYcCs0d}tt�|��}|rRt|�dkr4tdd�|���t�dd�|��||d}d|krv|rnt�d|d�|d}|dkr�t�d|�dSt	|t
�s�d	t|�j��}t�
|�t|��d
|kr�d}t�
|�t|��t|�t|�d��t|�t�d
�t|��rt|�n|��dhk�s,t|�dS)NrJzLUnable to configure Ubuntu Pro. Multiple deprecated config keys provided: %sr4z^Deprecated configuration key(s) provided: %s. Expected "ubuntu_pro"; will attempt to continue.rrz;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 ZcommandszPDeprecated configuration "ubuntu-advantage: commands" provided. Expected "token"r/zETo discover more log info, please check /var/log/ubuntu-advantage.logr)rM�DEPRECATED_KEYS�intersection�lenrr)rr$r9rrrrrrXrDrPrrcrj�keysre)rkrlrVrmrZ
deprecatedrrrr�handleYs^�����
�
�
�

rr)N)N),�__doc__rIZloggingr:�typingrrZurllib.parserZ	cloudinitrrrZcloudinit.cloudrZcloudinit.configr	Zcloudinit.config.schemar
Zcloudinit.settingsrr1rnrMr�__annotations__Z	getLoggerrrrr`r#rrr-rDrTrXrrcrerjr>rrrrrr�<module>s<�
�
',
d"