
    x[h                         d dl Z d dlZd dlmZ d dlmZmZmZmZ  ej                  e
      ZdgZdZdZ G d dej                        Zd	efd
ZdefdZeej*                  ej,                  ffgZd Zy)    N)Optional)dmisources
url_helperutilzhttp://169.254.169.254   CloudCIXc                   r     e Zd ZdZdZdZdZ fdZd Zde	fdZ
dee   fdZed	        Zed
        Z xZS )DataSourceCloudCIXr	         c                 L    t         t        |   |||       d | _        d | _        y N)superr   __init___metadata_url_net_cfg)selfsys_cfgdistropaths	__class__s       F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceCloudCIX.pyr   zDataSourceCloudCIX.__init__   s&     $0&%H!    c                     	 | j                         }|d   | _        t        j                  |d         | _        y# t        j                  $ r }t        j	                  d|       Y d}~yd}~ww xY w)z6
        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_datazDataSourceCloudCIX._get_data   sl    	668L %[1 ..|K/HI // 	IIBE 		s   : A-A((A-returnc                     | j                         }|t        j                  d      t        || j	                               }|S )Nz Could not determine metadata URL)determine_md_urlr   r   read_metadataget_url_params)r   md_urldatas      r   r   z)DataSourceCloudCIX.crawl_metadata_service/   sG    &&(>222  VT%8%8%:;r   c                    | j                   r| j                   S | j                         }t        j                  t        |j
                  |j                        \  }}|sy t        t        dd      D ]  }t        j                  |dj                  |      d      }	 t        j                  || j                        }|j!                         r7t        j                  |dj                  |            | _          | j                   S t        j                  d|        | j                   S # t        j                  $ r!}t        j                  d||       Y d }~d }~ww xY w)	N)max_waittimeoutr   zv{0}r"   )r0   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)   z#DataSourceCloudCIX.determine_md_url9   s:   %%% ((*
 --00..
!
  -q"5 	>G((&--0*C%--c4;K;KL
 {{}%/%;%;fmmG4&"  !!! 		7=!	>$ !!! && 		6Q?s   !D&&E9EEc                      t               S r   )is_platform_viable r   r   	ds_detectzDataSourceCloudCIX.ds_detect\   s    !##r   c                     | j                   r| j                   S | j                  sy | j                  d   | _         | j                   S )Nnetwork)r   r"   )r   s    r   network_configz!DataSourceCloudCIX.network_config`   s7    ==== }}i0}}r   )__name__
__module____qualname__dsnameurl_retriesurl_timeout_secondsurl_sec_between_retriesr   r&   dictr   r   strr)   staticmethodrI   propertyrL   __classcell__)r   s   @r   r   r      sh    FK
" !"(3- !"F $ $  r   r   r'   c                  :    t        j                  d      t        k(  S )Nzsystem-product-name)r   read_dmi_dataCLOUDCIX_DMI_NAMErH   r   r   rG   rG   k   s    237HHHr   r@   c                    i }ddt         j                  fddt         j                  ff}|D ]  \  }}}	 t        j                  t        j
                  | |      |j                  |j                  |j                        }|j                         s+t        j                  d
| d|  d| d|j                         	  ||j                        ||<    |S # t        j                  $ r&}t        j                  d| d|  d| d|       d	}~ww xY w# t        j                   j"                  $ r$}	t        j                  d|  d| d|	       |	d	}	~	ww xY w)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   )rC   retriessec_betweenr0   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:   r8   num_retriessec_between_retriesr5   r<   r   r   r>   codecontentsjsondecoderJSONDecodeError)
r@   r?   mdleaf_key_format_callbackurl_leafnew_keyformat_callbackrD   r!   excs
             r   r*   r*   o   s~    
B	[$..1	[$"6"67 
 /G *'?	!))**8X>"..&::"22	H {{}22H: &j(?8==/K 
	)(*;*;<BwK+4 I% "" 	22'z*AhZr%2 	 ||++ 	22"8*AhZr#?	s0   AC:DD&!DDE,EEc                 6    t        j                  | t              S r   )r   list_from_dependsdatasources)dependss    r   get_datasource_listrt      s    $$Wk::r   )rg   loggingtypingr   	cloudinitr   r   r   r   	getLoggerrM   r    r3   r7   r[   
DataSourcer   boolrG   rU   r*   DEP_FILESYSTEMDEP_NETWORKrr   rt   rH   r   r   <module>r}      s       4 4g!)*  W++ WtID I-C -d '00'2E2EFG;r   