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__/__init__.cpython-310.pyc
o

�Ad+��@s�ddlZddlZddlZddlZddlZddlmZddlmZm	Z	ddl
mZmZm
Z
mZmZddlmZmZddlmZddlmZmZddlmZdd	lmZdd
lmZddlmZddlmZm Z dd
l!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(dZ)dZ*dZ+dZ,e)e*e+gZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5e�6e7�Z8ddd�fd d!d�fd"d#d�fd$�Z9e	Gd%d&�d&e��Z:Gd'd(�d(e;�Z<Gd)d*�d*e;�Z=Gd+d,�d,e;�Z>dTd/d0�Z?e2fd1d2�Z@ed3gd4��ZAed5d6d7g�ZBGd8d�de&ejCd9�ZDd:d;�ZEd<eeDeFffd=d>�ZGd?d@�ZH	AdUdBeFd<eIfdCdD�ZJdEdF�ZKdVdHdI�ZLGdJdK�dKeM�ZNdLdM�ZOdNeDdOeFd<eIfdPdQ�ZPdOeFd<eeDfdRdS�ZQdS)W�N)�
namedtuple)�Enum�unique)�Any�Dict�List�Optional�Tuple)�dmi�importer)�log)�net�
type_utils)�	user_data)�util)�
write_json)�Distro)�
EventScope�	EventType)�launch_index)�Paths)�CloudInitPickleMixin)�events�disabled�localr
�pass�
FILESYSTEM�NETWORK�
DataSourcez|EXPERIMENTAL: The structure and format of content scoped under the 'ds' key may change in subsequent releases of cloud-init.zredacted for non-root user�
cloud-name�_unset�unknownz	aws-chinacC�|dkS�N�aws���cr%r%�</usr/lib/python3/dist-packages/cloudinit/sources/__init__.py�<lambda>?�r)zaws-govcCr"r#r%r&r%r%r(r)@r*zazure-chinacCr")N�azurer%r&r%r%r(r)Ar*)zcn-zus-gov-�chinac@s2eZdZdZdZdZdZdZdZde	fdd	�Z
d
S)�NetworkConfigSourcezb
    Represents the canonical list of network config sources that cloud-init
    knows about.
    �cmdline�ds�
system_cfg�fallback�	initramfs�returncC�|jS�N��value��selfr%r%r(�__str__R�zNetworkConfigSource.__str__N)�__name__�
__module__�__qualname__�__doc__�CMD_LINE�DS�
SYSTEM_CFG�FALLBACK�	INITRAMFS�strr:r%r%r%r(r-Esr-c@�eZdZdZdS)�DatasourceUnpickleUserDataErrorzERaised when userdata is unable to be unpickled due to python upgradesN�r<r=r>r?r%r%r%r(rGV�rGc@�eZdZdS)�DataSourceNotFoundExceptionN�r<r=r>r%r%r%r(rKZ�rKc@rF)�InvalidMetaDataExceptionz8Raised when metadata is broken, unavailable or disabled.NrHr%r%r%r(rN^rIrN�r%c
Cs�t�|�}g}g}|��D]V\}}|r|d|}n|}|��|vs(|��|vr-|�|�t|t�rD|�d�rD|�|�|�dd�||<t|t	�rct
|||�}	|�|	�d��|�|	�d��|	||<q
t
|�|d<t
|�|d<|S)z�Process all instance metadata cleaning it up for persisting as json.

    Strip ci-b64 prefix and catalog any 'base64_encoded_keys' as a list

    @return Dict copy of processed metadata.
    �/zci-b64:rO�base64_encoded_keys�sensitive_keys)�copy�deepcopy�items�lower�append�
isinstancerE�
startswith�replace�dict�process_instance_metadata�extend�pop�sorted)
�metadata�key_pathrR�md_copyrQ�	sens_keys�key�val�sub_key_path�
return_valr%r%r(r\bs4

�
�


��r\cCs�|�dg�s|St�|�}|�d�D]+}|�d�}|}|D]}||vr4t||t�r4||dkr4||}q||vr=|||<q|S)z�Redact any sensitive keys from to provided metadata dictionary.

    Replace any keys values listed in 'sensitive_keys' with redact_value.
    rRrP���)�getrSrT�splitrXr[)r`�redact_valuerbra�
path_parts�obj�pathr%r%r(�redact_sensitive_keys�s&

��
���ro�	URLParams)�max_wait_seconds�timeout_seconds�num_retries�sec_between_retries�DataSourceHostname�hostname�
is_defaultc	@s�eZdZUeZdZdZdZdZdZ	dZ
ejej
ejejfZeedfed<dZdZdZd	ZejejejejejhiZejejhiZd
e fde fdifd
dddddf	Z!eee"e#fdfed<dZ$dZ%ee"dfed<dZ&d	Z'dzde(de)fdd�Z*de+ddfdd�Z,dd �Z-de.fd!d"�Z/d#d$�Z0d%d&�Z1d'd(�Z2d{d*d+�Z3de.fd,d-�Z4d|d/d0�Z5de.fd1d2�Z6d3d4�Z7d}d5d6�Z8d7d8�Z9d9d:�Z:e;d;d<��Z<e;d=d>��Z=e;d?d@��Z>dAdB�Z?e;dCdD��Z@dEdF�ZAe;dGdH��ZBdIdJ�ZCe;dKdL��ZDdMdN�ZEdOdP�ZFdQdR�ZGdSdT�ZHdUdV�ZIdWdX�ZJdYdZ�ZKd[d\�ZLd]d^�ZMe;d_d`��ZNe;dadb��ZOdcdd�ZPd~dedf�ZQdgdh�ZRdieSefdjdk�ZTdieSede.fdldm�ZUdndo�ZVeWddpdq��ZXe;drds��ZYe;dtdu��ZZdvdw�Z[dxdy�Z\dS)�rzen_US.UTF-8�_undefN.�network_config_sourcesrh�
���ec2_metadata�network_jsonr`)�userdataN)�userdata_rawN)�
vendordataN)�vendordata_rawN)�vendordata2N)�vendordata2_rawN�cached_attr_defaultsF)�
merged_cfgzsecurity-credentialsr�	user-datarr��vendor-datazds/vendor_data�sensitive_metadata_keys�distro�pathscCs�||_||_||_d|_i|_d|_d|_d|_d|_d|_	t
�|jd|jfi�|_
|j
s0i|_
|s;t�|j�|_dS||_dS)N�
datasource)�sys_cfgr�r�rr`r�r�r�r�r�r�get_cfg_by_path�dsname�ds_cfg�ud�UserDataProcessor�ud_proc)r9r�r�r�r�r%r%r(�__init__s$�
zDataSource.__init__�ci_pkl_versionr3c
Cs�t|d�sd|_t|d�sd|_t|d�sd|_t|d�rA|jdurCzt|j�WdSty@}z
t�d|�t	�|�d}~wwdSdS)z(Perform deserialization fixes for Paths.r�Nr��skip_hotplug_detectFrz:Unable to unpickle datasource: %s. Ignoring current cache.)
�hasattrr�r�r�rrE�AttributeError�LOG�debugrG)r9r��er%r%r(�	_unpickle1s$


����zDataSource._unpicklecCs
t�|�Sr5�r�obj_namer8r%r%r(r:Is
zDataSource.__str__cC�dS)z#Check if running on this datasourceTr%r8r%r%r(�	ds_detectL�zDataSource.ds_detectcCs |j�dg�|jg|jdgfvS)z�Override if either:
        - only a single datasource defined (nothing to fall back to)
        - TODO: commandline argument is used (ci.ds=OpenStack)
        �datasource_list�None)r�rir�r8r%r%r(�override_ds_detectPs�zDataSource.override_ds_detectcCsH|��rt�d|�|��S|��rt�d|�|��St�d|�dS)z&Overrides runtime datasource detectionz5Machine is configured to run on single datasource %s.zMachine is running on %s.z#Datasource type %s is not detected.F)r�r�r�r��	_get_datar8r%r%r(�_check_and_get_dataZs���zDataSource._check_and_get_datacCs�|��j}|��}|j}|d}diddg�d|�d|�dt|j|j|j��d|j�d	|j�d
