Your IP : 216.73.216.52


Current Path : /usr/lib/python3/dist-packages/uaclient/jobs/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/uaclient/jobs/__pycache__/update_messaging.cpython-38.pyc

U

8�-d��@s�dZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
mZmZddl
mZddlmZddlmZmZdd	lmZd
ZdZejGdd
�d
ej��Zed�dd�Zeeeefd�dd�Zeed�dd�Z dd�Z!dS)a%
Update messaging text for use in MOTD and APT custom Ubuntu Pro messages.

Messaging files will be emitted to /var/lib/ubuntu-advantage/message-* which
will be sourced by apt-hook/hook.cc and various /etc/update-motd.d/ hooks to
present updated text about Ubuntu Pro service and token state.
�N)�exists)�Tuple)�contract�defaults�messages�system)�_updates)�UAConfig)�ESMAppsEntitlement�ESMInfraEntitlement)�ApplicationStatuszmotd-contract-statusz6/usr/lib/update-notifier/update-motd-updates-availablec@s eZdZdZdZdZdZdZdS)�ContractExpiryStatusr����N)�__name__�
__module__�__qualname__�NONE�ACTIVE�ACTIVE_EXPIRED_SOON�EXPIRED_GRACE_PERIOD�EXPIRED�rr�@/usr/lib/python3/dist-packages/uaclient/jobs/update_messaging.pyr
s
r
)�cfgcCs�|j}|�dd�}|�di��di��dd�}t�|�}|�||�}|�di��di��dd�}|dk	r�||jjkr�||ddd<|j�|�dS)NZmachineToken�ZmachineTokenInfoZcontractInfo�idZeffectiveTo)�
machine_token�getrZUAContractClientZget_updated_contract_info�machine_token_file�contract_expiry_datetime�write)rZ
orig_tokenrZcontract_idZcontract_clientZrespZresp_expiryrrr�update_contract_expiry&s@���
�����
��
�r$)r�returncCs�|jstjdfStj}tj}|jj}|dkrBt�	d�tj
|fSd|krV|krdnn
tj|fS||krzdkr�nn
tj|fS||kr�tj
|fStj
|fS)z/Return a tuple [ContractExpiryStatus, num_days]rNz:contract effectiveTo date is null - assuming it is expired)�is_attachedr
rr�!CONTRACT_EXPIRY_GRACE_PERIOD_DAYSZCONTRACT_EXPIRY_PENDING_DAYSr!Zcontract_remaining_days�loggingZwarningrrrr)rZgrace_periodZpending_expiry�remaining_daysrrr�get_contract_expiry_statusAs"
�



r*cCs�|js
dSt�d�tj�|jdt�}t|�\}}|t	j
t	jt	jfkrZt
|�t|�\}}|t	jt	jfkrxt�|��n&|t	j
kr�t�|tjj|d���n|t	jkr�tj|}|jj}|dkr�d}n
|�d�}t�|tjj||d��n�|t	jk�r�d	}d
}t���r6t|���\}	}
|	tj k�rld}t!|�j"j#}n6t�$��rlt%|���\}}
|tj k�rld}t!|�j"j&}|d
k�r�t�|tj'�nt�|tj(j||d
��dS)z�Emit human-readable status message used by motd.

    Used by /etc/update.motd.d/91-contract-ua-esm-status

    :param cfg: UAConfig instance for this environment.
    Fz&Updating Ubuntu Pro messages for MOTD.r)r)NZUnknownz%d %b %Y)Zexpired_dater)zn/arz	esm-infrazesm-apps)�pkg_num�serviceT))r&r(�debug�os�path�joinZdata_dir�MOTD_CONTRACT_STATUS_FILE_NAMEr*r
rrrr$rrrZensure_file_absentZ
write_filerZCONTRACT_EXPIRES_SOON_MOTD�formatrr'r!r"�strftimeZ"CONTRACT_EXPIRED_GRACE_PERIOD_MOTDZis_current_series_active_esmrZapplication_statusrZENABLED�api_u_pro_packages_updates_v1ZsummaryZnum_esm_infra_updatesZis_current_series_ltsr
Znum_esm_apps_updatesZCONTRACT_EXPIRED_MOTD_NO_PKGSZCONTRACT_EXPIRED_MOTD_PKGS)rZmotd_contract_status_msg_pathZ
expiry_statusr)Zgrace_period_remainingZexp_dtZ
exp_dt_strr,r+Zesm_infra_status�_Zesm_apps_statusrrr�update_motd_messages\s�
���
��
�
��
�

�
���r6c
CsLtt�rHzt�tdg�Wn,tk
rF}zt�|�W5d}~XYnXdS)Nz--force)r�UPDATE_NOTIFIER_MOTD_SCRIPTrZsubp�	Exceptionr(Z	exception)�excrrr�refresh_motd�s
r:)"�__doc__�enumr(r.�os.pathr�typingrZuaclientrrrrZ&uaclient.api.u.pro.packages.updates.v1rr4Zuaclient.configr	Zuaclient.entitlementsr
rZ(uaclient.entitlements.entitlement_statusrr1r7�unique�Enumr
r$�intr*�boolr6r:rrrr�<module>s*�
�X