
    fi                        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 j$                   ej&                  e            Zddd	d
ddZej.                  j0                  ej.                  j2                  ej.                  j4                  dZ G d de      Zdee   fdZ ed       ed      deee   ee   f   fd              Z	 ddee   dej@                  fdZ!y)    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                       e Zd ZdZdZy)NoCloudTypeReasonr      N)__name__
__module____qualname__NO_CLOUD_DETECTEDCLOUD_ID_ERROR     :/usr/lib/python3/dist-packages/uaclient/clouds/identity.pyr   r      s    Nr   r   returnc                      	 t        j                  g d      \  } }| j                         S # t        j                  $ r Y nw xY wt
        j                  d       y)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_errs     r    get_instance_idr,      sN    KK FG	Tyy{++ KK9:s   ), AA)maxsize
cloud_typec                  J   t        j                  d      r,	 t        j                  dg      \  } }| j                         d fS d t        j                  fS # t        j
                  $ r;}t        j                  dt        |             d t        j                  fcY d }~S d }~ww xY w)Nzcloud-idzerror running cloud-id: %s)r   whichr%   r&   r
   r'   r(   debugstrr   r   r   )r*   r+   excs      r    get_cloud_typer4   +   s     ||J	<ZL1ICIIK&&
 #5566	 // 	<II2CH=+::;;	<s   *A B"'0BB"B"cloud_overridec                 ~   ddl m}m}m} |j                  |j                  |j                  |j
                  |j                  d}| | }nt               \  }}|st        j                         |j                  |      }|st        j                  |       |       }|j                  st        j                         |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   )r.   )uaclient.cloudsr   r   r7   UAAutoAttachAWSInstanceUAAutoAttachAzureInstanceUAAutoAttachGCPInstancer4   r
   CloudFactoryNoCloudErrorgetNonAutoAttachImageError	is_viableCloudFactoryNonViableCloudError)	r5   r   r   r7   cloud_instance_mapr.   _clsinstances	            r    cloud_instance_factoryrE   :   s     0/ **00..00** !#
&(
A1133

 
 
,C00JGGuH88::Or   )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   r2   r,   r4   AutoAttachCloudInstancerE   r   r   r    <module>rU      s      . . ? ? :g:::8DE   ==--]]11==-- 
	# 	 4-
7hsmX6G-HHI 
7 . 
7 %)#SM####r   