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

'�Dg��@s�ddlZddlmZddlmZmZddlmZddlm	Z	ddl
mZe�
e�ZddiZd	Zd
Zd
ZGdd�dej�ZGd
d�de�ZeejffeejejffgZdd�ZdS)�N)�net)�sources�util)�NoDHCPLeaseError)�EphemeralDHCPv4)�upcloud�metadata_urlz'http://169.254.169.254/metadata/v1.json��c@sHeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	e
d
d��ZdS)�DataSourceUpCloud�UpCloudFcCs�tj�||||�||_t�|_t�t�|ddgi�t	g�|_
|j
d|_|j
�dt
�|_|j
�dt�|_|j
�dt�|_d|_d|_dS)NZ
datasourcerr�retries�timeout�
wait_retry)r�
DataSource�__init__�distro�dict�metadatarZ
mergemanydictZget_cfg_by_path�BUILTIN_DS_CONFIGZds_cfg�metadata_address�get�
MD_RETRIESr
�
MD_TIMEOUTr�
MD_WAIT_RETRYr�_network_config�
metadata_full)�self�sys_cfgr�paths�r �G/usr/lib/python3.9/site-packages/cloudinit/sources/DataSourceUpCloud.pyr"s��zDataSourceUpCloud.__init__cCst��S�N)�	uc_helperZread_sysinfo�rr r r!�_get_sysinfo3szDataSourceUpCloud._get_sysinfocCstj|j|j|j|jd�S)N)rZsec_betweenr
)r#Z
read_metadatarrrr
r$r r r!�_read_metadata6s�z DataSourceUpCloud._read_metadatac
Cs�|��\}}|sdSt�d|�|jr�zVt�d�t��}t�d|�t|j|��|�	�}Wd�n1sp0YWn<t
tjfy�}zt
�tt|��WYd}~dSd}~00n^zt�d�|�	�}WnFtj�y}z*t
�tt|��t�d|�WYd}~dSd}~00||_|�d|�|jd<|�d	�|jd
<|�d�|jd<|�d�|jd
<|�dd�|jd<|�dd�|_|�dd�|_dS)NFz"Running on UpCloud. server_uuid=%szFinding a fallback NICz*Discovering metadata via DHCP interface %sz7Discovering metadata without DHCP-configured networkingzENo DHCP-enabled interfaces available, unable to fetch metadata for %sZinstance_idzinstance-id�hostnamezlocal-hostname�networkZpublic_keyszpublic-keysZregion�defaultZavailability_zoneZvendor_dataZ	user_dataT)r%�LOG�info�perform_dhcp_setup�debug�cloudnetZfind_fallback_nicrrr&rrZInvalidMetaDataExceptionrZlogexc�strrrrZvendordata_rawZuserdata_raw)rZ
is_upcloudZserver_uuidZnicZmd�er r r!�	_get_data>sF
*��zDataSourceUpCloud._get_datacCst�|���Sr")rZinstance_id_matches_system_uuidZget_instance_id)rrr r r!�check_instance_idksz#DataSourceUpCloud.check_instance_idcCs6|jr|jS|j�d�}|s$td��t�|�|_|jS)z�
        Configure the networking. This needs to be done each boot,
        since the IP and interface information might have changed
        due to reconfiguration.
        r(z/Unable to get network meta-data from server....)rrr�RuntimeErrorr#Zconvert_network_config)rZraw_network_configr r r!�network_configns��z DataSourceUpCloud.network_configN)�__name__�
__module__�__qualname__Zdsnamer,rr%r&r1r2�propertyr4r r r r!rs-rc@seZdZdZdZdS)�DataSourceUpCloudLocalaz
    Run in init-local using a DHCP discovery prior to metadata crawl.

    In init-local, no network is available. This subclass sets up minimal
    networking with dhclient on a viable nic so that it can talk to the
    metadata service. If the metadata service provides network configuration
    then render the network configuration for that instance based on metadata.
    TN)r5r6r7�__doc__r,r r r r!r9�s	r9cCst�|t�Sr")rZlist_from_depends�datasources)Zdependsr r r!�get_datasource_list�sr<)ZloggingZ	cloudinitrr.rrZcloudinit.net.dhcprZcloudinit.net.ephemeralrZcloudinit.sources.helpersrr#Z	getLoggerr5r*rrrrrrr9ZDEP_FILESYSTEMZDEP_NETWORKr;r<r r r r!�<module>s 
k
�

© 2025 Cubjrnet7