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/unattended_upgrades/status/__pycache__/v1.cpython-38.pyc
U

��Jh+.�
@s�ddlZddlZddlmZmZmZmZmZddlm	Z	m
Z
mZmZddl
mZddlmZddlmZddlmZmZddlmZdd	lmZmZmZmZmZmZmZd
ddd
gZ dZ!Gdd�de�Z"Gdd�dee�Z#e$d�dd�Z%e$ee&ee&ee&ffee$eej'fd�dd�Z(eejd�dd�Z)e#d�dd�Z*ee#d�dd�Z+ed d!e+dd"�Z,d#d$d%e#ed&fgd'd(d)d*d+�	Z-dS),�N)�Dict�List�Optional�Tuple�Union)�apt�
exceptions�messages�system)�APIEndpoint)�AdditionalInfo)�UnattendedUpgradesError)�get_apt_config_keys�get_apt_config_values)�UAConfig)�
BoolDataValue�
DataObject�DatetimeDataValue�Field�IntDataValue�StringDataValue�	data_list�APT::Periodic::Enable�#APT::Periodic::Update-Package-Lists�!APT::Periodic::Unattended-Upgrade�#Unattended-Upgrade::Allowed-Originsz#/var/lib/apt/periodic/upgrade-stampc@s8eZdZededd�ededd�gZeed�dd�Zd	S)
� UnattendedUpgradesDisabledReason�msgzHuman readable reason��doc�codezReason code�rr cCs||_||_dS�Nr!)�selfrr �r$�N/usr/lib/python3/dist-packages/uaclient/api/u/unattended_upgrades/status/v1.py�__init__%sz)UnattendedUpgradesDisabledReason.__init__N)�__name__�
__module__�__qualname__rr�fields�strr&r$r$r$r%rs�rc
@s�eZdZededd�ededd�ededd�eded	d�ed
ee�dd�eded
d�ededdd�ede	ddd�gZ
eeeee
eeeeeejd�dd�ZdS)�UnattendedUpgradesStatusResult�systemd_apt_timer_enabledz4Indicate if the ``apt-daily.timer`` jobs are enabledr�apt_periodic_job_enabledzFIndicate if the ``APT::Periodic::Enabled`` configuration is turned off�$package_lists_refresh_frequency_dayszFThe value of the ``APT::Periodic::Update-Package-Lists`` configuration�"unattended_upgrades_frequency_dayszDThe value of the ``APT::Periodic::Unattended-Upgrade`` configuration�#unattended_upgrades_allowed_originszFThe value of the ``Unattended-Upgrade::Allowed-Origins`` configuration�unattended_upgrades_runningzRIndicate if the ``unattended-upgrade`` service is correctly configured and running�#unattended_upgrades_disabled_reasonFzyObject that explains why ``unattended-upgrades`` is not running -- if the application is running, the object will be null)Zrequiredr�unattended_upgrades_last_runz)The last time ``unattended-upgrades`` ran�r-r.r/r0r1r2r3r4c	Cs4||_||_||_||_||_||_||_||_dSr"r5)	r#r-r.r/r0r1r2r3r4r$r$r%r&ks����z'UnattendedUpgradesStatusResult.__init__N)r'r(r)rrrrrrrr*�bool�intrr+r�datetimer&r$r$r$r%r,*sl�������
��C��r,)�returnc
CsXz t�d�}t�d�}|o|}Wn2tjk
rR}ztt|�d��W5d}~XYnX|S)Nzapt-daily.timerzapt-daily-upgrade.timer)Z	error_msg)r
Zis_systemd_unit_activerZProcessExecutionErrorr
r+)Zapt_daily_job_enabledZapt_daily_upgrade_job_enabledr-�er$r$r%�_get_apt_daily_job_status�s��� r;)r-�unattended_upgrades_cfgr9cCsl|sdtjfStD]T}|�|�}t|t�rD|sDdtjj|d�fS|dksP|sdtjj|d�fSqdS)NF)Zcfg_name�0)TN)	r	Z(UNATTENDED_UPGRADES_SYSTEMD_JOB_DISABLED�UNATTENDED_UPGRADES_CONFIG_KEYS�get�
isinstance�listZ(UNATTENDED_UPGRADES_CFG_LIST_VALUE_EMPTY�formatZ(UNATTENDED_UPGRADES_CFG_VALUE_TURNED_OFF)r-r<�key�valuer$r$r%�_is_unattended_upgrades_running�s"

����
rEcCs4ztj�t�}Wntk
r&YdSXtj�|�Sr")�os�path�getctime�UNATTENDED_UPGRADES_STAMP_PATH�FileNotFoundErrorr8Z
fromtimestamp)Zcreation_epochr$r$r%�!_get_unattended_upgrades_last_run�s
rKcCs
tt��Sr")�_statusrr$r$r$r%�status�srM)�cfgr9c
Cs�t�d�s2tddddgttjjtjjd�ddd�St�}t	�}t
ttt
d���}|dp\d	|d<|d
plg|d
<t||�\}}|r�t|j|jd�}nd}t|t|�dd��d	kt|�d�p�d�t|�d
�p�d�t|�d
�p�g�|||d�}d|i|_|S)a�
    This endpoint returns the status around ``unattended-upgrades``. The focus
    of the endpoint is to verify if the application is running and how it is
    configured on the machine.

    .. important::

        For this endpoint, we deliver a unique key under ``meta`` called
        ``raw_config``. This field contains all related ``unattended-upgrades``
        configurations, unparsed. This means that this field will maintain both
        original name and values for those configurations.
    zunattended-upgradesFrr!N)r-r.r/r0r1r3r2r4zUnattended-Upgrader�1r�rrZ
raw_config)rZis_installedr,rr	ZUNATTENDED_UPGRADES_UNINSTALLEDr�namer;rKr�setr>rrEr+r?r7rA�meta)rNr-r4r<r2Zdisabled_reasonr3Zunattended_upgrades_resultr$r$r%rL�s�
�����
�
����
������
��
rLZv1ZUnattendedUpgradesStatus)�versionrQ�fnZoptions_clsz27.14FzT
from uaclient.api.u.unattended_upgrades.status.v1 import status

result = status()
zYRaised if we cannot run a necessary command to show the status of ``unattended-upgrades``z'pro api u.unattended_upgrades.status.v1a@
{
    "apt_periodic_job_enabled": true,
    "package_lists_refresh_frequency_days": 1,
    "systemd_apt_timer_enabled": true,
    "unattended_upgrades_allowed_origins": [
        "${distro_id}:${distro_codename}",
        "${distro_id}:${distro_codename}-security",
        "${distro_id}ESMApps:${distro_codename}-apps-security",
        "${distro_id}ESM:${distro_codename}-infra-security"
    ],
    "unattended_upgrades_disabled_reason": null,
    "unattended_upgrades_frequency_days": 1,
    "unattended_upgrades_last_run": null,
    "unattended_upgrades_running": true
}
a�
- Possible attributes in JSON ``meta`` field:

  .. code-block:: json

     {
         "meta": {
             "environment_vars": [],
             "raw_config": {
                 "APT::Periodic::Enable": "1",
                 "APT::Periodic::Unattended-Upgrade": "1",
                 "APT::Periodic::Update-Package-Lists": "1",
                 "Unattended-Upgrade::Allowed-Origins": [
                     "${distro_id}:${distro_codename}",
                     "${distro_id}:${distro_codename}-security",
                     "${distro_id}ESMApps:${distro_codename}-apps-security",
                     "${distro_id}ESM:${distro_codename}-infra-security"
                 ]
             }
         }
     }
�)	Z
introduced_inZrequires_networkZexample_pythonZresult_classrZexample_cliZexample_jsonZextraZextra_indent).r8rF�typingrrrrrZuaclientrrr	r
Zuaclient.api.apirZuaclient.api.data_typesrZuaclient.api.exceptionsr
Zuaclient.aptrrZuaclient.configrZuaclient.data_typesrrrrrrrr>rIrr,r6r;r+ZNamedMessagerErKrMrLZendpointZ_docr$r$r$r%�<module>sX$�a�	b����