|dd�d
|dd�d|dd�d|j�d|���d|d�d|�d|�d|dd�d|�d|�|dd|j|j	|d|dd��iS)z2Return a dictionary of standardized metadata keys.�sys_info�v1�
_beta_keys�subplatform�availability-zone�availability_zone�cloud_idr�
cloud_namer��distr�distro_versionr|�distro_release��platform�public_ssh_keys�python_version�python�instance-id�instance_id�kernel_release�uname�local-hostname�local_hostname��variant)�machine�regionr��system_platformr�)
�get_hostnamerv�get_instance_idr��canonical_cloud_idr�r��
platform_type�get_public_ssh_keysr�)r9�
instance_datar�r�r��sysinfor%r%r(�_get_standardized_metadatags`
�������	�
���
�������
��z%DataSource._get_standardized_metadatar%cCsP|jsdS|r
|}n|j}|D]\}}t||�rt|||�q|s&d|_dSdS)z�Reset any cached metadata attributes to datasource defaults.

        @param attr_defaults: Optional tuple of (attr, value) pairs to
           set instead of cached_attr_defaults.
        NF)�_dirty_cacher�r��setattr)r9�
attr_defaults�attr_values�	attributer7r%r%r(�clear_cached_attrs�s
�
�zDataSource.clear_cached_attrscCs"d|_|��}|s|S|��|S)z�Datasources implement _get_data to setup metadata and userdata_raw.

        Minimally, the datasource should return a boolean True on success.
        T)r�r��persist_instance_data)r9�return_valuer%r%r(�get_data�szDataSource.get_dataTc
Cs^|rtj�|jj�rt||j�d��t|d�r1t�	t
|d��}|�dd�|�dd�d|i}n/dd|jii}t|d�rLt
|d�}|t
krL||dd<t|d	�r`t
|d	�}|t
kr`||dd	<t|dd
<t�	|j�|d<d|dd
<t��|d
<|�|�|��zt�|�}tt�|�|jd�}Wn5ty�}zt�dt|��WYd}~dSd}~wty�}zt�dt|��WYd}~dSd}~ww|j�d�}	|d�dd�}
tj� |jj!d�}t�"|�d|
��|
�d��d}|�d|
��}
tj�#|��rtj�$|�}tj%|
|dd�|�r||
k�rt�&|�t'|	|dd�|j�d�}t'|t(|��dS)aPProcess and write INSTANCE_JSON_FILE with all instance metadata.

        Replace any hyphens with underscores in key names for use in template
        processing.

        :param write_cache: boolean set True to persist obj.pkl when
            instance_link exists.

        @return True on successful write, False otherwise.
        �obj_pkl�_crawled_metadatar�Nr�r/�	meta_datar~r}�_docr�zUMerged cloud-init system config from /etc/cloud/cloud.cfg and /etc/cloud/cloud.cfg.d/r�)rRz'Error persisting instance-data.json: %sF�instance_data_sensitiver�r��nonezcloud-id�-�
T)�forcei�)�moder�))�osrn�lexistsr��
instance_link�	pkl_store�
get_ipath_curr�rSrT�getattrr^r`�UNSET�EXPERIMENTAL_TEXTr�r�system_info�updater��
json_dumpsr\�json�loadsr��	TypeErrorr��warningrE�UnicodeDecodeError�get_runpathri�join�run_dir�
write_file�exists�realpath�sym_link�del_filerro)r9�write_cache�crawled_metadatar�r~r}�content�processed_datar��json_sensitive_filer��
cloud_id_file�prev_cloud_id_file�new_cloud_id_file�	json_filer%r%r(r��sl
�





�

����
z DataSource.persist_instance_datacCstd��)z@Walk metadata sources, process crawled data and save attributes.zlSubclasses of DataSource must implement _get_data which sets self.metadata, vendordata_raw and userdata_raw.)�NotImplementedErrorr8r%r%r(r��s�zDataSource._get_datac
CsB|j}zt|j�d|j��}Wnty$t�td|j�d�|�Ynw|j}zt	dt|j�d|j���}WntyO|j}t�td|j�d�|�Ynw|j
}zt|j�d|j
��}Wntytt�td|j�d�|�Ynw|j}zt|j�d|j��}Wnty�t�td	|j�d�|�Ynwt
||||�S)
z�Return the Datasource's preferred url_read parameters.

        Subclasses may override url_max_wait, url_timeout, url_retries.

        @return: A URLParams object with max_wait_seconds, timeout_seconds,
            num_retries.
        �max_waitz6Config max_wait '%s' is not an int, using default '%s'r�timeoutz5Config timeout '%s' is not an int, using default '%s'�retriesz5Config retries '%s' is not an int, using default '%s'rtzAConfig sec_between_retries '%s' is not an int, using default '%s')�url_max_wait�intr�ri�
ValueErrorr�logexcr��url_timeout�max�url_retries�	Exception�url_sec_between_retriesrp)r9r�rrrtr%r%r(�get_url_params�sd
��
��	
����
��	zDataSource.get_url_paramscCs2|jdur|j�|���|_|r|�|j�S|jSr5)rr��process�get_userdata_raw�
_filter_xdata)r9�apply_filterr%r%r(�get_userdata:s

zDataSource.get_userdatacC�"|jdur|j�|���|_|jSr5)r�r�r�get_vendordata_rawr8r%r%r(�get_vendordataA�
zDataSource.get_vendordatacCrr5)r�r�r�get_vendordata2_rawr8r%r%r(�get_vendordata2FrzDataSource.get_vendordata2cCs2|jdurt��|_|jdurt�d|j�|jS)zADetermine the network interface used during local network config.Nz(Did not find a fallback interface on %s.)�_fallback_interfacer
�find_fallback_nicr�r�r�r8r%r%r(�fallback_interfaceKs


�zDataSource.fallback_interfacecCs.t|d�s|j��|_|js|j��|_|jS)N�_platform_type)r�r�rVrr8r%r%r(r�Vs

zDataSource.platform_typecCs*t|d�s
|��|_|js|��|_|jS)a�Return a string representing subplatform details for the datasource.

        This should be guidance for where the metadata is sourced.
        Examples of this on different clouds:
            ec2:       metadata (http://169.254.169.254)
            openstack: configdrive (/dev/path)
            openstack: metadata (http://169.254.169.254)
            nocloud:   seed-dir (/seed/dir/path)
            lxd:   nocloud (/seed/dir/path)
        �_subplatform)r��_get_subplatformrr8r%r%r(r�_s



zDataSource.subplatformcCst|d�rdt|d�StS)z?Subclasses should implement to return a "slug (detail)" string.�metadata_addressz
metadata (%s))r�r��METADATA_UNKNOWNr8r%r%r(rrs
zDataSource._get_subplatformcCs~|jr|jS|jr5|j�t�r5|j�t�}t|t�r"|��|_|jS|����|_t�	dtt
|��|jS|����|_|jS)z�Return lowercase cloud name as determined by the datasource.

        Datasource can determine or define its own cloud product name in
        metadata.
        z5Ignoring metadata provided key %s: non-string type %s)�_cloud_namer`ri�METADATA_CLOUD_NAME_KEYrXrErV�_get_cloud_namer�r��type)r9r�r%r%r(r�xs 


���zDataSource.cloud_namecCr4)z�Return the datasource name as it frequently matches cloud name.

        Should be overridden in subclasses which can run on multiple
        cloud names, such as DatasourceEc2.
        )r�r8r%r%r(r!�szDataSource._get_cloud_namecCs"|jsdSd|jvr|jdSdS)Nzlaunch-index)r`r8r%r%r(r�s


zDataSource.launch_indexcCs0t�t�|j��g}|}|D]}|�|�}q|Sr5)r�Filterr�safe_int�apply)r9�processed_ud�filters�new_ud�fr%r%r(r�s�zDataSource._filter_xdatacCr��NFr%r8r%r%r(�is_disconnected�r�zDataSource.is_disconnectedcCr4r5)r�r8r%r%r(r
�r;zDataSource.get_userdata_rawcCr4r5)r�r8r%r%r(r�r;zDataSource.get_vendordata_rawcCr4r5)r�r8r%r%r(r�r;zDataSource.get_vendordata2_rawcCsiSr5r%r8r%r%r(�get_config_obj�szDataSource.get_config_objcCst|j�d��S)Nzpublic-keys)�normalize_pubkey_datar`rir8r%r%r(r��szDataSource.get_public_ssh_keyscCr�)a5Publish the public SSH host keys (found in /etc/ssh/*.pub).

        @param hostkeys: List of host key tuples (key_type, key_value),
            where key_type is the first field in the public key file
            (e.g. 'ssh-rsa') and key_value is the key itself
            (e.g. 'AAAAB3NzaC1y...').
        Nr%)r9�hostkeysr%r%r(�publish_host_keys�szDataSource.publish_host_keyscCsdddi}|��D]'\}}|�|�sq|D]}d||t|�d�f}tj�|�r.|SqqdS)N�sd)�vd�xvd�vtbz	/dev/%s%s)rUrY�lenr�rnr�)r9�
short_name�mappings�nfrom�tlist�nto�candr%r%r(�
_remap_device�s
��zDataSource._remap_devicecC�dSr5r%)r9�_namer%r%r(�device_name_to_device�sz DataSource.device_name_to_devicecCs,|j}z|j��}W|StyY|Sw)z<Default locale is en_US.UTF-8, but allow distros to override)�default_localer��
get_localer�)r9�localer%r%r(r@�s��zDataSource.get_localecCs2|j�d|j�d��}|r|S|j�di��d�S)Nr�r��	placement�r`ri)r9�top_level_azr%r%r(r��s�zDataSource.availability_zonecCs|j�d�S)Nr�rCr8r%r%r(r��szDataSource.regioncCs"|jrd|jvr
dSt|jd�S)Nr�ziid-datasource)r`rEr8r%r%r(r��szDataSource.get_instance_idcCsXd}d}|}d}|jr|j�d�sW|rtd|�Sg}t��}	|	dkr$d}t�|	�}
|
r:|
�d�dkr:t|
��d�}nI|	rK|	�d�dkrKt|	��d�}n8|	rR|	|g}n1||g}n,|jd}t	�
|�r~g}|rjt�|�}|rtt|��d�}nd	|�dd
�g}n|�d�}t
|�dkr�|d}	d�|dd��}n|d}	|r�||kr�d|	|f}	t|	|�S)
a�Get hostname or fqdn from the datasource. Look it up if desired.

        @param fqdn: Boolean, set True to return hostname with domain.
        @param resolve_ip: Boolean, set True to attempt to resolve an ipv4
            address provided in local-hostname meta-data.
        @param metadata_only: Boolean, set True to avoid looking up hostname
            if meta-data doesn't have local-hostname present.

        @return: a DataSourceHostname namedtuple
            <hostname or qualified hostname>, <is_default> (str, bool).
            is_default is a bool and
            it's true only if hostname is localhost and was
            returned by util.get_hostname() as a default.
            This is used to differentiate with a user-defined
            localhost hostname.
            Optionally return (None, False) when
            metadata_only is True and local-hostname data is not available.
        �localdomain�	localhostFr�NT�.rzip-%sr�r|z%s.%s)r`rirurr��get_fqdn_from_hosts�findrErjr
