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/uaclient/api/u/pro/services/enable/__pycache__/v1.cpython-38.pyc
U

��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'eeej(eeej(e)eej(eefd�dd�Z*eee+d�dd�Z,d*e&eee'd�dd�Z-d+e&eeee'd�dd�Z.edde.e&dd�Z/ddd 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@sVeZdZededd�ededdd�ededdd�gZd	dd
�eeee	d�dd
�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)rr�rrrcCs||_||_||_dS�Nr )�selfrrr�r#�G/usr/lib/python3/dist-packages/uaclient/api/u/pro/services/enable/v1.py�__init__*szEnableOptions.__init__)�__name__�
__module__�__qualname__rrr�fields�strr�boolr%r#r#r#r$rs*�����rc@sleZdZedee�dd�edee�dd�ededd�edee�d	d�gZee	ee	e
ee	d
�dd�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.�r-r.r/r	cCs||_||_||_||_dSr!r0)r"r-r.r/r	r#r#r$r%TszEnableResult.__init__N)r&r'r(rrrrr)rr*r+r%r#r#r#r$r,6s4����� �r,)�cfg�progress�entitlement�available_variantsr�returnc	Cs�d}|D]4}|||d�}|��dtjjkr|��r|}q>q|dkr^|jdk	r^|j||d�}|dk	r�|�dtjdt	j
jt	jj
|jt	jjd�ifg�t	jj|jd�}|t|j|jd|jid�fS|dfSdS)	N)r1rrZmessage_operation�msg)r)�variant_namer7)�title�code�meta)�applicability_statusr�ApplicabilityStatus�
APPLICABLEZvariant_auto_selectZdefault_variant�emitrZprompt_for_confirmationr	ZAUTO_SELECTING_VARIANT�formatZTxtColorZBOLDr7ZENDCZAUTO_SELECTED_VARIANT_WARNINGrr6�name)	r1r2r3r4rrZv_cls�vZwarningr#r#r$�_auto_select_variantbsL
������������rB)r1r5cCsdd�t|�jD�S)NcSsg|]
}|j�qSr#)r@��.0�sr#r#r$�
<listcomp>�sz+_enabled_services_names.<locals>.<listcomp>)r�enabled_services�r1r#r#r$�_enabled_services_names�srI)�options�progress_objectr5cCst|t�|d�S)N)rK)�_enabler)rJrKr#r#r$�enable�srM)rJr1rKr5c
st|�}g}t��st���t|�js.t����jdkr@t�	��t
|�}t�fdd�t|�j
D�d�}|rztggdgd�Stj|�j�jp�d�jd�}|��\}}	|j}
t|tjjk|j|
g�r�t||||
���jd	�\}}|r�|�|�|��|_d}d}
z*tjd
d��|� |�\}}
W5QRXWn0t!k
�rX}zt�"�|�W5d}~XYnX|�s�|
dk	�r~|
j#dk	�r~|
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.
    Z	landscapec3s6|].}|j�jkr�jr*|jr|j�jkr|VqdSr!)r@rrZvariant_enabledr7rC�rJr#r$�	<genexpr>�s�z_enable.<locals>.<genexpr>NFr0�)r1r@rr)r1r2r3r4rzu.pro.services.enable.v1)Zlock_holder)r�reasoncSsg|]}t|t�r|�qSr#)�
isinstancer*)rDr6r#r#r$rF�s
�z_enable.<locals>.<listcomp>Zpost_enablerH)1r
rZwe_are_currently_rootr�NonRootUserErrorrZis_attached�UnattachedErrorr�NotSupportedrI�nextrrGr,rZentitlement_factoryrrr;Zvariants�allr<r=Z
is_variantrB�values�appendZcalculate_total_enable_stepsZtotal_stepsrZ	RetryLockrM�	ExceptionZclear_lock_file_if_present�messager	ZGENERIC_UNKNOWN_ISSUE�EntitlementNotEnabledErrorZ	messaging�getr
Zfinish�sorted�list�set�
differenceZ_check_for_reboot�warnings)rJr1rKr2rbZenabled_services_beforeZalready_enabledr3Z
applicability�_r4Zauto_select_warningZsuccessZfail_reason�erQZenabled_services_afterZpost_enable_messages�resultr#rNr$rL�s�	


�	���
���


����������rLZv1Z
EnableServiceT)�versionr@�fnZoptions_clsZsupports_progressZ32zw
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
}
)Z
introduced_inZrequires_networkZexample_pythonZresult_classrZexample_cliZexample_json)N)N)7Zlogging�typingrrrrrZuaclientrrr	r
rZuaclient.apirr
rZuaclient.api.apirZuaclient.api.data_typesrrZ-uaclient.api.u.pro.status.enabled_services.v1rZ(uaclient.api.u.pro.status.is_attached.v1rZuaclient.configrZuaclient.data_typesrrrrrZ	getLoggerZreplace_top_level_logger_namer&ZLOGrr,Z
UAEntitlementr+rBr*rIrMrLZendpointrSrTrUZEntitlementNotFoundErrorZ
LockHeldErrorr\Z_docr#r#r#r$�<module>s� -�/��	��~�	������ �