File: //lib/python3/dist-packages/uaclient/__pycache__/actions.cpython-310.pyc
o
nHJe*# � @ s� d dl Z d dlZd dlZd dlZd dlmZmZ d dlmZm Z m
Z
mZmZm
Z
d dlmZ d dlmZ d dlmZmZmZ d dlmZ d dlmZ d d lmZmZmZ d d
lmZmZmZ e� e�!e"��Z#dZ$dZ%d
e j&de'de(ddfdd�Z) d0d
e j&dejddfdd�Z*dddddd�d
e j&de'de(de(de(de'deee' fd d!�Z+ddd"�d
e j&d#ee' d$e(fd%d&�Z d1d'e'd(eee, ddfd)d*�Z-d
e j&fd+d,�Z.d
e j&d-e'fd.d/�Z/dS )2� N)�List�Optional)�clouds�config�contract�entitlements�
exceptions� livepatch)�log)�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 sN ddl m} t�| �}tjjtjjd�}z |j||d�}W n t j
y5 } zt�t
|�� t �� �d}~ww | j�|� tj�� |�di ��dt�| ��}| �d|� zt�| i | jj|� W n( t j
t jfy� } zt�t|d �� tj| d
� || � |�� | �d} ~ ww t�� }
|
r�| �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)�tz)�contract_token�
attachment_dtN�machineTokenInfo� machineIdz
machine-id)�attached_at�r zinstance-id)"�uaclient.timer.update_messagingr r �UAContractClient�datetime�now�timezone�utc�add_contract_machiner �UrlError�LOG� exception�str�ConnectivityError�machine_token_file�writer �get_machine_id�cache_clear�get�write_cache�process_entitlements_deltar �UbuntuProErrorr r � ua_statusr �update_activity_tokenr �get_instance_idr
�start)r r r r �contract_clientr"