o x[h@sddlZddlZddlmZddlmZmZmZmZe e Z dgZ dZ dZGdddejZd efd d Zd efd dZeejejffgZddZdS)N)Optional)dmisources url_helperutilzhttp://169.254.169.254CloudCIXcsleZdZdZdZdZdZfddZddZde fd d Z de e fd d Z ed dZeddZZS)DataSourceCloudCIXrcs$tt||||d|_d|_dSN)superr __init__ _metadata_url_net_cfg)selfsys_cfgdistropaths __class__F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceCloudCIX.pyrs zDataSourceCloudCIX.__init__c Cs`z|}Wntjy }z td|WYd}~dSd}~ww|d|_t|d|_dS)z6 Fetch the user data and the metadata z0Failed to read data from CloudCIX datasource: %sNF meta-data user-dataT) crawl_metadata_servicerInvalidMetaDataExceptionLOGerrormetadatar decode_binary userdata_raw)r crawled_datarrrr _get_datas  zDataSourceCloudCIX._get_datareturncCs,|}|dur tdt||}|S)Nz Could not determine metadata URL)determine_md_urlrr read_metadataget_url_params)rmd_urldatarrrr/sz)DataSourceCloudCIX.crawl_metadata_servicec Cs|jr|jS|}tjt|j|jd\}}|sdSttddD]I}t |d |d}z tj ||j d}Wntj yP}z td||WYd}~q d}~ww|rct |d ||_|jStd|q |jS) N)max_waittimeoutrzv{0}r)r+zURL %s raised exception %szNo metadata found at URL %s)rr'r wait_for_url METADATA_URLSmax_wait_secondstimeout_secondsrangeMETADATA_VERSION combine_urlformatreadurl url_timeoutUrlErrorrdebugok)r url_paramsbase_url_versionurlresponseerrrr%9s:    z#DataSourceCloudCIX.determine_md_urlcCstSr )is_platform_viablerrrr ds_detect\szDataSourceCloudCIX.ds_detectcCs(|jr|jS|js dS|jd|_|jS)Nnetwork)rr)rrrrnetwork_config`s  z!DataSourceCloudCIX.network_config)__name__ __module__ __qualname__dsname url_retriesurl_timeout_secondsurl_sec_between_retriesrr#dictrrstrr% staticmethodrBpropertyrD __classcell__rrrrr s  # r r$cCstdtkS)Nzsystem-product-name)r read_dmi_dataCLOUDCIX_DMI_NAMErrrrrAksrAr;c Cs i}ddtjfddtjff}|D]r\}}}ztjt|||j|j|jd}Wntj yE}zt d|d|d|d|d }~ww| s\t d |d |d|d |j z ||j||<Wqtjjy} zt d |d|d| | d } ~ ww|S)a; Read metadata from metadata server at base_url :returns: dictionary of retrieved metadata and user data containing the following keys: meta-data, user-data :param: base_url: meta data server's base URL :param: url_params: dictionary of URL retrieval parameters. Valid keys are `retries`, `sec_between` and `timeout`. :raises: InvalidMetadataException upon network error connecting to metadata URL, error response from meta data server or failure to decode/parse metadata and userdata payload. rruserdatar)r>retries sec_betweenr+zFailed to fetch IMDS z: /Nz No valid z found. URL z returned code zInvalid JSON at )r load_jsonmaybe_b64decoderr5r3 num_retriessec_between_retriesr0r7rrr9codecontentsjsondecoderJSONDecodeError) r;r:mdleaf_key_format_callbackurl_leafnew_keyformat_callbackr?rexcrrrr&osZ    r&cCs t|tSr )rlist_from_depends datasources)dependsrrrget_datasource_lists ri)r]loggingtypingr cloudinitrrrr getLoggerrErr.r2rR DataSourcer boolrArMr&DEP_FILESYSTEM DEP_NETWORKrgrirrrrs  Z2