| Server IP : 104.21.4.30 / Your IP : 162.159.115.11 Web Server : Apache System : Linux keen-cori.18-142-40-148.plesk.page 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 06:59:36 UTC 2025 x86_64 User : simottodesign.com_2tntp341vs7 ( 10011) PHP Version : 8.3.31 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/lib/python3/dist-packages/uaclient/__pycache__/ |
Upload File : |
U
2�d�( �
@ s� d dl Z d dlZd dlZd dlZd dlmZmZ d dlmZm Z m
Z
mZmZm
Z
d dlmZ d dlmZ d dlmZ d dlmZmZmZ d dlmZ d d lmZ d d
lmZmZmZ d dlmZmZm Z e�!e�"e#��Z$dZ%d
Z&e j'e(e)dd�dd�Z*d+e j'ejdd�dd�Z+dddddd�e j'e(e)e)e)e(eee( d�dd�Z,ddd�e j'ee( e)d�dd�Zd,e(eee- dd�d d!�Z.e j'd"�d#d$�Z/e j'e(d%�d&d'�Z0e j'ed(�d)d*�Z1dS )-� N)�List�Optional)�clouds�config�contract�entitlements�
exceptions� livepatch)�log)�messages)�status)�system�timer�util)�AutoAttachCloudInstance)�identity)�CLOUD_BUILD_INFO�DEFAULT_CONFIG_FILE�DEFAULT_LOG_PREFIX)�AttachmentData�attachment_data_file�timer_jobs_state_file)zua-timer.servicezua-timer.timerzua-auto-attach.pathzua-auto-attach.servicezua-reboot-cmds.servicezubuntu-advantage.service�
)�cfg�token�allow_enable�returnc C sz ddl m} t�| �}tjjtjjd�}z|j||d�}W nN t j
k
r� } z.t�� � t
�t|�� W 5 Q R X t �� �W 5 d}~X Y nX | j�|� tj�� |�di ��dt�| ��}| �d|� zt�| i | jj|� W n\ t j
t jfk
�r: } z4t�t|d �� tj| d
� || � |�� | �W 5 d} ~ X Y nX t �!� }
|
�rV| �d|
� t�t|d �� || � t"�#� dS )a:
Common functionality to take a token and attach via contract backend
:raise UrlError: On unexpected connectivity issues to contract
server or inability to access identity doc from metadata service.
:raise ContractAPIError: On unexpected errors when talking to the contract
server.
r )�update_motd_messages)Ztz)Zcontract_tokenZ
attachment_dtNZmachineTokenInfoZ machineIdz
machine-id)�attached_at�r zinstance-id)$Zuaclient.timer.update_messagingr r �UAContractClient�datetimeZnow�timezoneZutcZadd_contract_machiner ZUrlErrorr Zdisable_log_to_console�LOGZ exception�strZConnectivityErrorZmachine_token_file�writer
Zget_machine_id�cache_clear�getZwrite_cacheZprocess_entitlements_deltar �UserFacingErrorr r � ua_statusr Zupdate_activity_tokenr Zget_instance_idr �start)r r r r �contract_clientr Znew_machine_token�eZ
machine_id�excZcurrent_iid� r. �2/usr/lib/python3/dist-packages/uaclient/actions.py�attach_with_token/ sL
�
�� r0 T)r �cloudr c C s0 t �| �}|j|d�}|d }t| ||d� dS )aS
:raise UrlError: On unexpected connectivity issues to contract
server or inability to access identity doc from metadata service.
:raise ContractAPIError: On unexpected errors when talking to the contract
server.
:raise NonAutoAttachImageError: If this cloud type does not have
auto-attach support.
)�instanceZ
contractToken)r r N)r r Z%get_contract_token_for_cloud_instancer0 )r r1 r r+ Z
tokenResponser r. r. r/ �auto_attachj s
�r3 F� )�
assume_yes�
allow_beta�access_only�variant�
extra_args)r �namer5 r6 r7 r8 r9 c C s, t j| ||d�}|| |||||d�}|�� S )z�
Constructs an entitlement based on the name provided. Passes kwargs onto
the entitlement constructor.
:raise EntitlementNotFoundError: If no entitlement with the given name is
found, then raises this error.
)r r: r8 )r5 r6 Zcalled_namer7 r9 )r Zentitlement_factory�enable) r r: r5 r6 r7 r8 r9 Zent_cls�entitlementr. r. r/ �enable_entitlement_by_name� s ��r= )�simulate_with_token�show_all)r r>