HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/cloudinit/sources/__pycache__/__init__.cpython-38.pyc
U

��0h>��@s�ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZddlm
Z
mZmZmZmZmZmZddlmZmZmZmZmZmZmZddlmZddlmZddlm Z dd	l!m"Z"dd
l#m$Z$m%Z%ddl&m'Z'ddl(m)Z)dd
l*m+Z+ddl,m-Z-dZ.dZ/dZ0dZ1e.e/e0gZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:e�;e<�Z=ddd�fddd�fd d!d�fd"�Z>eGd#d$�d$e
��Z?Gd%d&�d&e
�Z@Gd'd(�d(eA�ZBGd)d*�d*eA�ZCGd+d,�d,eA�ZDd^d/d0�ZEe7fd1d2�ZFed3d4d5d6d7g�ZGed8d9d:g�ZHGd;d<�d<e�ZIGd=d�de+ejJd>�ZKd?d@�ZLeeKeMfdA�dBdC�ZNdDdE�ZOd_eMePdG�dHdI�ZQdJdK�ZRd`dMdN�ZSGdOdP�dPeT�ZUdQdR�ZVeKeMePdS�dTdU�ZWeMeeKdV�dWdX�ZXeMdA�dYdZ�ZYeMeMd[�d\d]�ZZdS)a�N)�
namedtuple)�Enum�unique)�Any�Dict�List�
NamedTuple�Optional�Tuple�Union)�
atomic_helper�dmi�importer�	lifecycle�net�performance�
type_utils)�	user_data)�util)�
write_json)�Distro)�
EventScope�	EventType)�launch_index)�Paths)�CloudInitPickleMixin)�eventsZdisabled�localr�passZ
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-nameZ_unset�unknownz	aws-chinacCs|dkS�NZaws���cr$r$�</usr/lib/python3/dist-packages/cloudinit/sources/__init__.py�<lambda>G�r(zaws-govcCs|dkSr#r$r%r$r$r'r(Hr)zazure-chinacCs|dkS)NZazurer$r%r$r$r'r(Ir))zcn-zus-gov-Zchinac@s2eZdZdZdZdZdZdZdZe	d�dd	�Z
d
S)�NetworkConfigSourcezb
    Represents the canonical list of network config sources that cloud-init
    knows about.
    Zcmdline�dsZ
system_cfgZfallbackZ	initramfs��returncCs|jS�N��value��selfr$r$r'�__str__ZszNetworkConfigSource.__str__N)�__name__�
__module__�__qualname__�__doc__�CMD_LINE�DS�
SYSTEM_CFGZFALLBACK�	INITRAMFS�strr3r$r$r$r'r*Msr*c@s&eZdZdZdZdZed�dd�ZdS)�NicOrderzRepresents ways to sort NICsZmacZnic_namer,cCs|jSr.r/r1r$r$r'r3dszNicOrder.__str__N)r4r5r6r7ZMACZNIC_NAMEr<r3r$r$r$r'r=^sr=c@seZdZdZdS)�DatasourceUnpickleUserDataErrorzERaised when userdata is unable to be unpickled due to python upgradesN�r4r5r6r7r$r$r$r'r>hsr>c@seZdZdS)�DataSourceNotFoundExceptionN�r4r5r6r$r$r$r'r@lsr@c@seZdZdZdS)�InvalidMetaDataExceptionz8Raised when metadata is broken, unavailable or disabled.Nr?r$r$r$r'rBpsrB�r$c
Cs�t�|�}g}g}|��D]�\}}|r4|d|}n|}|��|ksP|��|krZ|�|�t|t�r�|�d�r�|�|�|�dd�||<t|t	�rt
|||�}	|�|	�d��|�|	�d��|	||<qt
|�|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:rC�base64_encoded_keys�sensitive_keys)�copy�deepcopy�items�lower�append�
isinstancer<�
startswith�replace�dict�process_instance_metadata�extend�pop�sorted)
�metadata�key_pathrF�md_copyrEZ	sens_keys�key�valZsub_key_pathZ
return_valr$r$r'rPts6

�
�


�
rPcCs�|�dg�s|St�|�}|�d�D]V}|�d�}|}|D].}||kr:t||t�r:||dkr:||}q:||kr$|||<q$|S)z�Redact any sensitive keys from to provided metadata dictionary.

    Replace any keys values listed in 'sensitive_keys' with redact_value.
    rFrD���)�getrGrH�splitrLrO)rTZredact_valuerVrU�
path_parts�obj�pathr$r$r'�redact_sensitive_keys�s"

��
�

r_�	URLParamsZmax_wait_secondsZtimeout_secondsZnum_retries�sec_between_retries�DataSourceHostname�hostname�
is_defaultc@s*eZdZUdZeed<eed<eed<dS)�HotplugRetrySettingsz
in secondsZforce_retryZsleep_periodZsleep_totalN)r4r5r6r7�bool�__annotations__�intr$r$r$r're�s
rec	@s�eZdZUeZdZdZdZee	e
d<dZdZdZ
eeee	fe
d<ejejejejfZeedfe
d<dZd	Zd
ZdZejejejej ej!hiZ"ejejhiZ#de$fd
e$fdifddddddf	Z%eee	e&fdfe
d<dZ'dZ(ee	dfe
d<dZ)e*ddd�Z+dZ,ee	e
d<dZ-d}e.e/d�dd�Z0e1dd�dd �Z2d!d"�Z3e4d#�d$d%�Z5e4d#�d&d'�Z6d(d)�Z7d*d+�Z8d~d-d.�Z9e:j;d/d0d1�e4d#�d2d3��Z<dd5d6�Z=e4d#�d7d8�Z>d9d:�Z?d�d;d<�Z@d=d>�ZAd?d@�ZBeCdAdB��ZDeCdCdD��ZEdEdF�ZFeCdGdH��ZGdIdJ�ZHeCdKdL��ZIdMdN�ZJdOdP�ZKdQdR�ZLdSdT�ZMdUdV�ZNdWdX�ZOdYdZ�ZPd[d\�ZQd]d^�ZRd_d`�ZSeCdadb��ZTeCdcdd��ZUdedf�ZVd�dgdh�ZWdidj�ZXeYedk�dldm�ZZeYee4dn�dodp�Z[dqdr�Z\dsdt�Z]e^d�dudv��Z_eCdwdx��Z`dydz�Zad{d|�ZbdS)�r zen_US.UTF-8Z_undefN�_cloud_name�_crawled_metadata.�network_config_sourcesrY�
���ec2_metadata�network_jsonrT)�userdataN)�userdata_rawN)�
vendordataN)�vendordata_rawN)�vendordata2N)�vendordata2_rawN�cached_attr_defaultsF)
Zcombined_cloud_config�
merged_cfg�merged_system_cfgzsecurity-credentialsrq�	user-datarrs�vendor-datazds/vendor_data�sensitive_metadata_keysr�extra_hotplug_udev_rules)�distro�pathscCs�||_||_||_d|_i|_d|_d|_d|_d|_d|_	d|_
t|_t|_
t�|jd|jfi�|_|jsri|_|s�t�|j�|_n||_dS)NZ
datasource)�sys_cfgr~rrqrTrrrsrurtrv�metadata_address�UNSETrprorZget_cfg_by_path�dsname�ds_cfg�udZUserDataProcessor�ud_proc)r2r�r~rr�r$r$r'�__init__Ts.�zDataSource.__init__)�ci_pkl_versionr-cCs�dddtddtdddtddd�d�}|��D]\}}t||�s,t|||�q,t|d�sft|ddd��t|d�r�|jdk	r�zt|j�Wn6tk
r�}zt�	d	|�t
�|�W5d}~XYnXdS)
z(Perform deserialization fixes for Paths.NFr)rj�_platform_type�_subplatformror}r�rp�skip_hotplug_detectrurv�hotplug_retry_settings�check_if_fallback_is_allowedcSsdS�NFr$r$r$r$r'r(�r)z&DataSource._unpickle.<locals>.<lambda>rqz:Unable to unpickle datasource: %s. Ignoring current cache.)r�rerI�hasattr�setattrrqr<�AttributeError�LOG�debugr>)r2r�Zexpected_attrsrWr0�er$r$r'�	_unpicklens4
�


�zDataSource._unpicklecCs
t�|�Sr.�r�obj_namer1r$r$r'r3�szDataSource.__str__r,cCsdS)z#Check if running on this datasourceTr$r1r$r$r'�	ds_detect�szDataSource.ds_detectcCsN|j��t���kr$t�d|�dS|j�dg�|jgkrJt�d|�dSdS)aJOverride if either:
        - only a single datasource defined (nothing to fall back to)
        - command line argument is used (ci.ds=OpenStack)

        Note: get_cmdline() is required for the general case - when ds-identify
        does not run, _something_ needs to detect the kernel command line
        definition.
        z6Kernel command line set to use a single datasource %s.TZdatasource_listz2Datasource list set to use a single datasource %s.F)r�rJ�
