관리-도구
편집 파일: __init__.cpython-39.pyc
a ����'�Dg������������������������@���s���d�dl�Z�d�dlZd�dlZd�dlZd�dlZd�dlZd�dlZd�dlmZ�d�dl m Z mZ�d�dlm Z mZmZmZmZmZ�d�dlmZmZmZmZmZmZmZ�d�dlmZ�d�dlmZ�d�dlmZ�d�d l m!Z!�d�d l"m#Z#m$Z$�d�dl%m&Z&�d�dl'm(Z(�d�d l)m*Z*�d�dl+m,Z,�dZ-dZ.dZ/dZ0e-e.e/gZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9e�:e;�Z<ddd��fddd��fd d!d��fd"�Z=eG�d#d$��d$e ��Z>G�d%d&��d&e �Z?G�d'd(��d(e@�ZAG�d)d*��d*e@�ZBG�d+d,��d,e@�ZCdYd/d0�ZDe6fd1d2�ZEed3g�d4��ZFed5d6d7g�ZGG�d8d��de*e�jHd9�ZId:d;��ZJeeIeKf�d<�d=d>�ZLd?d@��ZMdZeKeNdB�dCdD�ZOdEdF��ZPd[dHdI�ZQG�dJdK��dKeR�ZSdLdM��ZTeIeKeNdN�dOdP�ZUeKeeI�dQ�dRdS�ZVeKd<�dTdU�ZWeKeKdV�dWdX�ZXdS�)\�����N)� namedtuple)�Enum�unique)�Any�Dict�List�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-chinac�����������������C���s���|�dkS��NZaws����cr#���r#����>/usr/lib/python3.9/site-packages/cloudinit/sources/__init__.py�<lambda>G��������r'���zaws-govc�����������������C���s���|�dkS�r"���r#���r$���r#���r#���r&���r'���H���r(���zazure-chinac�����������������C���s���|�dkS�)NZazurer#���r$���r#���r#���r&���r'���I���r(���)zcn-zus-gov-Zchinac�������������������@���s2���e�Zd�ZdZdZdZdZdZdZe d�dd �Z d S�)�NetworkConfigSourcezb Represents the canonical list of network config sources that cloud-init knows about. Zcmdline�dsZ system_cfg�fallbackZ initramfs��returnc�����������������C���s���|�j�S��N��value��selfr#���r#���r&����__str__Z���s����zNetworkConfigSource.__str__N)�__name__� __module__�__qualname__�__doc__�CMD_LINE�DS� SYSTEM_CFGZFALLBACK� INITRAMFS�strr3���r#���r#���r#���r&���r)���M���s���r)���c�������������������@���s&���e�Zd�ZdZdZdZed�dd�ZdS�)�NicOrderzRepresents ways to sort NICsZmacZnic_namer,���c�����������������C���s���|�j�S�r.���r/���r1���r#���r#���r&���r3���d���s����zNicOrder.__str__N)r4���r5���r6���r7���ZMACZNIC_NAMEr<���r3���r#���r#���r#���r&���r=���^���s���r=���c�������������������@���s���e�Zd�ZdZdS�)�DatasourceUnpickleUserDataErrorzERaised when userdata is unable to be unpickled due to python upgradesN�r4���r5���r6���r7���r#���r#���r#���r&���r>���h���s���r>���c�������������������@���s���e�Zd�ZdS�)�DataSourceNotFoundExceptionN�r4���r5���r6���r#���r#���r#���r&���r@���l���s���r@���c�������������������@���s���e�Zd�ZdZdS�)�InvalidMetaDataExceptionz8Raised when metadata is broken, unavailable or disabled.Nr?���r#���r#���r#���r&���rB���p���s���rB�����r#���c����������� ������C���s����t��|��}g�}g�}|����D�]�\}}|r4|d�|�}n|}|���|v�sP|���|v�rZ|�|��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_copyrE���Z sens_keys�key�valZsub_key_pathZ return_valr#���r#���r&���rP���t���s2���� � � � rP���c�����������������C���s����|���dg��s|�S�t�|��}|���d�D�]V}|�d�}|}|D�].}||v�r:t||�t�r:||d�kr:||�}q:||v�r$|||<�q$|S�)z�Redact any sensitive keys from to provided metadata dictionary. Replace any keys values listed in 'sensitive_keys' with redact_value. rF���rD������)�getrG���rH����splitrL���rO���)rT���Zredact_valuerV���rU���� path_parts�obj�pathr#���r#���r&����redact_sensitive_keys����s"���� �� � r_���� URLParams)Zmax_wait_secondsZtimeout_secondsZnum_retries�sec_between_retries�DataSourceHostname�hostname� is_defaultc���������������� ���@���s���e�Zd�ZU�eZdZdZdZee �e d<�dZdZdZ eeee f��e d<�ejejejejfZeedf�e d<�dZd Zd ZdZejejejej ej!hiZ"ejejhiZ#de$fd e$fdi�fddddddf Z%eee e&f�df�e d<�dZ'dZ(ee df�e d<�dZ)dZ*ee �e d<�dZ+d|e,e-d�dd�Z.e/dd�dd�Z0d d!��Z1e2d"�d#d$�Z3e2d"�d%d&�Z4d'd(��Z5d)d*��Z6d}d,d-�Z7e8j9d.d/d0�e2d"�d1d2��Z:d~d4d5�Z;e2d"�d6d7�Z<d8d9��Z=dd:d;�Z>d<d=��Z?d>d?��Z@eAd@dA���ZBeAdBdC���ZCdDdE��ZDeAdFdG���ZEdHdI��ZFeAdJdK���ZGdLdM��ZHdNdO��ZIdPdQ��ZJdRdS��ZKdTdU��ZLdVdW��ZMdXdY��ZNdZd[��ZOd\d]��ZPd^d_��ZQeAd`da���ZReAdbdc���ZSddde��ZTd�dfdg�ZUdhdi��ZVeWe�dj�dkdl�ZXeWe�e2dm�dndo�ZYdpdq��ZZdrds��Z[e\d�dtdu��Z]eAdvdw���Z^dxdy��Z_dzd{��Z`dS�)�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-credentialsrm���� user-datar���ro����vendor-datazds/vendor_data�sensitive_metadata_keys�extra_hotplug_udev_rules)�distro�pathsc�����������������C���s����||�_�||�_||�_d�|�_i�|�_d�|�_d�|�_d�|�_d�|�_d�|�_ d�|�_ t|�_t|�_ t�|�j�d|�jfi��|�_|�jsri�|�_|s�t�|�j�|�_n||�_d�S�)NZ datasource)�sys_cfgrz���r{���rm���rT���rn���ro���rq���rp���rr����metadata_address�UNSETrl���rk���r���Zget_cfg_by_path�dsname�ds_cfg�udZUserDataProcessor�ud_proc)r2���r|���rz���r{���r����r#���r#���r&����__init__D��s*�����zDataSource.__init__)�ci_pkl_versionr-���c�����������������C���s����dddt�ddt�dddd� }|���D�]\}}t|�|�s"t|�||��q"t|�d�s\t|�ddd����t|�d�r�|�jdur�zt|�j��W�n8�ty��}�z t�d|��t ��|�W�Y�d}~n d}~0�0�dS�) z(Perform deserialization fixes for Paths.NF) rf����_platform_type�_subplatformrk���ry���r}���rl����skip_hotplug_detectrq���rr����check_if_fallback_is_allowedc�������������������S���s���dS��NFr#���r#���r#���r#���r&���r'���q��r(���z&DataSource._unpickle.<locals>.<lambda>rm���z:Unable to unpickle datasource: %s. Ignoring current cache.) r~���rI����hasattr�setattrrm���r<����AttributeError�LOG�debugr>���)r2���r����Zexpected_attrsrW���r0����er#���r#���r&���� _unpickle^��s2����� �zDataSource._unpicklec�����������������C���s ���t��|��S�r.����r����obj_namer1���r#���r#���r&���r3������s����zDataSource.__str__r,���c�����������������C���s���dS�)z#Check if running on this datasourceTr#���r1���r#���r#���r&���� ds_detect���s����zDataSource.ds_detectc�����������������C���sN���|�j����t�����kr$t�d|���dS�|�j�dg��|�j�gkrJt�d|���dS�dS�)aJ��Override 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|���rZ���r1���r#���r#���r&����override_ds_detect���s���� ��zDataSource.override_ds_detectc�����������������C���s@���|�����r|����S�|����r,t�d|���|����S�t�d|���dS�dS�)z&Overrides runtime datasource detectionzDetected %szDid not detect %sFN)r����� _get_datar����r����r����r1���r#���r#���r&����_check_and_get_data���s�����zDataSource._check_and_get_datac�����������������C���s����|�����j}|����}|�j}|d�}ddg||t|�j|�j|�j�|�j|�j|d�d�|d�d�|d�d�|�j|����|d�|||d �d�|||d �d �|�j|�j |d�|d�d �iS�)z2Return a dictionary of standardized metadata keys.�sys_info�v1�subplatformZdistr���rj�������Zpython�uname�����platform�variant)Z _beta_keys�availability-zone�availability_zone�cloud_idr ���� cloud_namerz���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���s>���� � ��z%DataSource._get_standardized_metadatar#���c�����������������C���sL���|�j�s 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_cachers���r����r����)r2���Z attr_defaultsZattr_valuesZ attributer0���r#���r#���r&����clear_cached_attrs���s���� zDataSource.clear_cached_attrszGetting metadata�always)Zlog_modec�����������������C���s"���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)r2���Zreturn_valuer#���r#���r&����get_data���s����zDataSource.get_dataTc����������� ��� ���C���s\��|r&t�j�|�jj�r&t|�|�j�d���|�jdur^t� |�j�}|� dd��|� dd��d|i}n>dd|�jii}|�jt kr�|�j|d�d<�|�jt kr�|�j|d�d<�t|d�d <�t� |�j�|d <�d|d �d <�t� |d ��|d<�d |d�d <�t���|d<�|�|��|���z"t�|�}tt�|�|�jd�}W�nn�t�yX�}�zt�dt|���W�Y�d}~dS�d}~0��t�y��}�zt�dt|���W�Y�d}~dS�d}~0�0�|�j� d�}|d��!dd�}t�j�"|�jj#d�} t�$| ��d|���|��d���d} | ��d|���}t�j�%| ��rt�j�&| �} tj'|| dd��| �r0| |k�r0t�(| ��t)||dd��|�j� d�}t)|t*|���dS�)aP��Process 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_pklNrv���rw���r*���Z meta_datarl���rk���Z_docrt���z<DEPRECATED: Use merged_system_cfg. Will be dropped from 24.1ru���zUMerged cloud-init system config from /etc/cloud/cloud.cfg and /etc/cloud/cloud.cfg.d/r����)rF���z'Error persisting instance-data.json: %sFZinstance_data_sensitiver����r����Znonezcloud-id�-� T)�forcei���)�moder����)+�osr^����lexistsr{���Z instance_link� pkl_storeZ get_ipath_currf���rG���rH���rR���rT���rl���r~���rk����EXPERIMENTAL_TEXTr|���r���Zsystem_info�updater����r���Z json_dumpsrP����json�loadsrx���� TypeErrorr�����warningr<����UnicodeDecodeErrorZget_runpathrZ����joinZrun_dir� write_file�exists�realpathZsym_linkZdel_filer���r_���) r2���Zwrite_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_datac�����������������C���s���t�d��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)�NotImplementedErrorr1���r#���r#���r&���r����E��s�����zDataSource._get_datac�������������� ���C���sD��|�j�}zt|�j�d|�j���}W�n*�tyH���t�td|�j�d�|��Y�n0�|�j}zt dt|�j�d|�j���}W�n0�ty����|�j}t�td|�j�d�|��Y�n0�|�j }zt|�j�d|�j ��}W�n*�ty����t�td|�j�d�|��Y�n0�|�j}zt|�j�d|�j��}W�n,�t�y4���t�td |�j�d�|��Y�n0�t ||||�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'ra���zAConfig sec_between_retries '%s' is not an int, using default '%s')�url_max_wait�intr����rZ���� ValueErrorr����logexcr�����url_timeout�max�url_retries� Exception�url_sec_between_retriesr`���)r2���r����r����r����ra���r#���r#���r&����get_url_paramsL��s\���� � � � �� � zDataSource.get_url_paramsc�����������������C���s2���|�j�d�u�r|�j�|�����|�_�|r,|��|�j��S�|�j�S�r.���)rm���r�����process�get_userdata_raw� _filter_xdata)r2���Zapply_filterr#���r#���r&����get_userdata���s ���� zDataSource.get_userdatac�����������������C���s"���|�j�d�u�r|�j�|�����|�_�|�j�S�r.���)ro���r����r�����get_vendordata_rawr1���r#���r#���r&����get_vendordata���s���� zDataSource.get_vendordatac�����������������C���s"���|�j�d�u�r|�j�|�����|�_�|�j�S�r.���)rq���r����r�����get_vendordata2_rawr1���r#���r#���r&����get_vendordata2���s���� zDataSource.get_vendordata2c�����������������C���s���|�j�s|�j���|�_�|�j�S�r.���)r����r���rJ���r1���r#���r#���r&���r�������s����zDataSource.platform_typec�����������������C���s���|�j�s|����|�_�|�j�S�)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_subplatformr1���r#���r#���r&���r�������s���� zDataSource.subplatformc�����������������C���s���|�j�rd|�j���d�S�tS�)z?Subclasses should implement to return a "slug (detail)" string.z metadata (�))r}����METADATA_UNKNOWNr1���r#���r#���r&���r�������s����zDataSource._get_subplatformc�����������������C���sv���|�j�r|�j�S�|�jrb|�j�t�rb|�j�t�}t|t�r@|���|�_�qp|�������|�_�t� dtt |���n|�������|�_�|�j�S�)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)re���rT���rZ����METADATA_CLOUD_NAME_KEYrL���r<���rJ����_get_cloud_namer����r�����type)r2���r����r#���r#���r&���r�������s���� �zDataSource.cloud_namec�����������������C���s���|�j�S�)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���r1���r#���r#���r&���r�������s����zDataSource._get_cloud_namec�����������������C���s"���|�j�s d�S�d|�j�v�r|�j�d�S�d�S�)Nzlaunch-index)rT���r1���r#���r#���r&���r������s ���� zDataSource.launch_indexc�����������������C���s0���t��t�|�j���g}|}|D�]}|�|�}q|S�r.���)r���ZFilterr���Zsafe_intZapply)r2���Zprocessed_ud�filtersZnew_ud�fr#���r#���r&���r�������s�����zDataSource._filter_xdatac�����������������C���s���|�j�S�r.���)rn���r1���r#���r#���r&���r�������s����zDataSource.get_userdata_rawc�����������������C���s���|�j�S�r.���)rp���r1���r#���r#���r&���r�������s����zDataSource.get_vendordata_rawc�����������������C���s���|�j�S�r.���)rr���r1���r#���r#���r&���r�������s����zDataSource.get_vendordata2_rawc�����������������C���s���i�S�r.���r#���r1���r#���r#���r&����get_config_obj���s����zDataSource.get_config_objc�����������������C���s���t�|�j�d��S�)Nzpublic-keys)�normalize_pubkey_datarT���rZ���r1���r#���r#���r&���r�������s����zDataSource.get_public_ssh_keysc�����������������C���s���dS�)a5��Publish 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#���)r2���Zhostkeysr#���r#���r&����publish_host_keys���s����zDataSource.publish_host_keysc�����������������C���sd���ddi}|����D�]N\}}|�|�s$q|D�]4}d||t|�d���f�}tj�|�r(|����S�q(qd�S�)N�sd)ZvdZxvdZvtbz /dev/%s%s)rI���rM����lenr����r^���r����)r2���Z short_nameZmappingsZnfromZtlistZntoZcandr#���r#���r&���� _remap_device��s���� zDataSource._remap_devicec�����������������C���s���d�S�r.���r#���)r2����_namer#���r#���r&����device_name_to_device��s����z DataSource.device_name_to_devicec�����������������C���s,���|�j�}z|�j���}W�n�ty&���Y�n0�|S�)z<Default locale is en_US.UTF-8, but allow distros to override)�default_localerz���� get_localer����)r2����localer#���r#���r&���r������s����zDataSource.get_localec�����������������C���s2���|�j��d|�j��d��}|r|S�|�j��di���d�S�)Nr����r����Z placement�rT���rZ���)r2���Ztop_level_azr#���r#���r&���r����"��s�����zDataSource.availability_zonec�����������������C���s���|�j��d�S�)Nr����r����r1���r#���r#���r&���r����+��s����zDataSource.regionc�����������������C���s"���|�j�rd|�j�vrdS�t|�j�d��S�)Nr����ziid-datasource)rT���r<���r1���r#���r#���r&���r����/��s����zDataSource.get_instance_idc�����������������C���s^��d}d}|}d}|�j�r"|�j��d�s�|r0td|�S�g�}t���} | dkrHd}t�| �} | rt| �d�dkrtt| ��d�}n8| r�| �d�dkr�t| ��d�}n| r�| |g}n||g}nX|�j�d�}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�.r���zip-%sr����rj���z%s.%s)rT���rZ���rb���r���r����Zget_fqdn_from_hosts�findr<���r[���r���Zis_ipv4_addressZ gethostbyaddrrN���r����r����)r2���ZfqdnZ resolve_ipZ metadata_onlyZ defdomainZdefhost�domainrd���Ztoksrc���Z hosts_fqdnZlhostr#���r#���r&���r����5��sF���� zDataSource.get_hostnamec�����������������C���s���|�j�j|�d�S�)N)Zdata_source)rz����get_package_mirror_infor1���r#���r#���r&���r����}��s����z"DataSource.get_package_mirror_info)�source_event_typesc�����������������C���sP���i�}|D�]B}|�j����D�]2\}}||v�r|�|�s:t��||<�||��|��qq|S�r.���)�supported_update_eventsrI���rZ����set�add)r2���r�����supported_events�eventZupdate_scopeZ update_eventsr#���r#���r&����get_supported_events���s����� zDataSource.get_supported_events)r����r-���c�������������� ���C���s����|���|�}|���D�]<\}}t�d|jd�dd��|D�����|��d|�tff��q|rl|�����|����}|rldS�t�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�, c�����������������S���s���g�|�] }|j��qS�r#���r/�����.0r����r#���r#���r&���� <listcomp>���r(���z;DataSource.update_metadata_if_supported.<locals>.<listcomp>z _%s_configTz(Datasource %s not updated for events: %sc�����������������S���s���g�|�] }|j��qS�r#���r/���r����r#���r#���r&���r������r(���F) r����rI���r����r����r0���r����r����r~���r����)r2���r����r����ZscopeZmatched_events�resultr#���r#���r&����update_metadata_if_supported���s&���� ��z'DataSource.update_metadata_if_supportedc�����������������C���s���dS�r����r#���)r2���r|���r#���r#���r&����check_instance_id���s����zDataSource.check_instance_idc�����������������C���s���dS�)a��check_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#���r1���r#���r#���r&���r�������s����z'DataSource.check_if_fallback_is_allowedc�����������������C���sV���|d�u�rt�}|d�u�rt}|�D�]4}|d�u�r*q||v�r:|��S�t�d||��|��S�q|S�)Nz%invalid dsmode '%s', using default=%s)�DSMODE_NETWORK� VALID_DSMODESr����r����)Z candidates�defaultZvalid� candidater#���r#���r&����_determine_dsmode���s����� zDataSource._determine_dsmodec�����������������C���s���d�S�r.���r#���r1���r#���r#���r&����network_config���s����zDataSource.network_configc�����������������C���s���dS�)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.setupc�����������������C���s���dS�)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#���)r2���Zcfgr ��r#���r#���r&����activate���s����zDataSource.activate)N)r#���)T)F)FFF)NN)ar4���r5���r6���r��Zdsmoder����r���re���r���r<����__annotations__r����r����rf���r ���r���r)���r8���r;���r:���r9���rg���r ���r����r����r����r����r���r���r����BOOT_NEW_INSTANCEZBOOTZBOOT_LEGACYZHOTPLUGr����Zdefault_update_eventsr~���rs���r���r����rx���r����ry���Z_ci_pkl_versionr���r���r����r����r����r3����boolr����r����r����r����r����r���Ztimedr����r����r����r����r����r����r�����propertyr����r����r����r����r����r���r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r���r����r��r��r�����staticmethodr��r ��r��r��r#���r#���r#���r&���r�������s���� � ���� �$& L< H�& )� metaclassc�����������������C���s����g�}|�s|S�t�|�t�r|����S�t�|�ttf�r4t|��S�t�|�t�r�|����D�]>\}}t�|t�r^|g}t�|ttf�rF|D�]}|rp|�|��qpqF|S�r.���)rL���r<���� splitlines�listr����rO���rI���rK���)Zpubkey_data�keysZ_keynameZklistZpkeyr#���r#���r&���r�������s ���� r����r,���c�������������� ���C���s6��t�|||�}dd��|D��}t|v�r&dnd} t�d| |��t||�D�]�\} }tjd| �dd��d | | f�d | | f�|d�}z~|�f�t�d|��||�||�} | �t j g�r�d | | f�|_| t� |�fW��d�����W���S�W�d�����n1�s�0����Y��W�qB�t�y���t�td|��Y�qB0�qBdd�|��}t|��d�S�)Nc�����������������S���s���g�|�]}t��|��qS�r#���r����)r����r����r#���r#���r&���r�����r(���zfind_source.<locals>.<listcomp>�networkr���z#Searching for %s data source in: %sz search-%sr���rC���zsearching 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���ZReportEventStackrN���r��r���r��r��r���r����r����r���r����r����r@���)r|���rz���r{���Zds_deps�cfg_list�pkg_listZreporter�ds_listZds_namesr����r���clsZmyrep�s�msgr#���r#���r&����find_source��s4���� ��D�r$��c�����������������C���s����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����r ���Z"match_case_insensitive_module_name�find_module�error� import_module�getattrrQ���)r���dependsr��Zsrc_listr*���Zds_nameZm_locsZ_looked_locsZm_loc�modZlister�matchesr#���r#���r&���r��3��s2����� �� r���system-uuid)�fieldr-���c�����������������C���s*���|�sdS�t��|�}|sdS�|����|���kS�r����)r���Z read_dmi_datarJ���)r����r-��Z dmi_valuer#���r#���r&����instance_id_matches_system_uuidW��s���� r.��c�����������������C���sl���|�st�}�|st�}|t�kr(|�t�kr$|�S�|S�t���D�]*\}}|\}}|�|�r0||��r0|��S�q0|�t�krh|�S�|S�)z@Lookup the canonical cloud-id for a given cloud_name and region.)r�����CLOUD_ID_REGION_PREFIX_MAPrI���rM���)r����r����r�����prefixZ cloud_id_testr����Zvalid_cloudr#���r#���r&���r����e��s���� r����Tc�����������������C���sj���|�sdS�t�|�t�r|�S�t�|�t�r*t�|��S�t�|�t�rV|du�rNt|��d�dd�S�td��tdt |�����dS�)aL��data: 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) rL���r<���r��rG���rH���rO����convert_vendordatarZ���r����r����)�datar1��r#���r#���r&���r2��x��s���� r2��c�������������������@���s���e�Zd�ZdS�)�BrokenMetadataNrA���r#���r#���r#���r&���r4�����s���r4��c�����������������C���s4���g�}t�|��}|D�]\}}|t�|�kr|�|��q|S�r.���)r����rK���)r)��r ��Zret_listZdepsetr!��Zdepsr#���r#���r&����list_from_depends���s����r5��)r]����fnamer-���c�����������������C���sp���zt��|��}W�n"�ty0���t�td|���Y�dS�0�ztj||ddd��W�n"�tyj���t�td|��Y�dS�0�dS�)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����r���r����r����r����)r]���r6��Zpk_contentsr#���r#���r&���r�������s����r����)r6��r-���c�������������� ���C���s����d}zt��|��}W�n>�tyP�}�z&tj�|��r<t�d|�|��W�Y�d}~n d}~0�0�|sZdS�zt� |�W�S��t yz���Y�dS��ty����t��td|���Y�dS�0�dS�)zBUse pickle to deserialize a instance Datasource from a cache file.Nzfailed loading pickle in %s: %sz#Failed loading pickled blob from %s)r���Zload_binary_filer����r����r^����isfiler����r����r9��r����r>���r����)r6��Zpickle_contentsr����r#���r#���r&����pkl_load���s����$r<��c�������������������C���s���t�t����S�)z�Check if command line argument for this datasource was passed Passing by command line overrides runtime datasource detection )�parse_cmdline_or_dmir���Zget_cmdliner#���r#���r#���r&���r�������s����r����)�inputr-���c�����������������C���s����t��d|��}t��d|��}t��d|��}|p.|p.|}|p6|}|rn|�d����}tjd|��d|���dd|��d �d ��|r�|�d�r�|�d�S�dS�)Nz(?:^|\s)ds=([^\s;]+)z(?:^|\s)ci\.ds=([^\s;]+)z (?:^|\s)ci\.datasource=([^\s;]+)rj���z8Defining 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�stripr���Z deprecate)r>��Z ds_parse_0Z ds_parse_1Z ds_parse_2r*���r?��r���r#���r#���r&���r=�����s&������ � r=��)rC���r#���)r,��)T)Y�abcrG���r����Zloggingr����r9��r@���collectionsr����enumr���r����typingr���r���r���r���r ���r ���Z cloudinitr���r���r ���r���r���r���r���r���r����r���Zcloudinit.atomic_helperr���Zcloudinit.distrosr���Zcloudinit.eventr���r���Zcloudinit.filtersr���Zcloudinit.helpersr���Zcloudinit.persistencer���Zcloudinit.reportingr���ZDSMODE_DISABLEDZDSMODE_LOCALr��ZDSMODE_PASSr��ZDEP_FILESYSTEMr��Z DS_PREFIXr����ZREDACT_SENSITIVE_VALUEr����r~���r����Z getLoggerr4���r����r/��r)���r=���r����r>���r@���rB���rP���r_���r`���rb����ABCMetar���r����r<���r$��r��r��r.��r����r2���IOErrorr4��r5��r����r<��r����r=��r#���r#���r#���r&����<module>���s���� $ � � #� �������7 �!%���