HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/uaclient/api/u/pro/services/enable/__pycache__/v1.cpython-310.pyc
o

��Jh&�@s�ddlZddlmZmZmZmZmZddlmZm	Z	m
Z
mZmZddl
mZmZmZddlmZddlmZmZddlmZddlmZdd	lmZdd
lmZmZmZm Z m!Z!e�"e�#e$��Z%Gdd�de�Z&Gd
d�dee�Z'dededej(deeej(de)deej(eeffdd�Z*dedee+fdd�Z,	d.de&deede'fdd�Z-	d.de&dedeede'fdd�Z.edd e.e&d!d"�Z/d#d!d$e'ej0d%fej1d&fej2d'fej3d(fej4d)fej5d*fgd+d,d-�Z6dS)/�N)�Iterable�List�Optional�Tuple�Type)�entitlements�lock�messages�status�util)�AbstractProgress�ProgressWrapper�
exceptions)�APIEndpoint)�AdditionalInfo�ErrorWarningObject)�_enabled_services)�_is_attached)�UAConfig)�
BoolDataValue�
DataObject�Field�StringDataValue�	data_listc@sZeZdZededd�ededdd�ededdd�gZd	dd
�dedeede	fdd�Z
d	S)
�
EnableOptions�servicezPro service to be enabled��doc�variantFz2Optional variant of the Pro service to be enabled.�access_onlyz^If true and the target service supports it, only enable access to the service (default: false)N)rrcCs||_||_||_dS�N)rrr)�selfrrr�r"�G/usr/lib/python3/dist-packages/uaclient/api/u/pro/services/enable/v1.py�__init__*s
zEnableOptions.__init__)�__name__�
__module__�__qualname__rrr�fields�strr�boolr$r"r"r"r#rs0�������rc	@sreZdZedee�dd�edee�dd�ededd�edee�d	d�gZdee	dee	de
dee	fd
d�ZdS)
�EnableResult�enabledz#List of services that were enabled.r�disabledz$List of services that were disabled.�reboot_requiredz?True if one of the services that was enabled requires a reboot.r	zaList of information message strings about the service that was just enabled. Possibly translated.cCs||_||_||_||_dSr �r,r-r.r	)r!r,r-r.r	r"r"r#r$Ts
zEnableResult.__init__N)r%r&r'rrrrr(rr)r*r$r"r"r"r#r+6s>���������r+�cfg�progress�entitlement�available_variantsr�returnc	Cs�d}|D]}|||d�}|��dtjjkr|��r|}nq|dur/|jdur/|j||d�}|durc|�dtjdt	j
jt	jj
|jt	jjd�ifg�t	jj|jd�}|t|j|jd|jid�fS|dfS)	N)r0rr�message_operation�msg)r)�variant_namer7)�title�code�meta)�applicability_statusr�ApplicabilityStatus�
APPLICABLE�variant_auto_select�default_variant�emitr�prompt_for_confirmationr	�AUTO_SELECTING_VARIANT�format�TxtColor�BOLDr7�ENDC�AUTO_SELECTED_VARIANT_WARNINGrr6�name)	r0r1r2r3rr�v_cls�v�warningr"r"r#�_auto_select_variantbsJ
������������rLcCsdd�t|�jD�S)NcSsg|]}|j�qSr")rH��.0�sr"r"r#�
<listcomp>�sz+_enabled_services_names.<locals>.<listcomp>)r�enabled_services�r0r"r"r#�_enabled_services_names�srS�options�progress_objectcCst|t�|d�S)N)rU)�_enabler)rTrUr"r"r#�enable�srWc
st|�}g}t��st���t|�jst����jdkr t�	��t
|�}t�fdd�t|�j
D�d�}|r=tggdgd�Stj|�j�jpFd�jd�}|��\}}	|j}
t|tjjk|j|
g�rvt||||
���jd	�\}}|rv|�|�|��|_d}d}
ztjd
d��|� |�\}}
Wd�n1s�wYWnt!y�}zt�"�|�d}~ww|s�|
dur�|
j#dur�|
j#}nt$j%}tj&�j|d��t
|�}d
d�|j'�(dg�p�gD�}t)j)|d�|�*�tt+t,t-|��.t-|����t+t,t-|��.t-|����|�/�|d�}||_0|S)z�
    Enable a Pro service. This will automatically disable incompatible services
    and enable required services that that target service depends on.
    �	landscapec3s8�|]}|j�jkr�jr|jr|j�jkr|VqdSr )rHrr�variant_enabledr7rM�rTr"r#�	<genexpr>�s�����z_enable.<locals>.<genexpr>NFr/�)r0rHrr)r0r1r2r3rzu.pro.services.enable.v1)�lock_holder)r�reasoncSsg|]	}t|t�r|�qSr")�
isinstancer))rNr6r"r"r#rP�s��z_enable.<locals>.<listcomp>�post_enablerR)1r
r�we_are_currently_rootr�NonRootUserErrorr�is_attached�UnattachedErrorr�NotSupportedrS�nextrrQr+r�entitlement_factoryrrr;�variants�allr<r=�
is_variantrL�values�append�calculate_total_enable_steps�total_stepsr�	RetryLockrW�	Exception�clear_lock_file_if_present�messager	�GENERIC_UNKNOWN_ISSUE�EntitlementNotEnabledError�	messaging�getr
�finish�sorted�list�set�
difference�_check_for_reboot�warnings)rTr0rUr1r}�enabled_services_before�already_enabledr2�
applicability�_r3�auto_select_warning�success�fail_reason�er^�enabled_services_after�post_enable_messages�resultr"rZr#rV�s�	


�	���
��
�

��������������rV�v1�
EnableServiceT)�versionrH�fn�options_cls�supports_progress�32zw
from uaclient.api.u.pro.services.enable.v1 import enable, EnableOptions
result = enable(EnableOptions(service="usg"))
zWhen called as non-root userzCWhen called on a machine that is not attached to a Pro subscriptionz_When called for a service that doesn't support being enabled via API (currently only Landscape)zxWhen the service argument is not a valid Pro service name or if the variant is not a valid variant of the target servicez8When another Ubuntu Pro related operation is in progressz When the service fails to enablez3pro api u.pro.services.enable.v1 --args service=usgzp
{
    "disabled": [],
    "enabled": [
        "usg"
    ],
    "messages": [],
    "reboot_required": false
}
)�
introduced_in�requires_network�example_python�result_classr�example_cli�example_jsonr )7�logging�typingrrrrr�uaclientrrr	r
r�uaclient.apirr
r�uaclient.api.apir�uaclient.api.data_typesrr�-uaclient.api.u.pro.status.enabled_services.v1r�(uaclient.api.u.pro.status.is_attached.v1r�uaclient.configr�uaclient.data_typesrrrrr�	getLogger�replace_top_level_logger_namer%�LOGrr+�
UAEntitlementr*rLr)rSrWrV�endpointrbrdre�EntitlementNotFoundError�
LockHeldErrorrt�_docr"r"r"r#�<module>s� ,�����
�/���
�	����
�~�	������ 