�is_ipv4_address�
gethostbyaddrrZr4r�)r9�fqdn�
resolve_ip�
metadata_only�	defdomain�defhost�domainrw�toksrv�
hosts_fqdn�lhostr%r%r(r��sF








zDataSource.get_hostnamecCs|jj|d�S)N)�data_source)r��get_package_mirror_infor8r%r%r(rVDsz"DataSource.get_package_mirror_info�source_event_typescCsPi}|D]!}|j��D]\}}||vr$|�|�st�||<||�|�qq|Sr5)�supported_update_eventsrUri�set�add)r9rW�supported_events�event�update_scope�
update_eventsr%r%r(�get_supported_eventsGs�

��zDataSource.get_supported_eventsc	Cs�|�|�}|��D]\}}t�d|jd�dd�|D���|�d|tff�q	|r6|��|��}|r6dSt�d|d�dd�|D���d	S)
a�Refresh cached metadata if the datasource supports this event.

        The datasource has a list of supported_update_events which
        trigger refreshing all cached metadata as well as refreshing the
        network configuration.

        @param source_event_types: List of EventTypes which may trigger a
            metadata update.

        @return True if the datasource did successfully update cached metadata
            due to source_event_type.
        z:Update datasource metadata and %s config due to events: %s�, cS�g|]}|j�qSr%r6��.0r\r%r%r(�
<listcomp>h�z;DataSource.update_metadata_if_supported.<locals>.<listcomp>z
_%s_configTz(Datasource %s not updated for events: %scSrar%r6rbr%r%r(rdvreF)	r_rUr�r�r7r�r�r�r�)r9rWr[�scope�matched_events�resultr%r%r(�update_metadata_if_supportedTs&
��z'DataSource.update_metadata_if_supportedcCr�r*r%)r9r�r%r%r(�check_instance_idzr�zDataSource.check_instance_idcCsT|durt}|durt}|D]}|durq||vr|St�d||�|S|S)Nz%invalid dsmode '%s', using default=%s)�DSMODE_NETWORK�
VALID_DSMODESr�r�)�
candidates�default�valid�	candidater%r%r(�_determine_dsmode~s�zDataSource._determine_dsmodecCr<r5r%r8r%r%r(�network_config�r�zDataSource.network_configcCr<r5r%r8r%r%r(�first_instance_boot�r�zDataSource.first_instance_bootcCr�)a(setup(is_new_instance)

        This is called before user-data and vendor-data have been processed.

        Unless the datasource has set mode to 'local', then networking
        per 'fallback' or per 'network_config' will have been written and
        brought up the OS at this point.
        Nr%)r9�is_new_instancer%r%r(�setup�s	zDataSource.setupcCr�)a�activate(cfg, is_new_instance)

        This is called before the init_modules will be called but after
        the user-data and vendor-data have been fully processed.

        The cfg is fully up to date config, it contains a merged view of
           system config, datasource config, user config, vendor config.
        It should be used rather than the sys_cfg passed to __init__.

        is_new_instance is a boolean indicating if this is a new instance.
        Nr%)r9�cfgrtr%r%r(�activate�szDataSource.activater5)r%�T)F)FFF)NN)]r<r=r>rk�dsmoder?r�rrrrr-r@rDrBrAryr	�__annotations__rrrr
