https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/uaclient/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/uaclient/__pycache__/status.cpython-310.pyc
o

��Jhr�@s:ddlZddlZddlZddlZddlmZddlmZmZddlm	Z	ddl
mZmZm
Z
mZmZddlmZmZmZmZmZmZmZddlmZddlmZmZdd	lmZmZdd
l m!Z!m"Z"ddl#m$Z$ddl%m&Z&m'Z'm(Z(m)Z)dd
l*m+Z+m,Z,m-Z-m.Z.ddl/m0Z0ddl1m2Z2e�3�Z4e�5e�6e7��Z8dZ9dZ:dZ;e)j<j=e2j>ej?e2j@e)jAj=e2jBejCe2j@e)jDj=e2jEejFe2j@e)jGj=e2jEejHe2j@e)jIj=e2jJejKe2j@e&jLj=e2j>ejMe2j@e&jNj=e2jEejOe2j@e9e2j>ejPe2j@e:e2j>ejQe2j@e;e2j>ejRe2j@i
ZSdZTdZUdjVejWejXejYejZd�Z[dZ\dZ]idd�dd�de�^��dd�dd �d!d�d"d�d#d�d$g�d%e(jAj=�d&ej_�d'i�d(g�d)d*d*d*ge)jDj=d+��d,d*d*d*gd-��d.d �Z`d/d0�Zad1eebeffd2d3�Zcd4ed1eebeffd5d6�Zdd4ed1eebeffd7d8�Zed1eebeffd9d:�ZfdUd4ed;egd1eebeffd<d=�Zhd>e
eebefd?ebd1eebeffd@dA�Zi	 dUdBebd;egd1eeebefejffdCdD�ZkdEebd1ebfdFdG�ZldHe
e
ebd1ebfdIdJ�Zm	dVdKe
eebebfdLeebd1e
ebfdMdN�Znd"eed1ebfdOdP�ZodUd=eebefd;egd1ebfdQdR�ZpdSdT�ZqdS)W�N)�OrderedDict)�datetime�timezone)�Enum)�Any�Dict�List�Optional�Tuple)�event_logger�
exceptions�	livepatch�lock�messages�util�version)�_is_attached)�UA_CONFIGURABLE_KEYS�UAConfig)�get_available_resources�get_contract_information)�ATTACH_FAIL_DATE_FORMAT�PRINT_WRAP_WIDTH)�entitlement_factory)�ContractStatus�UserFacingAvailability�UserFacingConfigStatus�UserFacingStatus)�
machine_token�notices�state_files�user_config_file)�Notice)�TxtColor�	essential�standard�advancedz({name: <17}{available: <11}{description}zJ{name: <17}{available: <11}{entitled: <11}{auto_enabled: <16}{description}z4{name: <17}{entitled: <10}{status: <13}{description}��name�entitled�status�descriptionz4{name: <17}{entitled: <19}{status: <22}{description}z={marker} {name: <15}{entitled: <19}{status: <22}{description}�_doczUContent provided in json response is currently considered Experimental and may change�_schema_versionz0.1r�
machine_id�attachedF�	effective�expires�origin�services�execution_status�execution_details�featuresr�contract���idr(�
created_at�products�tech_support_level�account�r(r:r;�external_account_ids�	simulatedcCsdd�|��D�S)NcSs4g|]}|jjs|jjn|jj|jj|jjd��qS))r(�reason_code�reason)�entitlement�
is_variantr(�variant_name�	named_msg�msg��.0�service�rL�1/usr/lib/python3/dist-packages/uaclient/status.py�
<listcomp>�s
�
���z,_get_blocked_by_services.<locals>.<listcomp>)�blocking_incompatible_services)�entrLrLrM�_get_blocked_by_services�s
�rQ�returnc

s�d}d}|��}|��}|j�vrdnd}i}|tjkr tj}	n=|j�vr.tj}	�|j}n/|��\}	}
|	tj	krA|
j|
j
d�}n|
rF|
j
}|	tjkrMd}|jr]��fdd�|j��D�}t
|�}|j|j|j|	j|||||d�	}|jsx||d<|S)	Nr8�no�yes)�code�messagecs$i|]\}}|t|�d�����qS))�cfg)�_attached_service_status)rJrF�variant_cls�rW�inapplicable_resourcesrLrM�
<dictcomp>�s���z,_attached_service_status.<locals>.<dictcomp>)	r(r+r)r*�status_details�description_override�	available�
blocked_by�warning�variants)�status_description_override�contract_statusr(r�
UNENTITLEDr�UNAVAILABLE�INAPPLICABLE�user_facing_status�WARNINGrHrb�itemsrQ�presentation_namer+�valuerE)
rPr[rWrar]r^rdr_rb�
ent_status�detailsr`�service_statusrLrZrMrX�sL


�
�	�rXrWcCs�t�tj�t�tj�t|�jrt�tj�t�	t
�}t�|�}|jd}|d}t
jj}|�|dd|�d�t��p=g|d|d|�dd	�|�d
g�|d�|jd|jd|j�dd	�|j�dg�d
�d��|�d�rt|j|d<|�d�r|d|d<|j�d�}|s�t|�}dd�t|dd�d�D�}|D]$}zt||�dd	�d�}	Wn
tjy�Yq�w|d�t|	||��q�|djdd�d�|���di��d�}
|
r�|
�di��d�}|r�||d d!<|S)"z8Return configuration of attached status as a dictionary.�machineTokenInfo�contractInfo�	machineIdTr2r:r(�	createdAtr8r<r9�externalAccountIDsr?)r.r/r2rr7r>�effectiveTor1�
effectiveFromr0�availableResourcescSs&i|]}|�d�s|d|�d��qS)r_r(r+��get�rJ�resourcerLrLrMr\s��z$_attached_status.<locals>.<dictcomp>cS�|�dd�S�Nr(r8rx��xrLrLrM�<lambda>�z"_attached_status.<locals>.<lambda>��key�rWr(r3cSr|r}rxr~rLrLrMr�r��supportrD�affordances�supportLevelr7r=)r�remover"�AUTO_ATTACH_RETRY_FULL_NOTICE�AUTO_ATTACH_RETRY_TOTAL_FAILUREr�is_attached_and_contract_valid�CONTRACT_EXPIRED�copy�deepcopy�DEFAULT_STATUSr�get_machine_token_filerrgrl�updatery�listr>�contract_expiry_datetimer�sortedrr�EntitlementNotFoundError�appendrX�sort�entitlements)rW�response�machine_token_filerprqr=�	resourcesr[r{rPr�r�rLrLrM�_attached_status�sp






�����


��
��r�cCs�t�t�}t|�}|D]X}|�d�rtjj}ntjj}zt	||�dd�d�}Wnt
jy;t�
d|�dd��Yqw|jdkrNt��tjjkrN|��}nd}|d	�|�d
|d�|j||d��q|d	jdd
�d�|S)z#Return unattached status as a dict.r_r(r8r�z@Ignoring availability of unknown service %s from contract serverzwithout a 'name' keyr
Nr3�presentedAs)r(r+r^r_cSr|r}rxr~rLrLrMr�Gr�z$_unattached_status.<locals>.<lambda>r�)r�r�r�rryr�	AVAILABLErlrfrrr��LOG�debugr(r
�on_supported_kernel�LivepatchSupport�UNSUPPORTEDrcr�r+r�)rWr�r�r{r_rP�descr_overriderLrLrM�_unattached_statuss<



��
�
��r�cCs�t}|jj}tj}t��\}}t��pg}|dkr&|j	j}tj
j||d�}ntj
jr7|jj}d}tjj|d�}||||j|j|jd�}tjj��}	tD]}
t||
�ri|	|
durit||
�}t|t�re|j}||	|
<qK|	|dd<|S)	aGReturn a dict with execution_status, execution_details and notices.

    Values for execution_status will be one of UserFacingConfigStatus
    enum:
        inactive, active, reboot-required
    execution_details will provide more details about that state.
    notices is a list of tuples with label and description items.
    r)�pid�lock_holderzconfiguration changes)�	operation)r4r5r�config_path�configr6Nr��	ua_config)r�INACTIVErlr�NO_ACTIVE_OPERATIONSr�check_lock_inforr��ACTIVE�	LOCK_HELD�formatr �reboot_cmd_marker_file�
is_present�REBOOTREQUIRED�ENABLE_REBOOT_REQUIRED_TMPL�cfg_pathrWr6r!�user_config�
public_config�to_dictr�hasattr�getattr�
isinstancer)rW�
userStatus�
status_val�status_desc�lock_pidr��notices_listr��retr�r��valrLrLrM�_get_config_statusLsB	���	

�r��show_allcCsdt|�jr
t|�}nt|�}|�t|��t��rtj	�
|�|s0dd�|�dg�D�}||d<|S)aReturn status as a dict, using a cache for non-root users

    When unattached, get available resources from the contract service
    to report detailed availability of different resources for this
    machine.

    Write the status-cache when called by root.
    cS� g|]}|�dd�dkr|�qS�r_rTrxrIrLrLrMrN��
�zstatus.<locals>.<listcomp>r3)r�is_attachedr�r�r�r�r�we_are_currently_rootr �status_cache_file�writery)rWr�r��available_servicesrLrLrMr*{s
	

�r*r��entitlement_namecCs`|D]'}|�d�|kr)|�d�rdnd|�di��d�rdnd|�di�d�Sqddid�S)	z0Extract information from the entitlements array.�typer)rTrS�obligations�enableByDefaultr�)r)�auto_enabledr�rx)r�r�rDrLrLrM�_get_entitlement_information�s��

��r��tokenc
Csd}t�t�}zt||�}Wntjy+}zt|d�r%|jdkr%t���|�d}~ww|�	di�}|�	di�}|�
|�	dd�|�	d	d�|�	d
d�|�	dg�d�|�	d	d�|�	d�|�	d
d�|�	d
g�d�dd��t�t
j�}	|�	d�r�|�	d�|d<|d}
|
|	}|��dkr�tjj|dd|
�t�d�}tj|j|jd�t�tjd|jd�d}|�	d�r�|�	d�|d<|d}
|	|
}|��dkr�tjj|dd|
�t�d�}tj|j|jd�t�tjd|jd�d}t|�}dd�t|dd�d�D�}|�	dg�}|D]B}|�	d	d�}zt||d �}Wntj�y'Y�qwt ||�}|d!�!|�	d"|j�|j"|d#|d$|j|v�rGd%nd&d'���q|d!j#d(d�d�t |d)�}|d#�rr|d*�	d+�}|�rr||dd,<|�
t$|��|�s�d-d�|�	d!g�D�}||d!<||fS).z�Get a status dictionary based on a token.

    Returns a tuple with the status dictionary and an integer value - 0 for
    success, 1 for failure
    rrUi�Nrq�accountInfor:r8r(rsr<)r:r(r;r<rtr?T)r7r>rArur1r7)�contract_id�date)�	error_msg�
