o
    ¦®Øf  ã                   @   sÀ   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 e¡ZdZG dd	„ d	ejƒZd
d„ Zdd„ ZG dd„ deƒZeejffeejejffgZdd„ ZdS )é    N)ÚList)ÚdmiÚsources)Ú
EventScopeÚ	EventType)ÚDataSourceEc2)ÚDataSourceHostnameÚNicOrderzAlibaba Cloud ECSc                       sx   e Zd ZU dZdgZdZg Zee e	d< e
dd„ ƒZ‡ fdd„Zd	ed
df‡ fdd„Zddd„Zdd„ Zdd„ Z‡  ZS )ÚDataSourceAliYunÚAliYunzhttp://100.100.100.200z
2016-01-01Úextended_metadata_versionsc                 C   s   dS )NzX-aliyun-ecs-metadata-token© ©Úselfr   r   úD/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceAliYun.pyÚimdsv2_token_put_header   s   z(DataSourceAliYun.imdsv2_token_put_headerc                    sB   t t| ƒ |||¡ t | j¡| _| jtj  t	j
¡ tj| _d S ©N)Úsuperr
   Ú__init__ÚcopyÚdeepcopyÚdefault_update_eventsr   ÚNETWORKÚaddr   ÚBOOTr	   ÚNIC_NAMEÚ_fallback_nic_order)r   Úsys_cfgÚdistroÚpaths©Ú	__class__r   r   r      s   zDataSourceAliYun.__init__Úci_pkl_versionÚreturnNc                    s   t ƒ  |¡ tj| _d S r   )r   Ú	_unpickler	   r   r   )r   r"   r    r   r   r$   %   s   zDataSourceAliYun._unpickleFc                 C   s*   | j  d¡}d}|d u rd}d}t||ƒS )NÚhostnameFzlocalhost.localdomainT)ÚmetadataÚgetr   )r   ÚfqdnÚ
resolve_ipÚmetadata_onlyr%   Ú
is_defaultr   r   r   Úget_hostname)   s   
zDataSourceAliYun.get_hostnamec                 C   s   t | j di ¡ƒS )Nzpublic-keys)Úparse_public_keysr&   r'   r   r   r   r   Úget_public_ssh_keys1   s   z$DataSourceAliYun.get_public_ssh_keysc                 C   s   t ƒ rtjjS tjjS r   )Ú
_is_aliyunÚEC2Ú
CloudNamesÚALIYUNÚNO_EC2_METADATAr   r   r   r   Ú_get_cloud_name4   s   z DataSourceAliYun._get_cloud_name)FFF)Ú__name__Ú
__module__Ú__qualname__ÚdsnameÚmetadata_urlsÚmin_metadata_versionr   r   ÚstrÚ__annotations__Úpropertyr   r   Úintr$   r,   r.   r4   Ú__classcell__r   r   r    r   r
      s   
 

r
   c                   C   s   t  d¡tkS )Nzsystem-product-name)r   Úread_dmi_dataÚALIYUN_PRODUCTr   r   r   r   r/   ;   s   r/   c                 C   sŽ   g }|   ¡ D ]>\}}t|tƒr| | ¡ ¡ qt|tƒr"| |¡ qt|tƒrD| dg ¡}t|tƒr:| | ¡ ¡ qt|tƒrD| |¡ q|S )Nzopenssh-key)	ÚitemsÚ
isinstancer;   ÚappendÚstripÚlistÚextendÚdictr'   )Úpublic_keysÚkeysÚ_key_idÚkey_bodyÚkeyr   r   r   r-   ?   s   





€r-   c                   @   s   e Zd ZdZdZdS )Ú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)r5   r6   r7   Ú__doc__Úperform_dhcp_setupr   r   r   r   rN   O   s    rN   c                 C   s   t  | t¡S r   )r   Úlist_from_dependsÚdatasources)Údependsr   r   r   Úget_datasource_listc   s   rT   )r   ÚloggingÚtypingr   Ú	cloudinitr   r   Úcloudinit.eventr   r   Úcloudinit.sourcesr   r0   r   r	   Ú	getLoggerr5   ÚLOGrA   r
   r/   r-   rN   ÚDEP_FILESYSTEMÚDEP_NETWORKrR   rT   r   r   r   r   Ú<module>   s"   
*
þ