
    x[h                         S SK r S SKrS SKJr  S SKJrJrJrJr  \R                  " \
5      rS/rSrSr " S S\R                  5      rS	\4S
 jrS\4S jr\\R*                  \R,                  44/rS rg)    N)Optional)dmisources
url_helperutilzhttp://169.254.169.254   CloudCIXc                      ^  \ rS rSrSrSrSrSrU 4S jrS r	S\
4S jrS\\   4S	 jr\S
 5       r\S 5       rSrU =r$ )DataSourceCloudCIX   r	         c                 J   > [         [        U ]  XU5        S U l        S U l        g N)superr   __init___metadata_url_net_cfg)selfsys_cfgdistropaths	__class__s       F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceCloudCIX.pyr   DataSourceCloudCIX.__init__   s$     $0%H!    c                      U R                  5       nUS   U l        [        R                  " US   5      U l        g! [        R                   a   n[        R	                  SU5         SnAgSnAff = f)z&
Fetch the user data and the metadata
z0Failed to read data from CloudCIX datasource: %sNF	meta-data	user-dataT)	crawl_metadata_servicer   InvalidMetaDataExceptionLOGerrormetadatar   decode_binaryuserdata_raw)r   crawled_datar#   s      r   	_get_dataDataSourceCloudCIX._get_data   sl    	668L %[1 ..|K/HI // 	IIBE 		s   ; A/A**A/returnc                     U R                  5       nUc  [        R                  " S5      e[        XR	                  5       5      nU$ )Nz Could not determine metadata URL)determine_md_urlr   r!   read_metadataget_url_params)r   md_urldatas      r   r    )DataSourceCloudCIX.crawl_metadata_service/   sE    &&(>222  V%8%8%:;r   c                    U R                   (       a  U R                   $ U R                  5       n[        R                  " [        UR
                  UR                  S9u  p#U(       d  g [        [        SS5       H  n[        R                  " USR                  U5      S5      n [        R                  " XPR                  S9nUR!                  5       (       a8  [        R                  " USR                  U5      5      U l           U R                   $ [        R                  SU5        M     U R                   $ ! [        R                   a!  n[        R                  SXW5         S nAM  S nAff = f)	N)max_waittimeoutr   zv{0}r$   )r4   zURL %s raised exception %szNo metadata found at URL %s)r   r.   r   wait_for_urlMETADATA_URLSmax_wait_secondstimeout_secondsrangeMETADATA_VERSIONcombine_urlformatreadurlurl_timeoutUrlErrorr"   debugok)r   
url_paramsbase_url_versionurlresponsees           r   r,   #DataSourceCloudCIX.determine_md_url9   s1   %%% ((*
 --00..

  -q"5G((&--0*C%--c;K;KL
 {{}}%/%;%;fmmG4&"  !!! 		7=! 6$ !!! && 		6?s   "D33E(E##E(c                      [        5       $ r   )is_platform_viable r   r   	ds_detectDataSourceCloudCIX.ds_detect\   s    !##r   c                     U R                   (       a  U R                   $ U R                  (       d  g U R                  S   U l         U R                   $ )Nnetwork)r   r$   )r   s    r   network_config!DataSourceCloudCIX.network_config`   s7    ==== }}i0}}r   )r   r   r$   r&   )__name__
__module____qualname____firstlineno__dsnameurl_retriesurl_timeout_secondsurl_sec_between_retriesr   r(   dictr    r   strr,   staticmethodrN   propertyrR   __static_attributes____classcell__)r   s   @r   r   r      sh    FK
" !"(3- !"F $ $  r   r   r*   c                  <    [         R                  " S5      [        :H  $ )Nzsystem-product-name)r   read_dmi_dataCLOUDCIX_DMI_NAMErM   r   r   rL   rL   k   s    237HHHr   rD   c                    0 nSS[         R                  4SS[         R                  44nU H  u  pEn [        R                  " [        R
                  " X5      UR                  UR                  UR                  S9nUR                  5       (       d,  [        R                  " S
U SU  SU SUR                   35      e U" UR                  5      X%'   M     U$ ! [        R                   a'  n[        R                  " SU SU  SU SU 35      eS	nAff = f! [        R                   R"                   a%  n	[        R                  " SU  SU SU	 35      U	eS	n	A	ff = f)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.
r$   r   userdatar   )rG   retriessec_betweenr4   zFailed to fetch IMDS z: /Nz	No valid z found. URL z returned code zInvalid JSON at )r   	load_jsonmaybe_b64decoder   r>   r<   num_retriessec_between_retriesr9   r@   r   r!   rB   codecontentsjsondecoderJSONDecodeError)
rD   rC   mdleaf_key_format_callbackurl_leafnew_keyformat_callbackrH   r#   excs
             r   r-   r-   o   sv    
B	[$..1	[$"6"67 
 /G*?	!))**8>"..&::"22	H {{}}22H: &j(?8==/K 
	)(*;*;<BK+ /G4 I% "" 	22'z*AhZr%2 	 ||++ 	22"8*AhZr#?	s0   A	C=DD+"DDE3 EEc                 8    [         R                  " U [        5      $ r   )r   list_from_dependsdatasources)dependss    r   get_datasource_listr}      s    $$Wk::r   )rp   loggingtypingr   	cloudinitr   r   r   r   	getLoggerrT   r"   r7   r;   rd   
DataSourcer   boolrL   r]   r-   DEP_FILESYSTEMDEP_NETWORKr{   r}   rM   r   r   <module>r      s       4 4!)*  W++ WtID I-C -d '00'2E2EFG;r   