name : DataSourceConfigDrive.cpython-39.pyc
a

'�Dg�,�@s�ddlZddlZddlmZmZmZmZddlmZm	Z	ddl
mZddlm
Z
ddlmZe�e�ZdZdeiZd	Zd
ZdZedd
�eD��ZGdd�dejej�Zdd�Zdd�Zddd�Zdd�Z ddd�Z!eZ"eej#ffgZ$dd�Z%dS)�N)�	lifecycle�sources�subp�util)�
EventScope�	EventType)�eni)�get_ibm_platform)�	openstackziid-dsconfigdrive�instance-id)ZvfatZiso9660)zconfig-2zCONFIG-2)�srZcdccs(|] }td�D]}d||fVqqdS)�z	/dev/%s%sN)�range)�.0�z�i�r�K/usr/lib/python3.9/site-packages/cloudinit/sources/DataSourceConfigDrive.py�	<genexpr>�rcsreZdZdZejejejej	ej
hiZ�fdd�Zdd�Z
dd�Zdd	�Zed
d��Zedd
��Zdd�Z�ZS)�DataSourceConfigDriveZConfigDrivecs\tt|��|||�d|_tj�|jd�|_d|_d|_	d|_
tj|_
d|_d|_i|_dS)NZconfig_drive)�superr�__init__�source�os�path�join�seed_dir�version�ec2_metadata�_network_configr�UNSET�network_json�network_eni�
known_macs�files)�self�sys_cfg�distro�paths��	__class__rrr.szDataSourceConfigDrive.__init__cCs0tj�|�}d||j|jf}|d|j7}|S)Nz%s [%s,ver=%s]z[source=%s])r�
DataSource�__str__�dsmoderr)r&�rootZmstrrrrr-:szDataSourceConfigDrive.__str__c