error_code�
�rvr0cSsg|]
}|ds|d�qS)r_r(rLrzrLrLrMrN�s��z#simulate_status.<locals>.<listcomp>cSs|dS)Nr(rLr~rLrLrMr��sz!simulate_status.<locals>.<lambda>r��resourceEntitlementsr�r3r�r)r�rTrS)r(r+r)r�r_cSr|r}rxr~rLrLrMr�r�r�r�r�r=cSr�r�rxrIrLrLrMrNr�)%r�r�r�rr�ContractAPIErrorr�rU�AttachInvalidTokenErrorryr�r�nowr�utc�
total_secondsr�E_ATTACH_FORBIDDEN_EXPIREDr��strftimer�event�errorrHr(�info�STATUS_TOKEN_NOT_VALID�E_ATTACH_FORBIDDEN_NOT_YETrr�rr�r�r�r+r�r�)rWr�r�r�r��contract_information�e�
contract_info�account_infor��expiration_datetime�deltarV�effective_datetimer�r[r�r{r�rP�entitlement_informationr�r�r�rLrLrM�simulate_status�s�
��



�

����

��

�������


�r��stringcCstj��rt�||�S|S)z=Return colorized string if using a tty, else original string.)�sys�stdout�isatty�STATUS_HUMANIZE_COLORIZEry)r�rLrLrM�for_human_colorized%s
���r��commandscCstd}|D]}|r|d7}|d�|�7}qd�tj|tddd��}d|vr*d	}d
}nd}d}d
jtj|||tjd�S)Nr8z && � z \
�z  )�width�subsequent_indentr�z{
  z
}z{ z }z%{color}{prefix}{content}{suffix}{end})�color�prefix�content�suffix�end)�join�textwrap�wraprr�r#�DISABLEGREY�ENDC)r�r��cmd�wrapped_contentr�rrLrLrM�colorize_commands.s,
���r	�column_data�headercsjg}|r	|�|�tdd�|D��}|dkr)d�|��|��fdd�|D��|S|�dd�|D��|S)z�Return a list of content lines to print to console for a section

    Content lines will be center-aligned based on max value length of first
    column.
    cSsg|]}t|d��qS)r)�len�rJ�pairrLrLrMrNUsz.get_section_column_content.<locals>.<listcomp>rz{{:>{}}}: {{}}csg|]}�j|��qSrL)r�r
��templaterLrMrNXscSsg|]}|d�qS)r�rLr
rLrLrMrN[s)r��maxr��extend)r
rr��template_lengthrLrrM�get_section_column_contentJs

�rcCs8|durtjSz|��}Wn	tyYnw|�d�S)Nz%c %Z)r�STATUS_CONTRACT_EXPIRES_UNKNOWN�
astimezone�	Exceptionr�)r1rLrLrM�format_expires_s�
rc
Cs4|�d�s�|�d�r<|�dd�stjStjtjtjtjtjtj	d�g}|�dg�D]
}|�
tjd)i|���q)d�|�S|�dd�sGtjg}n@tjtjtjtj	d�g}|�dg�D]-}|�d�}|rd|n|�d	d
�}|�d�dkrttj
ntj}|�
tj|�d
d
�||d��qY|�d�}|r�|�
tj�|�|�|�d�r�|�
dtj�t|�di����D]
\}}	|�
d�||	��q�|s�|�d
tjg�|�d
tjjg�t��tjjkr�|�d
tjg�d�|�Sg}
d}|�dd�s�tjg}n�tg}|�dg�D]�}|�dd
�}
|�d�}|�r|n|�d	d
�}|�d
d
�t|
�t|�dd
��|d�}|�dd�}|du�rD|�dd�}|du�rD|
�
|�|�d�}|�rZ|�sZd}d�|d
�|d
<|�
tjd)i|���|�r�|�r�t|���D]4\}\}}|t |�dk�r�dnd}|�
t!j||�d
�t|�dd
��t|�dd
��|�d	d
�d���qqq�|�r�|�
d
�|�
tj"�|�d��s�t |
�dk�r�|�
d
�|�
tj�|�d�}|�r�|�|�t |
�dk�r�|�|
�|�d��r
|�
dtj�t|�di����D]\}}	|�
d�||	���q�|�
d
�|�s%|�r|�
tj#�n|�
tj�|�
tj$jdd ��g}|�d!i��d
d"�}|�rF|�
tj%|f�|�d#i��d
d"�}|�r[|�
tj&|f�|�d$d�d%k�r�|�
tj't(|�d&��f�|�d#i��d'd"�}|�
tj)t|�f�|�r�|�
d
�|�t*|d(��d�|�S)*z&Format status dict for tabular output.r/rAr3N)r(r_r)r�r+r�)r(r_r+r^r+r8r_rTr(rr6z{}: {}Fr)r*r'rarVrbTz{}*r�u├u└)�markerr(r)r*r+rzpro enable <service>)�commandr>�unknownr7r2�freer1r=)r
rL)+ryr�STATUS_NO_SERVICES_AVAILABLE�STATUS_SIMULATED_TMPLr��STATUS_SERVICE�STATUS_AVAILABLE�STATUS_ENTITLED�STATUS_AUTO_ENABLED�STATUS_DESCRIPTIONr�r�STATUS_UNATTACHED_TMPL�STANDALONE_YES�
STANDALONE_NO�STATUS_NOTICESr�STATUS_FEATURESr�rj�STATUS_ALL_HINT�E_UNATTACHEDrHr
r�r�r��)LIVEPATCH_KERNEL_NOT_SUPPORTED_UNATTACHED�
STATUS_HEADERr��STATUS_TMPL�	enumerater�VARIANT_STATUS_TMPL�STATUS_SERVICE_HAS_VARIANTS�STATUS_ALL_HINT_WITH_VARIANTS�"STATUS_FOOTER_ENABLE_SERVICES_WITH�STATUS_FOOTER_ACCOUNT�STATUS_FOOTER_SUBSCRIPTION�STATUS_FOOTER_VALID_UNTILr�STATUS_FOOTER_SUPPORT_LEVELr)r*r�r�rKr�r+r_rr�rl�service_warnings�has_variantsror)�fmt_argsra�warning_messagerb�idx�_�variantr�pairs�account_name�
contract_namer=rLrLrM�format_tabularis4

