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: //usr/lib/python3/dist-packages/uaclient/cli/__pycache__/enable.cpython-38.pyc
U

��JhD�@s�ddlZddlZddlmZmZmZmZmZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZmZddlmZmZddlmZmZmZddlmZmZddlmZddlm Z dd	l!m"Z"m#Z#m$Z$dd
l%m&Z&e�'e�(e)��Z*edde+fd
e+fdeee,effg�Z-d5e
j.e+ee	j/d�dd�Z0e
j.e,eeeee,e,e,d�dd�Z1e+ee,efee,ee,eee,efeee,efe+d�dd�Z2e
j.e,e,e+e+e+eee,eeeee-d�
dd�Z3e j4e j5e �6e j7�e8d�dd����Z9e$dej:ej;e9e&j<de#e"d ej=j>d!�?ej@e
�.�d"��d#�d$d%d&�e"d'ejAj>dd(�d)d*�e"d+ejBd)d*�e"d,ejCd)d*�e"d-ejDj>d.d/�d$d.d0gd.d1�e"d2ejEd$d*�gd3�gd4�ZFdS)6�N)�Any�Dict�List�
NamedTuple�Optional)
�api�config�contract�entitlements�event_logger�
exceptions�lock�messages�status�util)�ServiceWithDependencies�
_dependencies)�
EnableOptions�EnableResult�_enable)�EnabledService�_enabled_services)�_is_attached)�cli_util)�ProArgument�ProArgumentGroup�
ProCommand)�HelpCategory�_EnableOneServiceResult�success�needs_reboot�error)�cfg�access_only�progress_objectc

Cs�t�|�}tj|d||d�}d}d}z,tjdd��|j|d�\}}W5QRXWn.tk
r~}zt��|�W5d}~XYnX|s�|dk	r�|j	dk	r�|j	}	nt
j}	tj
d|	d��tdggdgd	�S)
a
    Landscape gets special treatment because it currently not supported by our
    enable API. This function is a temporary workaround until we have a proper
    API for enabling landscape, which will happen after Landscape is fully
    integrated with the contracts backend.
    �	landscape)�called_namer#�
extra_argsFNzcli.enable._enable_landscape)Zlock_holder)�progress)�service�reason)�enabledZdisabled�reboot_requiredr)rZProgressWrapperr
ZLandscapeEntitlementr
Z	RetryLock�enable�	ExceptionZclear_lock_file_if_present�messagerZGENERIC_UNKNOWN_ISSUEr�EntitlementNotEnabledErrorr)
r"r#r'r$r(r%rZfail_reason�er*�r2�5/usr/lib/python3/dist-packages/uaclient/cli/enable.py�_enable_landscape/s>
����r4)r"r)�all_dependencies�enabled_servicesr&�variant�
service_titlecs�g}g}dd�|D��t�fdd�|D�d�}	|	dk	r^�fdd�|	jD�}�fdd�|	jD�}|D]N}
tj|jdd�}t�||
�}tj	j
||d	�}
|s�tj|
d
�sbtj
||d	��qb|D]:}t�||�}tjj
||d�}
tj|
d
�s�tj||d��q�t��fdd�|D�d�}|dk	�r��dk	�r�t�|���}t�|�|j�}tj|jdd�}tj	j
||d	�}
|�srtj|
d
��s�tj
||d	��dS)
NcSsg|]
}|j�qSr2��name��.0�sr2r2r3�
<listcomp>fsz2prompt_for_dependency_handling.<locals>.<listcomp>c3s|]}|j�kr|VqdS�Nr9r;)r)r2r3�	<genexpr>is
z1prompt_for_dependency_handling.<locals>.<genexpr>csg|]}|j�kr|j�qSr2r9r;��enabled_service_namesr2r3r>ls
�csg|]}|j�kr|j�qSr2r9r;rAr2r3r>qs
�z features.block_disable_on_enable)rZ
path_to_value)�service_being_enabled�incompatible_service)�msg)rC�required_servicec3s,|]$}|j�kr|jr|j�kr|VqdSr?�r:�variant_enabled�variant_namer;)r)r7r2r3r@�s


�)�nextZincompatible_withZ
depends_onrZis_config_value_truer"r
Z	get_titlerZINCOMPATIBLE_SERVICE�formatZprompt_for_confirmationrZIncompatibleServiceStopsEnableZREQUIRED_SERVICEZRequiredServiceStopsEnablerI)r"r)r5r6r&r7r8Zincompatible_servicesZrequired_servicesZdependenciesrDZcfg_block_disable_on_enableZincompatible_service_titleZuser_msgrFZrequired_service_titlerHZto_be_enabled_titleZenabled_variant_titler2)rBr)r7r3�prompt_for_dependency_handling[s�	�
�
����������
���
��rL��json_output�
json_response�processed_services�failed_services�errors�warningsrcCs^|rZ|��|��|rdnd|d<||d<||d<||d<||d<ttj|tjdd	��dS)
NrZfailure�resultrPrQrRrST)�clsZ	sort_keys)�sort�print�json�dumpsrZDatetimeAwareJSONEncoderrMr2r2r3�_print_json_output�s	��rZ)
r"�ent_namer7r#�
assume_yesrNr'r6r5�returnc	s�t�|�}	tj||�||d�}
|
j�|
j}t��fdd�|D�d�}|dk	r�tjj	|d�}
|	|
j
�|	tjj	|d��tddd||
j
|
jd�d�S|�szt
|�|||�|d	�Wn^tjk
�r}z<t�|�|	|j
�|	tjj	|d��tdddd�WY�Sd}~XYnXz�|�r d}ntj|d
�}�dk�rHt||||d�}ntt|�|d
�||d�}tj|d�|�r�|	tjj	|d��n|	tjj	|d��|j}|�r�|	tjj	dd��|jD]}|	|��q�td|dd�WStjk
�rZ}z^|jd}|d}|d}|d}|	|�|	tjj	|d��tddd||||d�d�WY�Sd}~XYnftjk
�r�}zD|	|j
�|	tjj	|d��tddd||j
|j|jd�d�WY�Sd}~XYnXdS)N)r7r#r'c3s0|](}|j�kr�r$|jr|j�kr|VqdSr?rGr;�Z	real_namer7r2r3r@�s

�z&_enable_one_service.<locals>.<genexpr>)�titleFr))�typer)r/�message_code)rr r!)r&r7r8)r\r%)r'r$)r)r7r#)r$�r"�install)Z	operationTr*�coder_�additional_info�r`r)r/rare)r�&create_interactive_only_print_functionr
Zentitlement_factoryr:r_rJrZALREADY_ENABLEDrKrEZ
ENABLE_FAILEDrrLr�UbuntuProError�LOGZ	exceptionZCLIEnableDisableProgressr4rrrZACCESS_ENABLED_TMPLZENABLED_TMPLr,ZENABLE_REBOOT_REQUIRED_TMPLr0re�msg_code)r"r[r7r#r\rNr'r6r5�interactive_only_printZentZ	ent_titleZalready_enabledrEr1r(Z
enable_resultr r/r*Zerr_code�err_msgZerr_infor2r^r3�_enable_one_service�s����	�
���
	

��
���
����
�
��
��rm)r]cKs6g}g}g}g}tjdd�}|jdk}t�|�}	t|dd�}
|j}|j}|
r^|r^tj	ddd��|	t
j�zt�
|�WnDtjtjfk
r�tjd	d
d�|�dt
jjt
jjd
��YnXt|�j�s
t��}
|	|
j�|�d|
j|
jd
��t||||||dd�dSt|dg�}t�||�\}}t|�j}t|�j }d
}t�!||�D]n}t"|||
||||�#d�||�	}|j$�r�|�|�|j%�r�d
|d<n&d}|�|�|j&dk	�rJ|�|j&��qJ|�rd}||7}tj'||d�}|	|j�|�dd|j|j|j(d��t�)|�}|�*�t|||||||d�|�r2dSdS)z^Perform the enable action on a named entitlement.

    @return: 0 on success, 1 otherwise
    F)Z_schema_versionr rXr7��
--access-only�	--variant)Zoption1Zoption2zFailed to refresh contractT)�exc_info�system)r`r/ra)r�r)r'r Nrbrfr)+rZJSON_SCHEMA_VERSIONrKrrg�getattrr#r\rZInvalidOptionCombinationrZREFRESH_CONTRACT_ENABLEr	ZrefreshZConnectivityErrorrhriZwarning�appendZE_REFRESH_CONTRACT_FAILURErEr:rZis_attached_and_contract_validZContractExpiredErrorrjrZr
Zget_valid_entitlement_namesrr6r�servicesZorder_entitlements_for_enablingrm�getrr r!Z*create_enable_entitlements_not_found_errorreZUAContractClientZupdate_activity_token)�argsr"�kwargsrPrQrRrSrOrNrkr7r#r\Zexpired_err�namesZentitlements_foundZentitlements_not_foundr6r5Zretr[rT�errZcontract_clientr2r2r3�
action_enableus��
��
��

���	
�

��


�
��

�
r|r-�r)z, rb)ZoptionsZstore�+)�help�action�nargsz--assume-yes)Zcommand�
store_true)rr�roz--betaz--formatZcli)�defaultrX)rr��choicesr�rp)Z	arguments)rZdescriptionr�Z
help_categoryZ
help_positionZargument_groups)N)GrXZlogging�typingrrrrrZuaclientrrr	r
rrr
rrrZ+uaclient.api.u.pro.services.dependencies.v1rrZ%uaclient.api.u.pro.services.enable.v1rrrZ-uaclient.api.u.pro.status.enabled_services.v1rrZ(uaclient.api.u.pro.status.is_attached.v1rZuaclient.clirZuaclient.cli.commandsrrrZuaclient.cli.parserrZ	getLoggerZreplace_top_level_logger_name�__name__ri�bool�strrZUAConfigZAbstractProgressr4rLrZrmZverify_json_format_argsZassert_rootZassert_attachedZ&_raise_enable_disable_unattached_error�intr|ZCLI_ROOT_ENABLEZCLI_ENABLE_DESCZ
QUICKSTARTZCLI_ENABLE_SERVICErK�joinZvalid_servicesZCLI_ASSUME_YESZCLI_ENABLE_ACCESS_ONLYZCLI_ENABLE_BETAZCLI_FORMAT_DESCZCLI_ENABLE_VARIANTZenable_commandr2r2r2r3�<module>s�0����-�]
�
�#
���
���������