Cs�d}i}i}|jdfD]L}tj�|�s(qzt|�}|}WqdWqtjy`t�t	d|�Yq0q|�s
|j
�d�}t|d�D]�}d}t�
�r�|�d�r�d}ztj|t|d�}|}WnFtjy�Yn4tjy�Yn"tjy�t�t	d|�Yn0|r��q
q�|�sd	S|�d
i�}t�|tg�}|�|�d�|j�d�|dd
k�rXtjndg�|_|jtjk�rtd	St|j�}|d}	||	k�r�t||j|jtjkd�|jtjk�r�t	�d||j�d	S||_||_ |�d�|_!|�d�|_"|d|_#|j$�%|�di��|�d�}
zt�&|
�|_'Wn8t(�y^}zt	�)d|�d|_'WYd}~n
d}~00|�d�}zt�&|�|_*Wn8t(�y�}zt	�)d|�d|_*WYd}~n
d}~00|�d�|_+|�d�|_,dS)Nz
/config-drivez#Failed reading config drive from %sZdatasource_list)�dslistz/dev/cdZcd9660)�mtypezBroken config drive: %sF�metadatar.r�r)r(�networkz&%s: not claiming datasource, dsmode=%szec2-metadataZuserdatar%Z
vendordataz"Invalid content in vendor-data: %sZvendordata2z#Invalid content in vendor-data2: %s�network_configZnetworkdataT)-rrr�isdir�read_config_driver
�NonReadabler�logexc�LOGr'�get�find_candidate_devsZis_BSD�
startswithZmount_cbZMountFailedErrorZBrokenMetadataZ
mergemanydict�DEFAULT_METADATAZ_determine_dsmodeZds_cfgrZDSMODE_PASSr.ZDSMODE_DISABLED�get_previous_iidr)�
on_first_bootr(�debugrr2rZuserdata_rawrr%�updateZconvert_vendordataZvendordata_raw�
ValueError�warningZvendordata2_rawr#r")
r&�foundZmd�resultsZsdirr0�devr1Zprev_iidZcur_iidZvd�eZvd2rrr�	_get_data@s�

�
��


��


zDataSourceConfigDrive._get_datacCst�|���S�N)rZinstance_id_matches_system_uuidZget_instance_id)r&r'rrr�check_instance_id�sz'DataSourceConfigDrive.check_instance_idcCs~|jdurx|jdtjfvr:t�d�tj|j|jd�|_n>|j	durnt
�|j	�|_t�d�tj
dddd�n
t�d�|jS)	Nz(network config provided via network_json)r$z.network config provided via converted eni dataz(Eni network configuration in ConfigDrivez24.3z<You can use openstack's network configuration format instead)Z
deprecatedZdeprecated_versionZ
extra_messagez"no network configuration available)r r"rr!r:rAr
Zconvert_net_jsonr$r#r�convert_eni_datarZ	deprecate�r&rrrr5�s 

�


�	
z$DataSourceConfigDrive.network_configcCsdS)Nr
rrMrrr�platform�szDataSourceConfigDrive.platformcCs$|j�d�rd}nd}d||jfS)z/Return the subplatform metadata source details.z/devzconfig-diskzseed-dirz%s (%s))rr=)r&Zsubplatform_typerrr�_get_subplatform�sz&DataSourceConfigDrive._get_subplatform)�__name__�
__module__�__qualname__ZdsnamerZNETWORKrZBOOT_NEW_INSTANCEZBOOTZBOOT_LEGACYZHOTPLUGZsupported_update_eventsrr-rIrK�propertyr5rNrO�
__classcell__rrr*rr!s"��	d

rcCs�t�|�}|jgif|jgifg}g}|D]P\}}}z||i|��WStjyx}z|�|�WYd}~q*d}~00q*|d�dS)N���)r
ZConfigDriveReaderZread_v2Zread_v1r8�append)Z
source_dir�readerZfindersZexcpsZfunctor�args�kwargsrHrrrr7�s


�"r7cCs@tj�|�d�d�}zt�|��d�WSty:YdS0dS)N�datar�
)rrrZ	get_cpathrZload_text_file�rstrip�IOError)r)�fnamerrrr?�s
r?TcCs^t|t�stdt|���|rL|�dd�}|rL|rLt�d�|�t�	|��t
|�d��dS)zDPerforms any first-boot actions using data read from a config-drive.z/Config-drive data expected to be a dict; not %sr5�z-Updating network interfaces from config driver%N)�
isinstance�dict�	TypeError�typer;r:rDZapply_network_configrrL�write_injected_files)rZr(r4Znet_confrrrr@�s

�
r@c	Csv|rrt�dt|��|��D]T\}}|�tj�s:tj|}ztj||dd�Wqt	ynt�
td|�Yq0qdS)NzWriting %s injected filesi�)�modezFailed writing file: %s)r:rA�len�itemsr=r�seprZ
write_filer]r9)r%�filenameZcontentrrrrd�s
rdc
	s|durg}|r@tD]*}ztj|d�Wqtjy<Yq0qg}tD]}|�t�d|��qHg�tD]}��t�d|��qj|jdd��jdd���fdd�|D�}�fd	d�|D�}t	�
d
||�|�rd|v�rt�\}}	|	|v�r|�|	�t	�
d|	|�|S)
aReturn a list of devices that may contain the config drive.

    The returned list is sorted by search order where the first item has
    should be searched first (highest priority)

    config drive v1:
       Per documentation, this is "associated as the last available disk on the
       instance", and should be VFAT.
       Currently, we do not restrict search list to "last available disk"

    config drive v2:
       Disk should be:
        * either vfat or iso9660 formatted
        * labeled with 'config-2' or 'CONFIG-2'
    N)rzTYPE=%szLABEL=%sT)�reversecsg|]}|�vr|�qSrr�r�d�Zby_labelrr�
<listcomp>*rz'find_candidate_devs.<locals>.<listcomp>cs"g|]}|�vst�|�s|�qSr)rZis_partitionrkrmrrrn.szdevices=%s dslist=%sZIBMCloudz5IBMCloud device '%s' (%s) removed from candidate list)
�OPTICAL_DEVICESrZfind_devs_withrZProcessExecutionError�FS_TYPES�extend�LABEL_TYPES�sortr:rAr	�remove)
Z
probe_opticalr0ZdeviceZ	by_fstypeZfs_typeZlabelZ
candidatesZdevicesZibm_platformZibm_pathrrmrr<s>
�


�r<cCst�|t�SrJ)rZlist_from_depends�datasources)Zdependsrrr�get_datasource_listKsrv)NT)TN)&ZloggingrZ	cloudinitrrrrZcloudinit.eventrrZ
cloudinit.netrZ$cloudinit.sources.DataSourceIBMCloudr	Zcloudinit.sources.helpersr
Z	getLoggerrPr:ZDEFAULT_IIDr>rprrZPOSSIBLE_MOUNTS�tupleroZSourceMixinr,rr7r?r@rdr<ZDataSourceConfigDriveNetZDEP_FILESYSTEMrurvrrrr�<module>	s6
��,

B
�

© 2025 Cubjrnet7