��	

��
�
���
��


��


�
�

��




�
�
���





�������

rAc
	Cs�t|�}d}t�}||d<|D](}|d|ks|�d�|kr7z
t||dd�}Wn
tjy2Yqw|}nq|durBtj|d��t|�jr\t	|i|�}|d}|d|d<||d<n|dret
jj}	nt
j
j}	|	|d<|j|d	<|S)
z�Return help information from an uaclient service as a dict

    :param name: Name of the service for which to return help data.

    :raises: UbuntuProError when no help is available.
    Nr(r�r�)r(r*r)r_�help)rrryrrr��
NoHelpContentrr�rXrr�rlrf�	help_info)
rWr(r��
help_resource�
response_dictr{�help_entro�
status_msgr_rLrLrMrB%s6��



rB)F)N)rr��loggingr�r�collectionsrrr�enumr�typingrrrr	r
�uaclientrrr
rrrr�(uaclient.api.u.pro.status.is_attached.v1r�uaclient.configrr�uaclient.contractrr�uaclient.defaultsrr�uaclient.entitlementsr�(uaclient.entitlements.entitlement_statusrrrr�uaclient.filesrrr r!�uaclient.files.noticesr"�uaclient.messagesr#�get_event_loggerr��	getLogger�replace_top_level_logger_name�__name__r��	ESSENTIAL�STANDARD�ADVANCEDr�rl�OKGREEN�STATUS_STATUS_ENABLEDrr��FAIL�STATUS_STATUS_DISABLEDrgr�STATUS_STATUS_INAPPLICABLErf�STATUS_STATUS_UNAVAILABLEri�
WARNINGYELLOW�STATUS_STATUS_WARNING�ENTITLED�STATUS_ENTITLED_ENTITLEDre�STATUS_ENTITLED_UNENTITLED�STATUS_SUPPORT_ESSENTIAL�STATUS_SUPPORT_STANDARD�STATUS_SUPPORT_ADVANCEDr�r$rr�rr!�
STATUS_STATUSr#r,r-r/�get_versionr�r�rQ�strrXr�r�r��boolr*r��intr�r�r	rrrArBrLrLrLrM�<module>s:$	�������������(�
��������	�
���
������� 

�;G. /��

����
�x	���
� 
=

https://t.me/RX1948 - 2025