HEX
Server: nginx/1.28.3
System: Linux lightweb-s1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64
User: dawonefr-98 (1071)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/uaclient/cli/__pycache__/enable.cpython-310.pyc
o

���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/de
j0de.de-fdd�Z1	dFde
j0de-dee	j2fdd�Z3de
j0de.deedeede.de.de.fdd�Z4d e-d!ee.efd"ee.d#ee.d$eee.efd%eee.efd
e-fd&d'�Z5de
j0d(e.de.de-de-d e-d)eee.deedeed*e/fd+d,�Z6e j7e j8e �9e j:�d*e;fd-d.����Z<e$d/ej=ej>e<e&j?d0e#e"dej@jAd1�BejCe
�0�d2��d3�d4d5d6�e"d7ejDd8d9�e"d:ejEjAd/d;�d8d9�e"d<ejFd8d9�e"d=ejGd8d9�e"d>ejHjAd?d@�d4d?dAgd?dB�e"dCejId4d9�gdD�gdE�ZJdS)G�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�||���}|s|tj�dSt	|�j
}t|�j}|D]}	t
||	j|d||d||d�	q'dS)NF)	r#�ent_namer$�access_onlyr%�json_output�
extra_args�enabled_services�all_dependencies)r�&create_interactive_only_print_functionr�get_machine_token_filer	�get_enabled_by_default_servicesr
r�NO_SERVICES_TO_AUTO_ENABLErr*r�services�_enable_one_service�name)
r#r$r%r(�interactive_only_print�machine_token_file�services_to_be_enabledr*r+�enable_by_default_service�r7�5/usr/lib/python3/dist-packages/uaclient/cli/enable.py�_auto_enable_services0s2�
�


��r9r'�progress_objectc

Cs�t�|�}tj|d||d�}d}d}z tjdd��|j|d�\}}Wd�n1s,wYWntyD}zt��|�d}~ww|s^|durT|j	durT|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)�lock_holder)�progress)�service�reason)�enabled�disabled�reboot_requiredr)r�ProgressWrapperr
�LandscapeEntitlementr
�	RetryLock�enable�	Exception�clear_lock_file_if_present�messager�GENERIC_UNKNOWN_ISSUEr�EntitlementNotEnabledErrorr)
r#r'r)r:r>r;r �fail_reason�er@r7r7r8�_enable_landscapeSs>
�������
�rOr?r+r*r<�
service_titlecs�g}g}dd�|D��t�fdd�|D�d�}	|	dur/�fdd�|	jD�}�fdd�|	jD�}|D]'}
tj|jdd�}t�||
�}tj	j
||d	�}
|sQtj|
d
�sXtj
||d	��q1|D]}t�||�}tjj
||d�}
tj|
d
�sxtj||d��q[t��fdd�|D�d�}|dur��dur�t�|���}t�|�|j�}tj|jdd�}tj	j
||d	�}
|s�tj|
d
�s�tj
||d	��dSdSdS)
NcSsg|]}|j�qSr7�r2��.0�sr7r7r8�
<listcomp>�sz2prompt_for_dependency_handling.<locals>.<listcomp>c3s�|]
}|j�kr|VqdS�NrQrR)r?r7r8�	<genexpr>�s�z1prompt_for_dependency_handling.<locals>.<genexpr>csg|]
}|j�vr|j�qSr7rQrR��enabled_service_namesr7r8rU��

�csg|]
}|j�vr|j�qSr7rQrRrXr7r8rU�rZz features.block_disable_on_enable)r�
path_to_value)�service_being_enabled�incompatible_service)�msg)r\�required_servicec3s.�|]}|j�kr|jr|j�kr|VqdSrV�r2�variant_enabled�variant_namerR)r?r$r7r8rW�s�
�
��)�next�incompatible_with�
depends_onr�is_config_value_truer#r
�	get_titler�INCOMPATIBLE_SERVICE�format�prompt_for_confirmationr�IncompatibleServiceStopsEnable�REQUIRED_SERVICE�RequiredServiceStopsEnablerb)r#r?r+r*r<r$rP�incompatible_services�required_services�dependenciesr]�cfg_block_disable_on_enable�incompatible_service_title�user_msgr_�required_service_titlera�to_be_enabled_title�enabled_variant_titler7)rYr?r$r8�prompt_for_dependency_handlings�	�
�
������������
������
rwr(�
json_response�processed_services�failed_services�errors�warningscCsb|r/|��|��|rdnd|d<||d<||d<||d<||d<ttj|tjdd	��dSdS)
Nr �failure�resultryrzr{r|T)�cls�	sort_keys)�sort�print�json�dumpsr�DatetimeAwareJSONEncoder)r(rxryrzr{r|r r7r7r8�_print_json_output�s 	���r�r&r)�returnc	s�t�|�}	tj||�||d�}
|
j�|
j}t��fdd�|D�d�}|durItjj	|d�}
|	|
j
�|	tjj	|d��tddd||
j
|
jd�d�S|s�z
t
|�|||�|d	�Wn-tjy�}z t�|�|	|j
�|	tjj	|d��tdddd�WYd}~Sd}~wwz_|r�d}ntj|d
�}�dkr�t||||d�}ntt|�|d
�||d�}tj|d�|r�|	tjj	|d��n	|	tjj	|d��|j}|r�|	tjj	dd��|jD]}|	|�q�td|dd�WStj�y$}z1|jd}|d}|d}|d}|	|�|	tjj	|d��tddd||||d�d�WYd}~Sd}~wtj�yU}z$|	|j
�|	tjj	|d��tddd||j
|j|jd�d�WYd}~Sd}~ww)N)r$r'r)c3s2�|]}|j�kr�r|jr|j�kr|VqdSrVr`rR��	real_namer$r7r8rWs�
��
��z&_enable_one_service.<locals>.<genexpr>)�titleFr?)�typer?rJ�message_code)r r!r")r<r$rP)r%r;)r)r:)r?r$r')r:�r#�install)�	operationTr@�coder��additional_info�r�r?rJr�r�)rr,r
�entitlement_factoryr2r�rcr�ALREADY_ENABLEDrir^�
ENABLE_FAILEDrrwr�UbuntuProError�LOG�	exception�CLIEnableDisableProgressrOrrr�ACCESS_ENABLED_TMPL�ENABLED_TMPLrC�ENABLE_REBOOT_REQUIRED_TMPLrLr��msg_code)r#r&r$r'r%r(r)r*r+r3�ent�	ent_title�already_enabledr^rNr>�
enable_resultr!rJr@�err_code�err_msg�err_infor7r�r8r1�s���	�
��
�	

�������
����

�
���
����r1cKs�g}g}g}g}tjdd�}|jdk}t�|�}	t|dd�}
|j}|j}|j}
|
r2|r2t	j
ddd��|
r=|
r=t	j
dd	d��|rH|
rHt	j
dd	d��|	tj�z	t
j|dd
�Wn!t	jt	jfywtjddd
�|�dtjjtjjd��Ynwt|�js�t	��}|	|j�|�d|j|jd��t||||||dd�dS|
r�t|dd|d�St|dg�}|s�t	���t�||�\}}t |�j!}t"|�j#}d}t�$||�D]4}t%|||
||||�&d�||�	}|j'r�|�|�|j(r�d|d<q�d}|�|�|j)du�r|�|j)�q�|�r&d}||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)�_schema_versionr!r�r$��
--access-only�	--variant)�option1�option2�--auto)�verbosezFailed to refresh contractT)�exc_info�system)r�rJr�)r �)r#r$r%r(r?r)r!Nr�r�r).r�JSON_SCHEMA_VERSIONrirr,�getattrr'r%�autor�InvalidOptionCombinationr�REFRESH_CONTRACT_ENABLEr	�refresh�ConnectivityErrorr�r��warning�append�E_REFRESH_CONTRACT_FAILUREr^r2r�is_attached_and_contract_valid�ContractExpiredErrorr�r�r9�NoServicesToEnabler
�get_valid_entitlement_namesrr*rr0�order_entitlements_for_enablingr1�getr r!r"�*create_enable_entitlements_not_found_errorr��UAContractClient�update_activity_token)�argsr#�kwargsryrzr{r|rxr(r3r$r'r%r��expired_err�names�entitlements_found�entitlements_not_foundr*r+�retr&r~�err�contract_clientr7r7r8�
action_enable�s��
����
���

���	�
�

��
�
��
��

�
r�rG�z, r�)�options�store�*)�help�action�nargsr��
store_true)r�r�z--assume-yes)�commandr�z--betaz--format�cli)�defaultr�)r�r��choicesr�r�)�	arguments)r��descriptionr��
help_category�
help_position�argument_groupsrV)Kr��logging�typingrrrrr�uaclientrrr	r
rrr
rrr�+uaclient.api.u.pro.services.dependencies.v1rr�%uaclient.api.u.pro.services.enable.v1rrr�-uaclient.api.u.pro.status.enabled_services.v1rr�(uaclient.api.u.pro.status.is_attached.v1r�uaclient.clir�uaclient.cli.commandsrrr�uaclient.cli.parserr�uaclient.filesr�	getLogger�replace_top_level_logger_name�__name__r��bool�strr�UAConfigr9�AbstractProgressrOrwr�r1�verify_json_format_args�assert_root�assert_attached�&_raise_enable_disable_unattached_error�intr��CLI_ROOT_ENABLE�CLI_ENABLE_DESC�
QUICKSTART�CLI_ENABLE_SERVICEri�join�valid_services�CLI_ENABLE_ACCESS_ONLY�CLI_ASSUME_YES�CLI_ENABLE_AUTO�CLI_ENABLE_BETA�CLI_FORMAT_DESC�CLI_ENABLE_VARIANT�enable_commandr7r7r7r8�<module>s$0��
��
�'���
�,������
�\�
�����
�������
��	�

�#
���
���������
