HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceExoscale.cpython-310.pyc
o

�Ad�#�@shddlmZmZddlmZddlmZmZmZddlm	Z	e�
e�ZdZ
dZdZdZd	Zd
ZGdd�dej�ZeejejffgZd
d�Ze
eeeefdd�Ze
eeeefdd�Zedkr�ddlZejdd�Zejddde
d�ejddded�ejdded ed!�ejd"ded#ed!�ejd$d%ed&ed!�e� �Z!ee!j"e!j#e!j$e!j%e!j&d'�Z'e(e�)e'��dSdS)(�)�dmi�helpers)�log)�sources�
url_helper�util)�ec2zhttp://169.254.169.254z1.0i��
��ExoscalecsTeZdZdZdZ�fdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�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�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__��F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceExoscale.pyrs
�
zDataSourceExoscale.__init__cCs<d}|j�d�}t�|�}|�d|d�rt�d�dSdS)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�clearrr)r"�cfg�is_new_instance�mod�sem_path�
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)�urls�max_waitr�	status_cb)
�formatrrr�wait_for_url�url_max_waitrr�critical�bool)r"r�url�	_responser(r(r)�wait_for_metadata_service9s�
�z,DataSourceExoscale.wait_for_metadata_servicecCs6tjtjd|jd�}|siSt|j|j|j|j	|j
�S)zw
        Crawl the metadata service when available.

        @returns: Dictionary of crawled metadata content.
        z waiting for the metadata service��logfunc�msg�func)r�log_timer�infor@�
read_metadatarrrrr )r"�metadata_readyr(r(r)�crawl_metadataIs��z!DataSourceExoscale.crawl_metadatacCst|��sdStjtjd|jd�}|sdS|d|_|d|_|�d�}i}|r/d|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.
        FzCrawl of metadata servicerA�	user-data�	meta-data�passwordT�expire)�
ssh_pwauthrL�chpasswd)�_is_platform_viablerrErrrI�userdata_raw�metadatar�
mergemanydictr!)r"�datarL�password_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)r�
read_dmi_data�
startswith�EXOSCALE_DMI_NAMErXr(r(r)rP�s
�z&DataSourceExoscale._is_platform_viable)
�__name__�
__module__�__qualname__�dsnamer;rr5r@rIrVrYrP�
__classcell__r(r(r&r)rs
.rcCst�|t�SrW)r�list_from_depends�datasources)�dependsr(r(r)�get_datasource_list�srecCsZd�|||�}tj|dddi||d�}|j�d�}|dvrdStj|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	{}:{}/{}/N�DomU_Request�send_my_password)�ssl_details�headersrrzutf-8)��saved_passwordrk)r9r�read_file_or_url�contents�decode)rrrrr �password_url�responserLr(r(r)�get_password�s*���rqc
Cs�i}||d<ztj||||d�|d<tj||||d�|d<Wnty:}zt�td||�iWYd}~Sd}~wwzt|||||d�|d<W|Stye}zt�td	|||�WYd}~|Sd}~ww)
z8Query the metadata server and return the retrieved data.�_metadata_api_version)rrrJrKz(failed reading from metadata url %s (%s)N)rrrr rrLz2failed to read from password server url %s:%s (%s))r�get_instance_userdata�get_instance_metadata�	Exceptionr�logexcrrq)rrrrr �crawled_metadata�er(r(r)rG�sH
����������rG�__main__NzQuery 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)rrrrr )*�	cloudinitrrr�loggingrrr�cloudinit.sources.helpersr�	getLoggerr]rrrrrrr\�
DataSourcer�DEP_FILESYSTEM�DEP_NETWORKrcrerqrG�argparse�ArgumentParser�parser�add_argumentr�
parse_args�args�endpoint�version�
password_portrrrT�print�
json_dumpsr(r(r(r)�<module>s�
�
�'
�+�������