Ë
    x[h~"  ã                   óÞ  — d dl Z d dlmZmZmZmZmZmZ d dlm	Z	  e j                  e«      ZdZdZdZdZdZd	Z G d
„ dej&                  «      Zeej*                  ej,                  ffgZd„ Zeeeeefd„Zeeeeefd„Zedk(  rëd dlZ ej8                  d¬«      Zej=                  ddde¬«       ej=                  ddde¬«       ej=                  ddede¬«       ej=                  ddede¬«       ej=                  dd ed!e¬«       ejA                  «       Z! ee!jD                  e!jF                  e!jH                  e!jJ                  e!jL                  ¬"«      Z' e( ejR                  e'«      «       yy)#é    N)Úatomic_helperÚdmiÚhelpersÚsourcesÚ
url_helperÚutil)Úec2zhttp://169.254.169.254z1.0i�  é
   é   ÚExoscalec                   óT   ‡ — e Zd ZdZdZˆ fd„Zd„ Zd„ Zd„ Zd„ Z	d„ Z
ed	„ «       Zˆ xZS )
ÚDataSourceExoscaler   éx   c                 óì  •— t         t        | �  |||«       t        j	                  d«       | j
                  j                  dt        «      | _        | j
                  j                  dt        «      | _
        t        | j
                  j                  dt        «      «      | _        | j
                  j                  dt        «      | _        | j
                  j                  dt         «      | _        i | _        y )Nz$Initializing the Exoscale datasourceÚmetadata_urlÚapi_versionÚpassword_server_portÚtimeoutÚretries)Úsuperr   Ú__init__ÚLOGÚdebugÚds_cfgÚgetÚMETADATA_URLr   ÚAPI_VERSIONr   ÚintÚPASSWORD_SERVER_PORTr   ÚURL_TIMEOUTÚurl_timeoutÚURL_RETRIESÚurl_retriesÚextra_config)ÚselfÚsys_cfgÚdistroÚpathsÚ	__class__s       €úF/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceExoscale.pyr   zDataSourceExoscale.__init__   s«   ø€ ÜÔ  $Ñ0°¸&À%ÔHÜ�	‰	Ð8Ô9à ŸK™KŸO™O¨N¼LÓIˆÔØŸ;™;Ÿ?™?¨=¼+ÓFˆÔÜ$'Ø�K‰K�O‰OÐ2Ô4HÓIó%
ˆÔ!ð  Ÿ;™;Ÿ?™?¨9´kÓBˆÔØŸ;™;Ÿ?™?¨9´kÓBˆÔØˆÕó    c                 ó¾   — d}| j                   j                  d«      }t        j                  |«      }|j	                  d|z   d«      rt
        j                  d«       yy)z<Adjust set_passwords module to run 'always' during each bootÚset_passwordsÚsemÚconfig_Nz5Overriding module set_passwords with frequency always)r(   Úget_ipath_curr   ÚFileSemaphoresÚclearr   r   )r%   ÚcfgÚis_new_instanceÚmodÚsem_pathÚ
sem_helpers         r*   ÚactivatezDataSourceExoscale.activate*   sS   € ð ˆØ—:‘:×+Ñ+¨EÓ2ˆÜ×+Ñ+¨HÓ5ˆ
Ø×Ñ˜I¨™O¨TÔ2Ü�I‰IÐMÕNð 3r+   c                 óâ   — dj                  | j                  | j                  «      }t        j                  |g| j
                  | j                  t        j                  ¬«      \  }}t        |«      S )z.Wait for the metadata service to be reachable.z{}/{}/meta-data/instance-id)ÚurlsÚmax_waitr   Ú	status_cb)
Úformatr   r   r   Úwait_for_urlÚurl_max_waitr!   r   ÚcriticalÚbool)r%   r   ÚurlÚ	_responses       r*   Úwait_for_metadata_servicez,DataSourceExoscale.wait_for_metadata_service9   se   € ð 5×;Ñ;Ø×Ñ˜t×/Ñ/ó
ˆô $×0Ñ0Ø�Ø×&Ñ&Ø×$Ñ$Ü—l‘lô	
‰ˆˆYô �C‹yÐr+   c                 óÖ   — | j                  «       }|st        j                  d«       i S t        | j                  | j
                  | j                  | j                  | j                  «      S )zw
        Crawl the metadata service when available.

        @returns: Dictionary of crawled metadata content.
        z,Unable to get response from metadata service)	rD   r   ÚerrorÚread_metadatar   r   r   r!   r#   )r%   Úmetadata_readys     r*   Úcrawl_metadataz!DataSourceExoscale.crawl_metadataI   sa   € ð ×7Ñ7Ó9ˆáÜ�I‰IÐDÔEØˆIäØ×ÑØ×ÑØ×%Ñ%Ø×ÑØ×Ñó
ð 	
r+   c                 óØ   — | j                  «       }|sy|d   | _        |d   | _        |j                  d«      }i }|rd|ddidœ}t	        j
                  | j                  |g«      | _        y)zçFetch the user data, the metadata and the VM password
        from the metadata service.

        Please refer to the datasource documentation for details on how the
        metadata server and password server are crawled.
        Fú	user-dataú	meta-dataÚpasswordTÚexpire)Ú
