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

��Jh<�	@sddlZddlmZmZddlmZddlmZddlm	Z	ddl
mZmZm
Z
mZmZddlmZmZddlmZGd	d
�d
ee�ZejGdd�dej��Ze	eeeeeefd
�dd�Zed�dd�Ze	ed�dd�Zeddedd�Zdddegdddd�ZdS) �N)�Optional�Tuple)�APIEndpoint)�AdditionalInfo)�UAConfig)�
BoolDataValue�
DataObject�Field�IntDataValue�StringDataValue)�!CONTRACT_EXPIRY_GRACE_PERIOD_DAYS�CONTRACT_EXPIRY_PENDING_DAYS)�
machine_tokenc@sZeZdZededd�ededdd�ededd�ed	ed
d�gZee	e
eed�dd
�ZdS)�IsAttachedResult�is_attachedz=True if the machine is attached to an Ubuntu Pro subscription)�doc�contract_statusFz%Status of the Ubuntu Pro subscription�contract_remaining_daysz2Number of days left in the Ubuntu Pro subscription�is_attached_and_contract_validzbTrue if the machine is attached to an Ubuntu Pro subscription and that subscription is not expired�rrrrcCs||_||_||_||_dS�Nr)�selfrrrr�r�J/usr/lib/python3/dist-packages/uaclient/api/u/pro/status/is_attached/v1.py�__init__3szIsAttachedResult.__init__N)
�__name__�
__module__�__qualname__r	rrr
Zfields�boolr�str�intrrrrrrs6����� �rc@s eZdZdZdZdZdZdZdS)�ContractExpiryStatusNZactivezactive-soon-to-expirezgrace-periodZexpired)rrr�NONE�ACTIVE�ACTIVE_EXPIRED_SOON�EXPIRED_GRACE_PERIOD�EXPIREDrrrrr!As
r!)�cfg�is_machine_attached�remaining_days�returncCs�|stjdfSt}t}|dkr*tj|fSd|kr>|krLnn
tj|fS||krbdkrpnn
tj|fS||kr�tj|fStj|fS)z/Return a tuple [ContractExpiryStatus, num_days]rN)r!r"rr
r&r$r%r#)r'r(r)Zgrace_periodZpending_expiryrrr�_get_contract_expiry_statusJs




r+)r*cCs
tt��Sr)�_is_attachedrrrrrrcsr)r'r*cCsNt�|�}t|j�}t|||j�\}}d}|r8|tjkr<d}t||j||d�S)zO
    This endpoint shows if the machine is attached to a Pro subscription.
    TFr)	rZget_machine_token_filerr+rr!r&r�value)r'Zmachine_token_filer(rr)rrrrr,gs&

����r,Zv1Z
IsAttached)�version�name�fnZoptions_clsZ28FzZ
from uaclient.api.u.pro.status.is_attached.v1 import is_attached

result = is_attached()
z#pro api u.pro.status.is_attached.v1z�
{
    "contract_remaining_days": 360,
    "contract_status": "active",
    "is_attached": true,
    "is_attached_and_contract_valid": true
}
a�
.. tab-item:: Explanation
    :sync: explanation

    The ``contract_status`` field can return 4 different states, they are:

    * **active**: The contract is currently valid.
    * **grace-period**: The contract is in the grace period. This means that
      it is expired, but there are still some days where the contract will be
      valid.
    * **active-soon-to-expire**: The contract is almost expired, but still
      valid.
    * **expired**: The contract is expired and no longer valid.
)Z
introduced_inZrequires_networkZexample_pythonZresult_class�
exceptionsZexample_cliZexample_jsonZextra) �enum�typingrrZuaclient.api.apirZuaclient.api.data_typesrZuaclient.configrZuaclient.data_typesrrr	r
rZuaclient.defaultsrr
Zuaclient.filesrr�unique�Enumr!rr r+rr,ZendpointZ_docrrrr�<module>s@,	
���