x[hvddlZddlZddlmZddlmZddlmZejeZ dZ dZ d dZ dZ y) N)dmi)net) url_helperc d}g}tj}tjd||j dD]}tjd||j d}||vrt d|d||j d}|j |}tjd ||||j d d ||d }g} |j d D]+} || |j d} | j | -| |d<|j ||j drHtjd|j d|j d|j ddd|dS)aC Convert the UpCloud network metadata description into Cloud-init's version 1 netconfig format. Example JSON: { "interfaces": [ { "index": 1, "ip_addresses": [ { "address": "94.237.105.53", "dhcp": true, "dns": [ "94.237.127.9", "94.237.40.9" ], "family": "IPv4", "floating": false, "gateway": "94.237.104.1", "network": "94.237.104.0/22" }, { "address": "94.237.105.50", "dhcp": false, "dns": [], "family": "IPv4", "floating": true, "gateway": "", "network": "94.237.105.50/32" } ], "mac": "32:d5:ba:4a:36:e7", "network_id": "031457f4-0f8c-483c-96f2-eccede02909c", "type": "public" }, { "index": 2, "ip_addresses": [ { "address": "10.6.3.27", "dhcp": true, "dns": [], "family": "IPv4", "floating": false, "gateway": "10.6.0.1", "network": "10.6.0.0/22" } ], "mac": "32:d5:ba:4a:84:cc", "network_id": "03d82553-5bea-4132-b29a-e1cf67ec2dd1", "type": "utility" }, { "index": 3, "ip_addresses": [ { "address": "2a04:3545:1000:720:38d6:baff:fe4a:63e7", "dhcp": true, "dns": [ "2a04:3540:53::1", "2a04:3544:53::1" ], "family": "IPv6", "floating": false, "gateway": "2a04:3545:1000:720::1", "network": "2a04:3545:1000:720::/64" } ], "mac": "32:d5:ba:4a:63:e7", "network_id": "03000000-0000-4000-8046-000000000000", "type": "public" }, { "index": 4, "ip_addresses": [ { "address": "172.30.1.10", "dhcp": true, "dns": [], "family": "IPv4", "floating": false, "gateway": "172.30.1.1", "network": "172.30.1.0/24" } ], "mac": "32:d5:ba:4a:8a:e1", "network_id": "035a0a4a-77b4-4de5-820d-189fc8135714", "type": "private" } ], "dns": [ "94.237.127.9", "94.237.40.9" ] } c|jdrd}|jddk(rd}d|iSd}|jddk(rd}|d|jd d }|jd r|jd |d <d |jd vr&|jd jd d|d<||jdk7r%|jdr|jd|d<|S)NdhcpfamilyIPv6zipv6_dhcpv6-statelesstypestaticstatic6autoaddress)r controlrgateway/networknetmaskdnsdns_nameservers)getsplit)ip_addrr dhcp_type static_typesubparts C/usr/lib/python3/dist-packages/cloudinit/sources/helpers/upcloud.py_get_subnet_configz8convert_to_network_config_v1.._get_subnet_configrs ;;v I{{8$.4 I& & ;;x F *#K{{9-  ;;y !!(Y!7GI  '++i( (!(Y!7!=!=c!B1!EGI  '++e$ $U);)0U);G% &zNIC mapping: %s interfaceszConsidering %smacz3Did not find network interface on system with mac 'z'. Cannot apply configuration: r z4Found %s interface '%s' with address '%s' (index %d)indexphysical)r name mac_address ip_addressesrsubnetszSetting DNS nameservers to %s nameserver)r rr)versionconfig)cloudnetget_interfaces_by_macLOGdebugr RuntimeErrorappend) r+r nic_configsmacs_to_interfaces raw_ifacer& iface_type sysfs_name interfacer( ip_addresssub_parts rconvert_to_network_config_v1r:sF:K!779II!34ZZ -"&  "I.mmE* 0 0 +  ]]6* '++K8  B    MM' "  & #--7 %J)*fjj6GHH NN8 $ % ' )9%E"&Hzz% 16::e3DE!fjj.? @ K 00r ct|S)N)r:)r+s rconvert_network_configr<s ' //r ctj||||}|jstd|zt j |j jS)N)timeout sec_betweenretrieszunable to read metadata at %s)rreadurlokr0jsonloadscontentsdecode)urlr>r?r@responses r read_metadatarIsU!! W+wH ;;=:S@AA ::h''..0 11r ctjd}|dk7rytjd}|rtjd|d|fSd}tj |t |)Nzsystem-manufacturerUpCloud)FNz system-uuidz2system identified via SMBIOS as UpCloud server: %szsystem identified via SMBIOS as a UpCloud server, but did not provide an ID. Please contact support viahttps://hub.upcloud.com or via email with support@upcloud.comT)r read_dmi_datar.r/criticalr0) vendor_name server_uuidmsgs r read_sysinforQsu ##$9:Ki##M2K @+    L S3r )rR)rClogging cloudinitrrr,r getLogger__name__r.r:r<rIrQr rrYs>  % g!n1b02r