o x[h@sddlZddlmZddlmZmZmZddlmZe e Z        ddd Z         dd d Z   dd dZdS)N)MutableMapping)net url_helperutil)ec2latesthttp://100.100.100.200c sPt||}t|d}tj|||||||d} t| j} fdd| S)Nz meta-data/all ssl_detailstimeoutretries exception_cb headers_cbheaders_redactcsJt|trfdd|DSt|trfdd|DStd|S)Ncsi|] \}}||qSr).0kv_process_dict_valuesrB/usr/lib/python3/dist-packages/cloudinit/sources/helpers/aliyun.py WszHget_instance_meta_data.._process_dict_values..csg|]}|qSrr)ritemrrr YszHget_instance_meta_data.._process_dict_values..) isinstancedictitemslistrMetadataLeafDecoder)drrrrUs  z4get_instance_meta_data.._process_dict_values)r combine_urlread_file_or_urlr load_jsoncontents) api_versionmetadata_addressr r r rrrud_urlresponse meta_data_rawrrrget_instance_meta_data s  4r+c Cst||} t| |} d} ddg} || vrtd|| Sztj| ||||||d} | j} W| StyBttd|| Y| Sw)Nz user-dataz vendor-dataz*aliyun datasource not support the item %sr zFailed fetching %s from url %s) rr"LOGerrorr#r% Exceptionrlogexc) r&r'r r r rrr item_namer(datasupport_items_listr)rrrget_instance_data`s4   r4TcCsdid}|s t}|dd}|sC|D] \}}||kr!nqddd|i|d}||} | d r;d|d <||d |<|St} |D]\}}||} | sVqJ|| |<qJt| tjd } t | D]4\} }| |} || } d | ddi}d|dd| i|d}| d rd|d <||d<||d |<qht |d dkr|d D])}|d | d|d | dd|d | dd|d | ddq|S)aConvert 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 ethernets interfacesmacsTF macaddress)dhcp4dhcp6matchset-nameipv6sr<r7)keyz route-metricd)r;dhcp4-overridesr<r=r>zdhcp6-overridesrCNrouteszrouting-policy) rget_interfaces_by_macrlowergetrsortedkeysnatural_sort_key enumeratelenpop) network_md macs_to_nics fallback_nicfull_network_confignetcfg macs_metadatamacnic_name dev_config nic_metadatanic_name_2_mac_maporderd_nic_name_listnic_idxnic_mac dhcp_overriderrr#convert_ecs_metadata_network_configsb            r])rrNr r NNN) rrNr r NNNN)NNT)loggingtypingr cloudinitrrrcloudinit.sources.helpersr getLogger__name__r-r+r4r]rrrrs8    U '