rrr�BOOT_NEW_INSTANCE�BOOT�BOOT_LEGACY�HOTPLUGrX�default_update_eventsr�r�rErr�r�r��_ci_pkl_versionrrr�rr�r:�boolr�r�r�r�r�r�r�r�rrrr�propertyrr�r�rr�r!rrr+r
rrr,r�r/r;r>r@r�r�r�r�rVrr_rirj�staticmethodrqrrrsrurwr%r%r%r(r�s�
���	��
�

&
K
<





	
		


H
�
�&

)�	metaclasscCs�g}|s|St|t�r|��St|ttf�rt|�St|t�rC|��D]\}}t|t�r/|g}t|ttf�rB|D]	}|rA|�|�q8q#|Sr5)rXrE�
splitlines�listrYr[rUrW)�pubkey_data�keys�_keyname�klist�pkeyr%r%r(r-�s"



�r-r3c	Cs.t|||�}dd�|D�}t|vrdnd}	t�d|	|�t||�D]j\}
}tjd|
�dd�d	|	|
fd
|	|
f|d�}z?|�3t�d|�||||�}
|
�t	j
g�rkd
|	|
f|_|
t�
|�fWd�WSWd�n1suwYWq!ty�t�td|�Yq!wdd�|�}t|��)NcSsg|]}t�|��qSr%r�)rcr)r%r%r(rd�szfind_source.<locals>.<listcomp>�networkrz#Searching for %s data source in: %sz	search-%srrOzsearching for %s data from %szno %s data found from %s)�name�description�message�parentz%Seeing if we can get any data from %szfound %s data from %szGetting data from %s failedz4Did not find any data source, searched classes: (%s)r`)�list_sources�DEP_NETWORKr�r��zipr�ReportEventStackrZrirr{r�rr�r	rrr�rK)r�r�r��ds_deps�cfg_list�pkg_list�reporter�ds_list�ds_namesr�r��cls�myrep�s�msgr%r%r(�find_source�s>

�������r�cCs�g}t�d|||�|D];}|�t�sdt|f}t�||dg�\}}|s+t�d|�|D]}t�|�}t|d�}	|	|�}
|
rF|�	|
�nq-q|S)NzLLooking for data source in: %s, via packages %s that matches dependencies %sz%s%s�get_datasource_listzDCould not import %s. Does the DataSource exist and is it importable?)
r�r�rY�	DS_PREFIXr�find_module�error�
import_moduler�r])r��dependsr��src_list�ds_name�m_locs�_looked_locs�m_loc�mod�lister�matchesr%r%r(r��s8�
��


��r��system-uuid�fieldcCs*|sdSt�|�}|s
dS|��|��kSr*)r
�
read_dmi_datarV)r�r��	dmi_valuer%r%r(�instance_id_matches_system_uuids
r�cCsl|st}|st}|tkr|tkr|S|St��D]\}}|\}}|�|�r-||�r-|Sq|tkr4|S|S)z@Lookup the canonical cloud-id for a given cloud_name and region.)r�CLOUD_ID_REGION_PREFIX_MAPrUrY)r�r�r��prefix�
cloud_id_testr��valid_cloudr%r%r(r�%s �r�TcCsf|sdSt|t�r|St|t�rt�|�St|t�r+|dur't|�d�dd�Std��tdt	|���)aLdata: a loaded object (strings, arrays, dicts).
    return something suitable for cloudinit vendordata_raw.

    if data is:
       None: return None
       string: return string
       list: return data
             the list is then processed in UserDataProcessor
       dict: return convert_vendordata(data.get('cloud-init'))
    NTz
cloud-initF)�recursez'vendordata['cloud-init'] cannot be dictz$Unknown data type for vendordata: %s)
rXrEr�rSrTr[�convert_vendordatarirr")�datar�r%r%r(r�8s



r�c@rJ)�BrokenMetadataNrLr%r%r%r(r�PrMr�cCs4g}t|�}|D]\}}|t|�kr|�|�q|Sr5)rYrW)r�r��ret_list�depsetr��depsr%r%r(�list_from_depends[s
�r�rm�fnamecCsnzt�|�}Wntyt�td|�YdSwztj||ddd�WdSty6t�td|�YdSw)z[Use pickle to serialize Datasource to a file as a cache.

    :return: True on success
    zFailed pickling datasource %sF�wb�)�omoder�z Failed pickling datasource to %sT)�pickle�dumpsr	rrr�r�)rmr��pk_contentsr%r%r(r�ds���r�c
Cs�d}z	tj|dd�}Wnty*}ztj�|�r t�d||�WYd}~nd}~ww|s/dSzt�	|�WSt
y?YdStyOt�td|�YdSw)zBUse pickle to deserialize a instance Datasource from a cache file.NF)�decodezfailed loading pickle in %s: %sz#Failed loading pickled blob from %s)r�	load_filer	r�rn�isfiler�r�r�r�rGr)r��pickle_contentsr�r%r%r(�pkl_loadvs$���r�)rOr%)r�rx)R�abcrSr�r�r��collectionsr�enumrr�typingrrrrr	�	cloudinitr
rr�loggingr
rrr�r�cloudinit.atomic_helperr�cloudinit.distrosr�cloudinit.eventrr�cloudinit.filtersr�cloudinit.helpersr�cloudinit.persistencer�cloudinit.reportingr�DSMODE_DISABLED�DSMODE_LOCALrk�DSMODE_PASSrl�DEP_FILESYSTEMr�r�r��REDACT_SENSITIVE_VALUEr r�r�	getLoggerr<r�r�r-r	rGrKrNr\rorpru�ABCMetarr-rEr�r�r�r�r�r��IOErrorr�r�r�r�r%r%r%r(�<module>s�

�



�
#�
�


�% ��
