3 \¼meÝ ã@s´ddlZddlmZddlmZmZddlmZmZddl m Z ddl m Z ej eƒZdZGdd „d e j ƒZd d „Zd d „ZGdd„deƒZeejffeejejffgZdd„ZdS)éN)ÚList)ÚdmiÚsources)Ú EventScopeÚ EventType)Ú DataSourceEc2)ÚDataSourceHostnamezAlibaba Cloud ECScs^eZdZUdZdgZdZgZeee dd„ƒZ ‡fdd„Z dd d „Z d d „Z d d„Z‡ZS)ÚDataSourceAliYunZAliYunzhttp://100.100.100.200z 2016-01-01cCsdS)NzX-aliyun-ecs-metadata-token©)Úselfr r ú&/usr/lib/python3.6/DataSourceAliYun.pyÚimdsv2_token_put_headersz(DataSourceAliYun.imdsv2_token_put_headercs,tt|ƒj|||ƒ|jtjjtjƒdS)N) Úsuperr Ú__init__Zdefault_update_eventsrZNETWORKÚaddrZBOOT)r Zsys_cfgZdistroÚpaths)Ú __class__r r rszDataSourceAliYun.__init__FcCs*|jjdƒ}d}|dkr d}d}t||ƒS)NÚhostnameFzlocalhost.localdomainT)ÚmetadataÚgetr)r ZfqdnZ resolve_ipZ metadata_onlyrZ is_defaultr r r Ú get_hostname"s  zDataSourceAliYun.get_hostnamecCst|jjdiƒƒS)Nz public-keys)Úparse_public_keysrr)r r r r Úget_public_ssh_keys*sz$DataSourceAliYun.get_public_ssh_keyscCstƒrtjjStjjSdS)N)Ú _is_aliyunÚEC2Z CloudNamesZALIYUNZNO_EC2_METADATA)r r r r Ú_get_cloud_name-sz DataSourceAliYun._get_cloud_name)FFF)Ú__name__Ú __module__Ú __qualname__ZdsnameZ metadata_urlsZmin_metadata_versionZextended_metadata_versionsrÚstrÚpropertyr rrrrÚ __classcell__r r )rr r s     r cCstjdƒtkS)Nzsystem-product-name)rZ read_dmi_dataÚALIYUN_PRODUCTr r r r r4srcCs’g}xˆ|jƒD]|\}}t|tƒr0|j|jƒƒqt|tƒrF|j|ƒqt|tƒr|jdgƒ}t|tƒrv|j|jƒƒqt|tƒr|j|ƒqW|S)Nz openssh-key) ÚitemsÚ isinstancerÚappendÚstripÚlistÚextendÚdictr)Z public_keysÚkeysZ_key_idZkey_bodyÚkeyr r r r8s       rc@seZdZdZdZdS)ÚDataSourceAliYunLocalayDatasource 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)rrrÚ__doc__Zperform_dhcp_setupr r r r r,Hsr,cCs tj|tƒS)N)rZlist_from_dependsÚ datasources)Zdependsr r r Úget_datasource_list[sr/)ZloggingZtypingrZ cloudinitrrZcloudinit.eventrrZcloudinit.sourcesrrrZ getLoggerrZLOGr"r rrr,ZDEP_FILESYSTEMZ DEP_NETWORKr.r/r r r r Ús    $