name : aliyun.cpython-39.pyc
a

��h��	@s`ddlZddlmZddlmZmZmZddlmZe�	e
�Zddd	�Zdd
d�Z
dd
d�ZdS)�N)�MutableMapping)�net�
url_helper�util)�ec2�latest�http://100.100.100.200�c	sPt�||�}t�|d�}tj|||||||d�}	t�|	j�}
�fdd���|
�S)Nz
meta-data/all��ssl_details�timeout�retries�exception_cb�
headers_cb�headers_redactcsNt|t�r �fdd�|��D�St|t�r<�fdd�|D�St��d|�SdS)Ncsi|]\}}|�|��qS�r)�.0�k�v��_process_dict_valuesr�D/usr/lib/python3.9/site-packages/cloudinit/sources/helpers/aliyun.py�
<dictcomp>W�zHget_instance_meta_data.<locals>._process_dict_values.<locals>.<dictcomp>csg|]}�|��qSrr)r�itemrrr�
<listcomp>YrzHget_instance_meta_data.<locals>._process_dict_values.<locals>.<listcomp>�)�
isinstance�dict�items�listrZMetadataLeafDecoder)�drrrrUs


z4get_instance_meta_data.<locals>._process_dict_values)r�combine_url�read_file_or_urlrZ	load_json�contents)�api_version�metadata_addressrrr
rrr�ud_url�responseZ
meta_data_rawrrr�get_instance_meta_datas
�	4r)c	
	Cs�t�||�}	t�|	|�}	d}
ddg}||vr<t�d|�|
Sz"tj|	||||||d�}|j}
Wn"ty�t�td||	�Yn0|
S)Nrz	user-datazvendor-dataz*aliyun datasource not support the item  %sr
zFailed fetching %s from url %s)	rr"�LOG�errorr#r$�	ExceptionrZlogexc)
r%r&rrr
rrrZ	item_namer'�dataZsupport_items_listr(rrr�get_instance_data`s0��	
r.TcCs�did�}|st��}|dd}|s�|��D]\}}||kr.qDq.ddd|��i|d�}|�|�}	|	�d	�rvd|d
<||d|<|St�}
|��D] \}}|�|�}	|	s�q�||
|<q�t|
��tjd�}t	|�D]j\}}|
|}
|�|
�}	d
|ddi}d|dd|
��i|d�}|	�d	��r.d|d
<||d<||d|<q�t
|d�dk�r�|d��D]T}|d|�d�|d|�dd�|d|�dd�|d|�dd��qZ|S)a�Convert ecs metadata to network config version 2 data dict.

    @param: network_md: 'network' portion of ECS metadata.
    generally formed as {"interfaces": {"macs": {}} where
    'macs' is a dictionary with mac address as key:
    @param: macs_to_nics: Optional dict of mac addresses and nic names. If
    not provided, get_interfaces_by_mac is called to get it from the OS.
    @param: fallback_nic: Optionally provide the primary nic interface name.
    This nic will be guaranteed to minimally have a dhcp4 configuration.
    @param: full_network_config: Boolean set True to configure all networking
    presented by IMDS. This includes rendering secondary IPv4 and IPv6
    addresses on all NICs and rendering network config on secondary NICs.
    If False, only the primary nic will be configured and only with dhcp
    (IPv4/IPv6).

    @return A dict of network config version 2 based on the metadata and macs.
    �)�version�	ethernetsZ
interfacesZmacsTFZ
macaddress)�dhcp4�dhcp6�match�set-nameZipv6sr3r1)�keyzroute-metric��d)r2�dhcp4-overridesr3r4r5zdhcp6-overridesr9NZrouteszrouting-policy)rZget_interfaces_by_macr�lower�getr�sorted�keysZnatural_sort_key�	enumerate�len�pop)Z
network_mdZmacs_to_nicsZfallback_nicZfull_network_configZnetcfgZ
macs_metadataZmacZnic_nameZ
dev_configZnic_metadataZnic_name_2_mac_mapZorderd_nic_name_listZnic_idxZnic_macZ
dhcp_overriderrr�#convert_ecs_metadata_network_config�s`

�




�

�rA)rrNr	r	NNN)	rrNr	r	NNNN)NNT)Zlogging�typingrZ	cloudinitrrrZcloudinit.sources.helpersrZ	getLogger�__name__r*r)r.rArrrr�<module>s6
�
U�
'�

© 2025 Cubjrnet7