a 'Dg@sddlZddlZddlmZddlmZmZmZmZe e Z dgZ dZ dZGdddejZed d d Zed d dZeejejffgZddZdS)N)Optional)dmisources url_helperutilzhttp://169.254.169.254CloudCIXcsleZdZdZdZdZdZfddZddZe dd d Z e e dd d Z ed dZeddZZS)DataSourceCloudCIXrcs$tt||||d|_d|_dSN)superr __init__ _metadata_url_net_cfg)selfZsys_cfgZdistropaths __class__H/usr/lib/python3.9/site-packages/cloudinit/sources/DataSourceCloudCIX.pyrszDataSourceCloudCIX.__init__c Cs`z |}Wn4tjy@}ztd|WYd}~dSd}~00|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_servicerInvalidMetaDataExceptionLOGerrormetadatarZ decode_binaryZ userdata_raw)rZ crawled_datarrrr _get_datas  zDataSourceCloudCIX._get_datareturncCs,|}|durtdt||}|S)Nz Could not determine metadata URL)determine_md_urlrr read_metadataget_url_params)rZmd_urldatarrrr/sz)DataSourceCloudCIX.crawl_metadata_servicec Cs|jr |jS|}tjt|j|jd\}}|s4dSttddD]}t |d |d}ztj ||j d}Wn@tj y}z&td||WYd}~q@WYd}~n d}~00|rt |d ||_qq@td|q@|jS) N)Zmax_waittimeoutrzv{0}r)r%zURL %s raised exception %szNo metadata found at URL %s)rr#rZ wait_for_url METADATA_URLSZmax_wait_secondstimeout_secondsrangeMETADATA_VERSION combine_urlformatreadurlZ url_timeoutUrlErrorrdebugok)r url_paramsbase_url_versionurlresponseerrrr!9s4  " z#DataSourceCloudCIX.determine_md_urlcCstSr )is_platform_viablerrrr ds_detect\szDataSourceCloudCIX.ds_detectcCs(|jr |jS|jsdS|jd|_|jS)Nnetwork)rr)rrrrnetwork_config`s  z!DataSourceCloudCIX.network_config)__name__ __module__ __qualname__ZdsnameZ url_retriesZurl_timeout_secondsZurl_sec_between_retriesrrdictrrstrr! staticmethodr9propertyr; __classcell__rrrrr s  # r rcCstdtkS)Nzsystem-product-name)rZ read_dmi_dataCLOUDCIX_DMI_NAMErrrrr8ksr8)r2c Cs(i}ddtjfddtjff}|D]\}}}z$tjt|||j|j|jd}WnHtj y}z.t d|d|d|d|WYd }~n d }~00| st d |d |d|d |j z||j||<Wq tjjy } z*t d |d|d| | WYd } ~ q d } ~ 00q |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. rrZuserdatar)r5ZretriesZ sec_betweenr%zFailed to fetch IMDS z: /Nz No valid z found. URL z returned code zInvalid JSON at )rZ load_jsonZmaybe_b64decoderr-r+Z num_retriesZsec_between_retriesr(r.rrr0codecontentsjsondecoderZJSONDecodeError) r2r1ZmdZleaf_key_format_callbackZurl_leafZnew_keyZformat_callbackr6rexcrrrr"osR     r"cCs t|tSr )rZlist_from_depends datasources)Zdependsrrrget_datasource_listsrL)rHZloggingtypingrZ cloudinitrrrrZ getLoggerr<rr'r*rDZ DataSourcer boolr8r@r"ZDEP_FILESYSTEMZ DEP_NETWORKrKrLrrrrs  Z2