parse_cmdliner�r�r�rZr1r$r$r'�override_ds_detect�s	��zDataSource.override_ds_detectcCs@|��r|��S|��r,t�d|�|��St�d|�dSdS)z&Overrides runtime datasource detectionzDetected %szDid not detect %sFN)r��	_get_datar�r�r�r1r$r$r'�_check_and_get_data�s�zDataSource._check_and_get_datacCs�|��j}|��}|j}|d}ddg||t|j|j|j�|j|j|dd|dd|dd|j|��|d|||d	d|||d	d
|j|j	|d|dd
�iS)z2Return a dictionary of standardized metadata keys.�sys_info�v1�subplatformZdistrrn��python�uname��platform�variant)Z
_beta_keys�availability-zone�availability_zone�cloud_idr!�
cloud_namer~Zdistro_versionZdistro_releaser�Zpublic_ssh_keysZpython_version�instance-id�instance_idZkernel_release�local-hostname�local_hostname�machine�regionr�Zsystem_platformr�)
�get_hostnamerc�get_instance_idr��canonical_cloud_idr�r��
platform_type�get_public_ssh_keysr�)r2�
instance_datar�r�r�Zsysinfor$r$r'�_get_standardized_metadata�sB
�




��z%DataSource._get_standardized_metadatar$cCsL|js
dS|r|}n|j}|D]\}}t||�rt|||�q|sHd|_dS)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_cacherwr�r�)r2Z
attr_defaultsZattr_valuesZ	attributer0r$r$r'�clear_cached_attrs�s
zDataSource.clear_cached_attrszGetting metadata�always)Zlog_modecCs"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)r2Zreturn_valuer$r$r'�get_data�szDataSource.get_dataTc

Cs`|r&tj�|jj�r&t||j�d��|jdk	r^t�	|j�}|�
dd�|�
dd�d|i}n>dd|jii}|jt
kr�|j|dd<|jt
kr�|j|dd<t|dd	<t�	|j�|d
<d|d
d	<t�	|d
�|d<d
|dd	<t��|d<|�|�|��z"t�|�}tt�|�|jd�}Wnrtk
�rZ}zt�dt|��WY�dSd}~XYn:tk
�r�}zt�dt|��WY�dSd}~XYnX|j� d�}|d�!dd�}tj�"|jj#d�}	t�$|	�d|��|�d��d}
|	�d|��}tj�%|	��r
tj�&|	�}
tj'||	dd�|
�r4|
|k�r4t�(|
�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.
        Zobj_pklNrzr{r+Z	meta_datarproZ_docrxz<DEPRECATED: Use merged_system_cfg. Will be dropped from 24.1ryzUMerged cloud-init system config from /etc/cloud/cloud.cfg and /etc/cloud/cloud.cfg.d/r�)rFz'Error persisting instance-data.json: %sFZinstance_data_sensitiver�r�Znonezcloud-id�-�
T)Zforcei�)�moder�)+�osr^�lexistsrZ
instance_link�	pkl_storeZ
get_ipath_currjrGrHrRrTrpr�ro�EXPERIMENTAL_TEXTr�rZsystem_info�updater�rZ
json_dumpsrP�json�loadsr|�	TypeErrorr��warningr<�UnicodeDecodeErrorZget_runpathrZ�joinZrun_dir�
write_file�exists�realpathZsym_linkZdel_filerr_)
r2Zwrite_cacheZcrawled_metadatar�ZcontentZprocessed_datar�Zjson_sensitive_filer�Z
cloud_id_fileZprev_cloud_id_fileZnew_cloud_id_fileZ	json_filer$r$r'r�
sh



����

�

z DataSource.persist_instance_datacCstd��dS)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.N)�NotImplementedErrorr1r$r$r'r�Vs�zDataSource._get_datac
CsL|j}zt|j�d|j��}Wn,tk
rJt�td|j�d�|�YnX|j}zt	dt|j�d|j���}Wn2tk
r�|j}t�td|j�d�|�YnX|j
}zt|j�d|j
��}Wn,tk
r�t�td|j�d�|�YnX|j}zt|j�d|j��}Wn.tk
�r<t�td	|j�d�|�YnXt
||||�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'razAConfig sec_between_retries '%s' is not an int, using default '%s')�url_max_waitrhr�rZ�
ValueErrorr�logexcr��url_timeout�max�url_retries�	Exception�url_sec_between_retriesr`)r2r�r�r�rar$r$r'�get_url_params]s^
�

�

�
��
�
zDataSource.get_url_paramscCs2|jdkr|j�|���|_|r,|�|j�S|jSr.)rqr��process�get_userdata_raw�
_filter_xdata)r2Zapply_filterr$r$r'�get_userdata�s

zDataSource.get_userdatacCs"|jdkr|j�|���|_|jSr.)rsr�r��get_vendordata_rawr1r$r$r'�get_vendordata�s
zDataSource.get_vendordatacCs"|jdkr|j�|���|_|jSr.)rur�r��get_vendordata2_rawr1r$r$r'�get_vendordata2�s
zDataSource.get_vendordata2cCs|js|j��|_|jSr.)r�r�rJr1r$r$r'r��szDataSource.platform_typecCs|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)
        )r��_get_subplatformr1r$r$r'r��s
zDataSource.subplatformcCs|jrd|j�d�StS)z?Subclasses should implement to return a "slug (detail)" string.z
metadata (�))r��METADATA_UNKNOWNr1r$r$r'r��szDataSource._get_subplatformcCsv|jr|jS|jrb|j�t�rb|j�t�}t|t�r@|��|_qp|����|_t�	dtt
|��n|����|_|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)rirTrZ�METADATA_CLOUD_NAME_KEYrLr<rJ�_get_cloud_namer�r��type)r2r�r$r$r'r��s
�zDataSource.cloud_namecCs|jS)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�r1r$r$r'r��szDataSource._get_cloud_namecCs"|js
dSd|jkr|jdSdS)Nzlaunch-index)rTr1r$r$r'r�s


zDataSource.launch_indexcCs0t�t�|j��g}|}|D]}|�|�}q|Sr.)rZFilterrZsafe_intZapply)r2Zprocessed_ud�filtersZnew_ud�fr$r$r'r��s�zDataSource._filter_xdatacCs|jSr.)rrr1r$r$r'r��szDataSource.get_userdata_rawcCs|jSr.)rtr1r$r$r'r��szDataSource.get_vendordata_rawcCs|jSr.)rvr1r$r$r'r��szDataSource.get_vendordata2_rawcCsiSr.r$r1r$r$r'�get_config_objszDataSource.get_config_objcCst|j�d��S)Nzpublic-keys)�normalize_pubkey_datarTrZr1r$r$r'r�szDataSource.get_public_ssh_keyscCsdS)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$)r2Zhostkeysr$r$r'�publish_host_keys	szDataSource.publish_host_keyscCsdddi}|��D]N\}}|�|�s$q|D]4}d||t|�d�f}tj�|�r(|Sq(qdS)NZsd)ZvdZxvdZvtbz	/dev/%s%s)rIrM�lenr�r^r�)r2Z
short_nameZmappingsZnfromZtlistZntoZcandr$r$r'�
_remap_devices
zDataSource._remap_devicecCsdSr.r$)r2�_namer$r$r'�device_name_to_device"sz DataSource.device_name_to_devicecCs.|j}z|j��}Wntk
r(YnX|S)z<Default locale is en_US.UTF-8, but allow distros to override)�default_localer~�
get_localer�)r2Zlocaler$r$r'r�*szDataSource.get_localecCs2|j�d|j�d��}|r|S|j�di��d�S)Nr�r�Z	placement�rTrZ)r2Ztop_level_azr$r$r'r�3s
�zDataSource.availability_zonecCs|j�d�S)Nr�r�r1r$r$r'r�<szDataSource.regioncCs"|jrd|jkrdSt|jd�S)Nr�ziid-datasource)rTr<r1r$r$r'r�@szDataSource.get_instance_idcCs^d}d}|}d}|jr"|j�d�s�|r0td|�Sg}t��}	|	dkrHd}t�|	�}
|
rt|
�d�dkrtt|
��d�}n8|	r�|	�d�dkr�t|	��d�}n|	r�|	|g}n||g}nX|jd}t	�
|�r�g}|r�t�|�}|r�t|��d�}nd	|�dd
�g}n
|�d�}t
|�dk�r0|d}	d�|dd��}n|d}	|�rT||k�rTd|	|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.
        ZlocaldomainZ	localhostFr�NT�.rzip-%sr�rnz%s.%s)rTrZrbrr�Zget_fqdn_from_hosts�findr<r[rZis_ipv4_addressZ
gethostbyaddrrNr�r�)r2ZfqdnZ
resolve_ipZ
metadata_onlyZ	defdomainZdefhostZdomainrdZtoksrcZ
hosts_fqdnZlhostr$r$r'r�FsF







zDataSource.get_hostnamecCs|jj|d�S)N)Zdata_source)r~�get_package_mirror_infor1r$r$r'r��sz"DataSource.get_package_mirror_info)�source_event_typescCsPi}|D]B}|j��D]2\}}||kr|�|�s:t�||<||�|�qq|Sr.)�supported_update_eventsrIrZ�set�add)r2r��supported_events�eventZupdate_scopeZ
update_eventsr$r$r'�get_supported_events�s�

zDataSource.get_supported_events)r�r-c	Cs�|�|�}|��D]<\}}t�d|jd�dd�|D���|�d|tff�q|rl|��|��}|rldSt�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�, cSsg|]
}|j�qSr$r/��.0r�r$r$r'�
<listcomp>�sz;DataSource.update_metadata_if_supported.<locals>.<listcomp>z
_%s_configTz(Datasource %s not updated for events: %scSsg|]
}|j�qSr$r/r�r$r$r'r�sF)	r�rIr�r�r0r�r�r�r�)r2r�r�ZscopeZmatched_events�resultr$r$r'�update_metadata_if_supported�s&
��z'DataSource.update_metadata_if_supportedcCsdSr�r$)r2r�r$r$r'�check_instance_id�szDataSource.check_instance_idcCsdS)acheck_if_fallback_is_allowed()
        Checks if a cached ds is allowed to be restored when no valid ds is
        found in local mode by checking instance-id and searching valid data
        through ds list.

        @return True if a ds allows fallback, False otherwise.
        Fr$r1r$r$r'r��sz'DataSource.check_if_fallback_is_allowedcCsV|dkrt}|dkrt}|D]4}|dkr*q||kr:|St�d||�|Sq|S)Nz%invalid dsmode '%s', using default=%s)�DSMODE_NETWORK�
VALID_DSMODESr�r�)Z
candidates�defaultZvalid�	candidater$r$r'�_determine_dsmode�s �
zDataSource._determine_dsmodecCsdSr.r$r1r$r$r'�network_config�szDataSource.network_configcCsdS)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$)r2�is_new_instancer$r$r'�setup�s	zDataSource.setupcCsdS)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$)r2Zcfgrr$r$r'�activate�szDataSource.activate)N)r$)T)F)FFF)NN)cr4r5r6rZdsmoder�r�rir	r<rgr�r�rjrrr*r8r;r:r9rkr
r�r�r�r�rrr�BOOT_NEW_INSTANCEZBOOTZBOOT_LEGACYZHOTPLUGr�Zdefault_update_eventsr�rwrr�r|r�rer�r}Z_ci_pkl_versionrrr�rhr�r3rfr�r�r�r�r�rZtimedr�r�r�r�r�r�r��propertyr�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�rrr��staticmethodr	r
rr
r$r$r$r'r �s�
� ����
�%&

L<




			


H�&

)�	metaclasscCs�g}|s|St|t�r|��St|ttf�r4t|�St|t�r�|��D]>\}}t|t�r^|g}t|ttf�rF|D]}|rp|�|�qpqF|Sr.)rLr<�
splitlines�listr�rOrIrK)Zpubkey_data�keysZ_keynameZklistZpkeyr$r$r'r�s 


r�r,cCs"t|||�}dd�|D�}t|kr&dnd}	t�d|	|�t||�D]�\}
}tjd|
�dd�d	|	|
fd
|	|
f|d�}zh|�Zt�d|�||||�}
|
�t	j
g�r�d
|	|
f|_|
t�
|�fW5QR�WSW5QRXWqBtk
�rt�td|�YqBXqBdd�|�}t|��dS)NcSsg|]}t�|��qSr$r�)rr�r$r$r'r'szfind_source.<locals>.<listcomp>Znetworkrz#Searching for %s data source in: %sz	search-%sr rCzsearching for %s data from %szno %s data found from %s)�nameZdescription�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��ziprZReportEventStackrNrrrrrr�r�rr�r�r@)r�r~rZds_deps�cfg_list�pkg_listZreporter�ds_listZds_namesr�r�clsZmyrep�s�msgr$r$r'�find_source#s4

��.�r!cCs�g}t�d|||�|D]j}t�|�}t�||dg�\}}|sJt�d|�|D]2}t�|�}	t|	d�}
|
|�}|rN|�|�qqNq|S)z�Return a list of classes that have the same depends as 'depends'
    iterate through cfg_list, loading "DataSource*" modules
    and calling their "get_datasource_list".
    Return an ordered list of classes that match (if any)
    zLLooking for data source in: %s, via packages %s that matches dependencies %sZget_datasource_listzDCould not import %s. Does the DataSource exist and is it importable?)	r�r�rZ"match_case_insensitive_module_name�find_module�error�
import_module�getattrrQ)r�dependsrZsrc_listr+Zds_nameZm_locsZ_looked_locsZm_loc�modZlisterZmatchesr$r$r'rDs6�
��


r�system-uuid)�fieldr-cCs*|sdSt�|�}|sdS|��|��kSr�)r
Z
read_dmi_datarJ)r�r)Z	dmi_valuer$r$r'�instance_id_matches_system_uuidhs
r*cCsl|st}|st}|tkr(|tkr$|S|St��D]*\}}|\}}|�|�r0||�r0|Sq0|tkrh|S|S)z@Lookup the canonical cloud-id for a given cloud_name and region.)r��CLOUD_ID_REGION_PREFIX_MAPrIrM)r�r�r��prefixZ
cloud_id_testr�Zvalid_cloudr$r$r'r�vs
r�TcCsj|sdSt|t�r|St|t�r*t�|�St|t�rV|dkrNt|�d�dd�Std��tdt	|���dS)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)
rLr<rrGrHrO�convert_vendordatarZr�r�)�datar-r$r$r'r.�s



r.c@seZdZdS)�BrokenMetadataNrAr$r$r$r'r0�sr0cCs4g}t|�}|D]\}}|t|�kr|�|�q|Sr.)r�rK)r&rZret_listZdepsetrZdepsr$r$r'�list_from_depends�sr1)r]�fnamer-cCstzt�|�}Wn$tk
r2t�td|�YdSXztj||ddd�Wn$tk
rnt�td|�YdSXdS)z[Use pickle to serialize Datasource to a file as a cache.

    :return: True on success
    zFailed pickling datasource %sF�wb�)Zomoder�z Failed pickling datasource to %sT)�pickle�dumpsr�rr�r�r�)r]r2Zpk_contentsr$r$r'r��sr�)r2r-c
Cs�d}zt�|�}Wn<tk
rN}ztj�|�r>t�d||�W5d}~XYnX|sXdSzt�	|�WSt
k
rzYdStk
r�t�td|�YdSXdS)zBUse pickle to deserialize a instance Datasource from a cache file.Nzfailed loading pickle in %s: %sz#Failed loading pickled blob from %s)rZload_binary_filer�r�r^�isfiler�r�r5r�r>r�)r2Zpickle_contentsr�r$r$r'�pkl_load�s r8cCstt���S)z�Check if command line argument for this datasource was passed
    Passing by command line overrides runtime datasource detection
    )�parse_cmdline_or_dmirZget_cmdliner$r$r$r'r��sr�)�inputr-cCs�t�d|�}t�d|�}t�d|�}|p.|p.|}|p6|}|rn|�d���}tjd|�d|��dd|�d	�d
�|r�|�d�r�|�d�SdS)Nz(?:^|\s)ds=([^\s;]+)z(?:^|\s)ci\.ds=([^\s;]+)z (?:^|\s)ci\.datasource=([^\s;]+)rnz8Defining the datasource on the command line using ci.ds=z or ci.datasource=z23.2zUse ds=z instead)�
deprecatedZdeprecated_versionZ
extra_messagerC)�re�search�group�striprZ	deprecate)r:Z
ds_parse_0Z
ds_parse_1Z
ds_parse_2r+r;r�r$r$r'r9�s
�	
r9)rCr$)r()T)[�abcrGr�Zloggingr�r5r<�collectionsr�enumrr�typingrrrrr	r
rZ	cloudinitrr
rrrrrrr�rZcloudinit.atomic_helperrZcloudinit.distrosrZcloudinit.eventrrZcloudinit.filtersrZcloudinit.helpersrZcloudinit.persistencerZcloudinit.reportingrZDSMODE_DISABLEDZDSMODE_LOCALrZDSMODE_PASSrZDEP_FILESYSTEMrZ	DS_PREFIXr�ZREDACT_SENSITIVE_VALUEr�r�r�Z	getLoggerr4r�r+r*r=r�r>r@rBrPr_r`rbre�ABCMetar r�r<r!rrfr*r�r.�IOErrorr0r1r�r8r�r9r$r$r$r'�<module>s�$$	
�



�

#��
�@
�!%��