HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/uaclient/cli/__pycache__/enable.cpython-38.pyc
U

���hAK�@s�ddlZddlZddlmZmZmZmZmZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZmZddlmZmZddlmZmZmZddlmZmZddlmZddlm Z dd	l!m"Z"m#Z#m$Z$dd
l%m&Z&ddl'm(Z(e�)e�*e+��Z,edd
e-fde-fdeee.effg�Z/e
j0e.e-d�dd�Z1d:e
j0e-ee	j2d�dd�Z3e
j0e.eeeee.e.e.d�dd�Z4e-ee.efee.ee.eee.efeee.efe-d�dd�Z5e
j0e.e.e-e-e-eee.eeeee/d�
dd�Z6e j7e j8e �9e j:�e;d�d d!����Z<e$d"ej=ej>e<e&j?d#e#e"d$ej@jAd%�BejCe
�0�d&��d'�d(d)d*�e"d+ejDd,d-�e"d.ejEjAd"d/�d,d-�e"d0ejFd,d-�e"d1ejGd,d-�e"d2ejHjAd3d4�d(d3d5gd3d6�e"d7ejId(d-�gd8�gd9�ZJdS);�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)�
machine_token�_EnableOneServiceResult�success�needs_reboot�error)�cfg�variant�
assume_yesc
Cstt�|�}t�|�}t�||���}|s6|tj�dSt	|�j
}t|�j}|D] }	t
||	j|d||d||d�	qNdS)NF)	r#�ent_namer$�access_onlyr%�json_output�
extra_args�enabled_services�all_dependencies)r�&create_interactive_only_print_functionrZget_machine_token_filer	Zget_enabled_by_default_servicesr
rZNO_SERVICES_TO_AUTO_ENABLErr*r�services�_enable_one_service�name)
r#r$r%r(�interactive_only_printZmachine_token_fileZservices_to_be_enabledr*r+Zenable_by_default_service�r1�5/usr/lib/python3/dist-packages/uaclient/cli/enable.py�_auto_enable_services0s2�
�


�r3)r#r'�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'r)FNzcli.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)r4r7r5r Zfail_reason�er9r1r1r2�_enable_landscapeSs>
����rA)r#r8r+r*r6r$�
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�qSr1�r/��.0�sr1r1r2�
<listcomp>�sz2prompt_for_dependency_handling.<locals>.<listcomp>c3s|]}|j�kr|VqdS�NrCrD)r8r1r2�	<genexpr>�s
z1prompt_for_dependency_handling.<locals>.<genexpr>csg|]}|j�kr|j�qSr1rCrD��enabled_service_namesr1r2rG�s
�csg|]}|j�kr|j�qSr1rCrDrJr1r2rG�s
�z features.block_disable_on_enable)rZ
path_to_value)�service_being_enabled�incompatible_service)�msg)rL�required_servicec3s,|]$}|j�kr|jr|j�kr|VqdSrH�r/�variant_enabled�variant_namerD)r8r$r1r2rI�s


�)�nextZincompatible_withZ
depends_onrZis_config_value_truer#r
Z	get_titlerZINCOMPATIBLE_SERVICE�formatZprompt_for_confirmationrZIncompatibleServiceStopsEnableZREQUIRED_SERVICEZRequiredServiceStopsEnablerR)r#r8r+r*r6r$rBZincompatible_servicesZrequired_servicesZdependenciesrMZcfg_block_disable_on_enableZincompatible_service_titleZuser_msgrOZrequired_service_titlerQZto_be_enabled_titleZenabled_variant_titler1)rKr8r$r2�prompt_for_dependency_handlings�	�
�
����������
���
��rU�r(�
json_response�processed_services�failed_services�errors�warningsr cCs^|rZ|��|��|rdnd|d<||d<||d<||d<||d<ttj|tjdd	��dS)
Nr Zfailure�resultrXrYrZr[T)�clsZ	sort_keys)�sort�print�json�dumpsrZDatetimeAwareJSONEncoderrVr1r1r2�_print_json_output�s	��rb)
r#r&r$r'r%r(r)r*r+�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)r$r'r)c3s0|](}|j�kr�r$|jr|j�kr|VqdSrHrPrD�Z	real_namer$r1r2rIs

�z&_enable_one_service.<locals>.<genexpr>)�titleFr8)�typer8r>�message_code)r r!r")r6r$rB)r%r5)r)r4)r8r$r')r4�r#�install)Z	operationTr9�codere�additional_info�rfr8r>rgrk)rr,r
Zentitlement_factoryr/rerSrZALREADY_ENABLEDrTrNZ
ENABLE_FAILEDrrUr�UbuntuProError�LOGZ	exceptionZCLIEnableDisableProgressrArrrZACCESS_ENABLED_TMPLZENABLED_TMPLr;ZENABLE_REBOOT_REQUIRED_TMPLr?rk�msg_code)r#r&r$r'r%r(r)r*r+r0ZentZ	ent_titleZalready_enabledrNr@r7Z
enable_resultr!r>r9Zerr_code�err_msgZerr_infor1rdr2r.�s����	�
���
	

��
���
����
�
��
��r.)rccKs�g}g}g}g}tjdd�}|jdk}t�|�}	t|dd�}
|j}|j}|j}
|
rd|rdt	j
ddd��|
rz|
rzt	j
dd	d��|r�|
r�t	j
dd	d��|	tj�zt
j|dd
�WnDt	jt	jfk
r�tjddd
�|�dtjjtjjd��YnXt|�j�s@t	��}|	|j�|�d|j|jd��t||||||dd�dS|
�rVt|dd|d�St|dg�}|�spt	���t�||�\}}t |�j!}t"|�j#}d}t�$||�D]n}t%|||
||||�&d�||�	}|j'�r�|�|�|j(�rd|d<n&d}|�|�|j)dk	�r�|�|j)��q�|�rZd}||7}tj*||d�}|	|j�|�dd|j|j|j+d��t
�,|�}|�-�t|||||||d�|�r�dSdS)z^Perform the enable action on a named entitlement.

    @return: 0 on success, 1 otherwise
    F)Z_schema_versionr!r`r$��
--access-only�	--variant)Zoption1Zoption2�--auto)�verbosezFailed to refresh contractT)�exc_info�system)rfr>rg)r �)r#r$r%r(r8r)r!Nrhrlr).rZJSON_SCHEMA_VERSIONrTrr,�getattrr'r%�autorZInvalidOptionCombinationrZREFRESH_CONTRACT_ENABLEr	ZrefreshZConnectivityErrorrmrnZwarning�appendZE_REFRESH_CONTRACT_FAILURErNr/rZis_attached_and_contract_validZContractExpiredErrorrorbr3ZNoServicesToEnabler
Zget_valid_entitlement_namesrr*rr-Zorder_entitlements_for_enablingr.�getr r!r"Z*create_enable_entitlements_not_found_errorrkZUAContractClientZupdate_activity_token)�argsr#�kwargsrXrYrZr[rWr(r0r$r'r%rzZexpired_err�namesZentitlements_foundZentitlements_not_foundr*r+Zretr&r\�errZcontract_clientr1r1r2�
action_enable�s�
����
��

���	�
�

��


�
��

�
r�r<�r8z, rh)ZoptionsZstore�*)�help�action�nargsrr�
store_true)r�r�z--assume-yes)Zcommandrtz--betaz--formatZcli)�defaultr`)r�r��choicesr�rs)Z	arguments)r�Zdescriptionr�Z
help_categoryZ
help_positionZargument_groups)N)Kr`Zlogging�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.parserrZuaclient.filesrZ	getLoggerZreplace_top_level_logger_name�__name__rn�bool�strrZUAConfigr3ZAbstractProgressrArUrbr.Zverify_json_format_argsZassert_rootZassert_attachedZ&_raise_enable_disable_unattached_error�intr�ZCLI_ROOT_ENABLEZCLI_ENABLE_DESCZ
QUICKSTARTZCLI_ENABLE_SERVICErT�joinZvalid_servicesZCLI_ENABLE_ACCESS_ONLYZCLI_ASSUME_YESZCLI_ENABLE_AUTOZCLI_ENABLE_BETAZCLI_FORMAT_DESCZCLI_ENABLE_VARIANTZenable_commandr1r1r1r2�<module>s�0���'��-�]
�
�#
���
����������