a 'Dg8"@s^ddlZddlmZmZmZmZmZmZddlm Z e e Z dZ dZdZdZdZd ZGd d d ejZeejejffgZd d Ze eeeefddZe eeeefddZe dkrZddlZejddZejddde dejdddedejddededejd ded!edejd"d#ed$ede Z!ee!j"e!j#e!j$e!j%e!j&d%Z'e(e)e'dS)&N) atomic_helperdmihelperssources url_helperutil)ec2zhttp://169.254.169.254z1.0i ExoscalecsXeZdZdZdZfddZddZddZd d Zd d Z d dZ e ddZ Z S)DataSourceExoscaler xcs|tt||||td|jdt|_|jdt |_ t |jdt |_ |jdt|_|jdt|_i|_dS)Nz$Initializing the Exoscale datasource metadata_url api_versionpassword_server_porttimeoutretries)superr __init__LOGdebugZds_cfgget METADATA_URLr API_VERSIONrintPASSWORD_SERVER_PORTr URL_TIMEOUT url_timeout URL_RETRIES url_retries extra_config)selfZsys_cfgZdistropaths __class__H/usr/lib/python3.9/site-packages/cloudinit/sources/DataSourceExoscale.pyrs  zDataSourceExoscale.__init__cCs8d}|jd}t|}|d|dr4tddS)zdStj|dddi||d|S) zObtain 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)Z ssl_detailsZheadersrrzutf-8)saved_passwordrD)r*rZread_file_or_urlcontentsdecode)rrrrrZ password_urlZresponser3r%r%r& get_passwords*  rGc Csi}||d<z0tj||||d|d<tj||||d|d<Wn8tyt}z ttd||iWYd}~Sd}~00zt|||||d|d<Wn6ty}zttd |||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_metadataer%r%r&r/s> r/__main__zQuery Exoscale Metadata) descriptionz --endpointZURLz The url of the metadata service.)metavarhelpdefaultz --versionZVERSIONz.The version of the metadata endpoint to query.z --retriesZNUMz,The number of retries querying the endpoint.)rLtyperMrNz --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_FILESYSTEMZ DEP_NETWORKrArBrGr/argparseArgumentParserparser add_argumentr parse_argsargsZendpointversionZ password_portrrr5printZ json_dumpsr%r%r%r&s   x ' +