ssh_pwauthrM   Úchpasswd)rI   Úuserdata_rawÚmetadatar   r   Úmergemanydictr$   )r%   ÚdatarM   Úpassword_configs       r*   Ú	_get_datazDataSourceExoscale._get_data]   sˆ   € ð ×"Ñ"Ó$ˆáØà  Ñ-ˆÔØ˜[Ñ)ˆŒØ—8‘8˜JÓ'ˆàˆÙð #Ø$à˜eðñˆOô !×.Ñ.Ø×Ñ Ð0ó
ˆÔð r+   c                 ó   — | j                   S ©N)r$   )r%   s    r*   Úget_config_objz!DataSourceExoscale.get_config_obj„   s   € Ø× Ñ Ð r+   c                  óR   — t        j                  d«      j                  t        «      S )Nzsystem-product-name)r   Úread_dmi_dataÚ
startswithÚEXOSCALE_DMI_NAME© r+   r*   Ú	ds_detectzDataSourceExoscale.ds_detect‡   s$   € ä× Ñ Ð!6Ó7×BÑBÜó
ð 	
r+   )Ú__name__Ú
__module__Ú__qualname__Údsnamer?   r   r8   rD   rI   rV   rY   Ústaticmethodr_   Ú__classcell__)r)   s   @r*   r   r      sA   ø„ à€Fà€LôòOòò 
ò(%òN!ð ñ
ó ô
r+   r   c                 ó6   — t        j                  | t        «      S rX   )r   Úlist_from_dependsÚdatasources)Údependss    r*   Úget_datasource_listrj   •   s   € Ü×$Ñ$ W¬kÓ:Ð:r+   c                 óÜ   — dj                  | ||«      }t        j                  |dddi||¬«      }|j                  j	                  d«      }|dv ryt        j                  |dddi||¬«       |S )	z�Obtain the VM's password if set.

    Once fetched the password is marked saved. Future calls to this method may
    return empty string or 'saved_password'.z	{}:{}/{}/NÚDomU_RequestÚsend_my_password)Ússl_detailsÚheadersr   r   zutf-8)Ú Úsaved_passwordrq   )r=   r   Úread_file_or_urlÚcontentsÚdecode)r   r   r   r!   r#   Úpassword_urlÚresponserM   s           r*   Úget_passwordrw   ™   s“   € ð ×%Ñ%ØÐ*¨Kó€Lô ×*Ñ*ØØØÐ!3Ð4ØØô€Hð × Ñ ×'Ñ'¨Ó0€Hð Ð)Ñ)Øä×ÑØØØÐ!1Ð2ØØõð €Or+   c                 ó~  — i }||d<   	 t        j                  || ||¬«      |d<   t        j                  || ||¬«      |d<   	 t        || |||¬«      |d<   |S # t        $ r(}t	        j
                  t        d| |«       i cY d}~S d}~ww xY w# t        $ r(}t	        j
                  t        d	| ||«       Y d}~|S d}~ww xY w)
z8Query the metadata server and return the retrieved data.Ú_metadata_api_version)r   r   rK   rL   z(failed reading from metadata url %s (%s)N)r   r   r   r#   r!   rM   z2failed to read from password server url %s:%s (%s))r	   Úget_instance_userdataÚget_instance_metadataÚ	Exceptionr   Úlogexcr   rw   )r   r   r   r!   r#   Úcrawled_metadataÚes          r*   rG   rG   ¿   sï   € ð ÐØ0;ÐÐ,Ñ-ðÜ(+×(AÑ(AØ˜¨{ÀKô)
Ð˜Ñ%ô ),×(AÑ(AØ˜¨{ÀKô)
Ð˜Ñ%ð
Ü'3Ø#Ø%Ø!5Ø#Ø#ô(
Ð˜Ñ$ð  Ðøô/ ò Ü�‰ÜÐ;¸\È1ô	
ð �	ûð	ûô ò 
Ü�‰ÜØ@ØØ Ø÷	
ð 	
ð Ðûð
ús5   ‰8A ÁB Á	BÁ BÁ=BÂBÂ	B<ÂB7Â7B<Ú__main__zQuery Exoscale Metadata)Údescriptionz
--endpointÚURLz The url of the metadata service.)ÚmetavarÚhelpÚdefaultz	--versionÚVERSIONz.The version of the metadata endpoint to query.z	--retriesÚNUMz,The number of retries querying the endpoint.)rƒ   Útyper„   r…   z	--timeoutz.The time in seconds to wait before timing out.z--password-portÚPORTz/The port on which the password endpoint listens)r   r   r   r!   r#   )*ÚloggingÚ	cloudinitr   r   r   r   r   r   Úcloudinit.sources.helpersr	   Ú	getLoggerr`   r   r   r   r   r    r"   r]   Ú
DataSourcer   ÚDEP_FILESYSTEMÚDEP_NETWORKrh   rj   rw   rG   ÚargparseÚArgumentParserÚparserÚadd_argumentr   Ú
parse_argsÚargsÚendpointÚversionÚpassword_portr   r   rT   ÚprintÚ
json_dumpsr^   r+   r*   ú<module>rœ      sØ  ðó ç L× LÝ )à€g×Ñ˜Ó!€à'€Ø€ØÐ à€Ø€àÐ ôt
˜×+Ñ+ô t
ðr ˜'×0Ñ0°'×2EÑ2EÐFÐGð€ò;ð
 ØØ-ØØó#ðN ØØ-ØØó(ðV ˆzÒÛà$ˆX×$Ñ$Ð1JÔK€FØ
×ÑØØØ/Øð	 ô ð ×ÑØØØ=Øð	 ô ð ×ÑØØØØ;Øð ô ð ×ÑØØØØ=Øð ô ð ×ÑØØØØ>Ø$ð ô ð ×ÑÓ€DáØ—]‘]Ø—L‘LØ!×/Ñ/Ø—L‘LØ—L‘Lô€Dñ 
Ð
"ˆ-×
"Ñ
" 4Ó
(Õ)ða r+   