name : DataSourceExoscale.cpython-39.opt-1.pyc
a

'�Dg8"�@s^ddlZddlmZmZmZmZmZmZddlm	Z	e�
e�ZdZ
dZdZdZdZd	ZGd
d�dej�ZeejejffgZdd
�Ze
eeeefdd�Ze
eeeefdd�Zedk�rZddlZejdd�Zejddde
d�ejddded�ejddeded�ejd ded!ed�ejd"d#ed$ed�e� �Z!ee!j"e!j#e!j$e!j%e!j&d%�Z'e(e�)e'��dS)&�N)�
atomic_helper�dmi�helpers�sources�
url_helper�util)�ec2zhttp://169.254.169.254z1.0i��
��ExoscalecsXeZdZdZdZ�fdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
edd��Z�Z
S)�DataSourceExoscaler�xcs|tt|��|||�t�d�|j�dt�|_|j�dt	�|_
t|j�dt��|_
|j�dt�|_|j�dt�|_i|_dS)Nz$Initializing the Exoscale datasource�metadata_url�api_version�password_server_port�timeout�retries)�superr�__init__�LOG�debugZds_cfg�get�METADATA_URLr�API_VERSIONr�int�PASSWORD_SERVER_PORTr�URL_TIMEOUT�url_timeout�URL_RETRIES�url_retries�extra_config)�selfZsys_cfgZdistro�paths��	__class__��H/usr/lib/python3.9/site-packages/cloudinit/sources/DataSourceExoscale.pyrs
�zDataSourceExoscale.__init__cCs8d}|j�d�}t�|�}|�d|d�r4t�d�dS)z<Adjust set_passwords module to run 'always' during each bootZ
set_passwordsZsemZconfig_Nz5Overriding module set_passwords with frequency always)r"Z
get_ipath_currZFileSemaphores�clearrr)r!ZcfgZis_new_instance�modZsem_pathZ
sem_helperr%r%r&�activate*s
	
zDataSourceExoscale.activatecCs6d�|j|j�}tj|g|j|jtjd�\}}t	|�S)z.Wait for the metadata service to be reachable.z{}/{}/meta-data/instance-id)ZurlsZmax_waitrZ	status_cb)
�formatrrrZwait_for_url�url_max_waitrrZcritical�bool)r!r�urlZ	_responser%r%r&�wait_for_metadata_service9s��
z,DataSourceExoscale.wait_for_metadata_servicecCs*|��}|siSt|j|j|j|j|j�S)zw
        Crawl the metadata service when available.

        @returns: Dictionary of crawled metadata content.
        )r.�
read_metadatarrrrr)r!Zmetadata_readyr%r%r&�crawl_metadataIs�z!DataSourceExoscale.crawl_metadatacCs\|��}|sdS|d|_|d|_|�d�}i}|rFd|ddid�}t�|j|g�|_dS)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�passwordTZexpire)Z
ssh_pwauthr3Zchpasswd)r0Zuserdata_raw�metadatarrZ
mergemanydictr )r!�datar3Zpassword_configr%r%r&�	_get_data\s"


��	�zDataSourceExoscale._get_datacCs|jS�N)r )r!r%r%r&�get_config_obj�sz!DataSourceExoscale.get_config_objcCst�d��t�S)Nzsystem-product-name)rZ
read_dmi_data�
startswith�EXOSCALE_DMI_NAMEr%r%r%r&�	ds_detect�s
�zDataSourceExoscale.ds_detect)�__name__�
__module__�__qualname__Zdsnamer+rr)r.r0r6r8�staticmethodr;�
__classcell__r%r%r#r&rs
'rcCst�|t�Sr7)rZlist_from_depends�datasources)Zdependsr%r%r&�get_datasource_list�srBcCsZd�|||�}tj|dddi||d�}|j�d�}|dvr>dStj|dddi||d�|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	{}:{}/{}/NZDomU_RequestZsend_my_password)Zssl_detailsZheadersrrzutf-8)��saved_passwordrD)r*rZread_file_or_url�contents�decode)rrrrrZpassword_urlZresponser3r%r%r&�get_password�s*���rGc
Cs�i}||d<z0tj||||d�|d<tj||||d�|d<Wn8tyt}z t�td||�iWYd}~Sd}~00zt|||||d�|d<Wn6ty�}zt�td	|||�WYd}~n
d}~00|S)
z8Query the metadata server and return the retrieved data.Z_metadata_api_version)rrr1r2z(failed reading from metadata url %s (%s)N)rrrrrr3z2failed to read from password server url %s:%s (%s))rZget_instance_userdataZget_instance_metadata�	ExceptionrZlogexcrrG)rrrrrZcrawled_metadata�er%r%r&r/�s>�
����r/�__main__zQuery Exoscale Metadata)�descriptionz
--endpointZURLz The url of the metadata service.)�metavar�help�defaultz	--versionZVERSIONz.The version of the metadata endpoint to query.z	--retriesZNUMz,The number of retries querying the endpoint.)rL�typerMrNz	--timeoutz.The time in seconds to wait before timing out.z--password-portZPORTz/The port on which the password endpoint listens)rrrrr)*ZloggingZ	cloudinitrrrrrrZcloudinit.sources.helpersrZ	getLoggerr<rrrrrrr:Z
DataSourcerZDEP_FILESYSTEMZDEP_NETWORKrArBrGr/�argparse�ArgumentParser�parser�add_argumentr�
parse_args�argsZendpoint�versionZ
password_portrrr5�printZ
json_dumpsr%r%r%r&�<module>s� 
x��
'�
+
������

© 2025 Cubjrnet7