
    }f                     (   d dl Z d dlZd dlmZ d dlmZmZ d dlmZm	Z	 d dl
mZ d dl
mZmZ  ej                  e      ZdZ G d d	ej                        Zd
 Zd Z G d de      Zeej.                  ffeej.                  ej0                  ffgZd Zy)    N)List)dmisources)
EventScope	EventType)DataSourceEc2)DataSourceHostnameNicOrderzAlibaba Cloud ECSc                   z     e Zd ZU dZdgZdZg Zee   e	d<   e
d        Z fdZdedd	f fd
ZddZd Zd Z xZS )DataSourceAliYunAliYunzhttp://100.100.100.200z
2016-01-01extended_metadata_versionsc                      y)NzX-aliyun-ecs-metadata-token selfs    D/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceAliYun.pyimdsv2_token_put_headerz(DataSourceAliYun.imdsv2_token_put_header   s    ,    c                    t         t        |   |||       t        j                  | j
                        | _        | j
                  t        j                     j                  t        j                         t        j                  | _        y N)superr   __init__copydeepcopydefault_update_eventsr   NETWORKaddr   BOOTr
   NIC_NAME_fallback_nic_order)r   sys_cfgdistropaths	__class__s       r   r   zDataSourceAliYun.__init__   s_    .wF%)]]43M3M%N""":#5#56::9>>J#+#4#4 r   ci_pkl_versionreturnNc                 N    t         |   |       t        j                  | _        y r   )r   	_unpickler
   r    r!   )r   r&   r%   s     r   r)   zDataSourceAliYun._unpickle%   s    .)#+#4#4 r   c                 `    | j                   j                  d      }d}|d}d}t        ||      S )NhostnameFzlocalhost.localdomainT)metadatagetr	   )r   fqdn
resolve_ipmetadata_onlyr+   
is_defaults         r   get_hostnamezDataSourceAliYun.get_hostname)   s8    ==$$Z0
.HJ!(J77r   c                 L    t        | j                  j                  di             S )Nzpublic-keys)parse_public_keysr,   r-   r   s    r   get_public_ssh_keysz$DataSourceAliYun.get_public_ssh_keys1   s     !2!2="!EFFr   c                 ~    t               rt        j                  j                  S t        j                  j                  S r   )
_is_aliyunEC2
CloudNamesALIYUNNO_EC2_METADATAr   s    r   _get_cloud_namez DataSourceAliYun._get_cloud_name4   s'    <>>(((>>111r   )FFF)__name__
__module____qualname__dsnamemetadata_urlsmin_metadata_versionr   r   str__annotations__propertyr   r   intr)   r2   r5   r<   __classcell__)r%   s   @r   r   r      sc    F-.M (,.S	. - -55 5 58G2r   r   c                  :    t        j                  d      t        k(  S )Nzsystem-product-name)r   read_dmi_dataALIYUN_PRODUCTr   r   r   r7   r7   ;   s    23~EEr   c                    g }| j                         D ]  \  }}t        |t              r |j                  |j	                                6t        |t
              r|j                  |       Xt        |t              si|j                  dg       }t        |t              r |j                  |j	                                t        |t
              s|j                  |        |S )Nzopenssh-key)	items
isinstancerC   appendstriplistextenddictr-   )public_keyskeys_key_idkey_bodykeys        r   r4   r4   ?   s    D(..0 
!h$KK()$'KK!$',,}b1C#s#CIIK(C&C 
! Kr   c                       e Zd ZdZdZy)DataSourceAliYunLocalay  Datasource run at init-local which sets up network to query metadata.

    In init-local, no network is available. This subclass sets up minimal
    networking with dhclient on a viable nic so that it can talk to the
    metadata service. If the metadata service provides network configuration
    then render the network configuration for that instance based on metadata.
    TN)r=   r>   r?   __doc__perform_dhcp_setupr   r   r   rY   rY   O   s     r   rY   c                 6    t        j                  | t              S r   )r   list_from_dependsdatasources)dependss    r   get_datasource_listr`   b   s    $$Wk::r   )r   loggingtypingr   	cloudinitr   r   cloudinit.eventr   r   cloudinit.sourcesr   r8   r	   r
   	getLoggerr=   LOGrJ   r   r7   r4   rY   DEP_FILESYSTEMDEP_NETWORKr^   r`   r   r   r   <module>rj      s       " 1 2 :g!$'2s(( '2TF 	, 	 W3356..0C0CDE;r   