o
    ϴfi                     @   s
  d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	 d dl
mZmZmZmZmZ d dlmZ e eeZddd	d
ddZejjejjejjdZG dd deZdee fddZeddeddeee ee f fddZ	ddee dej fddZ!dS )    N)Enum)	lru_cache)DictOptionalTupleType)clouds
exceptionsmessagessystemutil)apply_config_settings_overrideAWSz	AWS ChinazAWS GovAzureGCPawsz	aws-chinazaws-govazuregce)r   r   r   c                   @   s   e Zd ZdZdZdS )NoCloudTypeReasonr      N)__name__
__module____qualname__NO_CLOUD_DETECTEDCLOUD_ID_ERROR r   r   :/usr/lib/python3/dist-packages/uaclient/clouds/identity.pyr      s    r   returnc                  C   s@   zt g d\} }|  W S  tjy   Y nw td dS )z%Query cloud instance-id from cmdline.)z
cloud-initqueryinstance_idz'Unable to determine current instance-idN)r   subpstripr	   ProcessExecutionErrorLOGwarning)out_errr   r   r   get_instance_id   s   

r(   )maxsize
cloud_typec               
   C   st   t dr5zt dg\} }|  d fW S  tjy4 } ztdt| d t	j
fW  Y d }~S d }~ww d t	jfS )Nzcloud-idzerror running cloud-id: %s)r   whichr!   r"   r	   r#   r$   debugstrr   r   r   )r&   r'   excr   r   r   get_cloud_type+   s   

r/   cloud_overridec           	      C   s   ddl m}m}m} |j|j|j|j|jd}| dur| }nt \}}|s)t	 |
|}|s6tj|d| }|js@t |S )a  
    :raises CloudFactoryError: if no cloud instance object can be constructed
    :raises CloudFactoryNoCloudError: if no cloud instance object can be
        constructed because we are not on a cloud
    :raises CloudFactoryUnsupportedCloudError: if no cloud instance object can
        be constructed because we don't have a class for the cloud we're on
    :raises CloudFactoryNonViableCloudError: if no cloud instance object can be
        constructed because we explicitly do not support the cloud we're on
    r   )r   r   gcpr   N)r*   )uaclient.cloudsr   r   r1   UAAutoAttachAWSInstanceUAAutoAttachAzureInstanceUAAutoAttachGCPInstancer/   r	   CloudFactoryNoCloudErrorgetNonAutoAttachImageError	is_viableCloudFactoryNonViableCloudError)	r0   r   r   r1   cloud_instance_mapr*   _clsinstancer   r   r   cloud_instance_factory:   s&   

r?   )N)"loggingenumr   	functoolsr   typingr   r   r   r   uaclientr   r	   r
   r   r   uaclient.configr   	getLoggerreplace_top_level_logger_namer   r$   CLOUD_TYPE_TO_TITLEurlsPRO_ON_AWS_HOME_PAGEPRO_ON_AZURE_HOME_PAGEPRO_ON_GCP_HOME_PAGEPRO_CLOUD_URLSr   r-   r(   r/   AutoAttachCloudInstancer?   r   r   r   r   <module>   s8    	"