o x[h@sddlZddlZddlZddlmZddlmZddlmZmZdddZ e e Z ddd Z d d Zdd d ZddZdddZddZdS)N)dmi)net) url_helperutileth0eth1)publicprivatec Cs|s t|}td||stddtddtdd}z|j|||j |td||W|St yGt td ||w) zBring up NIC using an address using link-local (ip4LL) IPs. On DigitalOcean, the link-local domain is per-droplet routed, so there is no risk of collisions. However, to be more safe, the ip4LL address is random. z,selected interface '%s' for reading metadatazPunable to find interfaces to access themeta-data server. This droplet is broken.z169.254.{0}.{1}/16rz&brought device '%s' up with address %szRip4LL address assignment of '%s' to '%s' failed. Droplet networking will be broken) get_link_local_nicLOGdebug RuntimeErrorformatrandomrandintnet_opsadd_addrlink_up Exceptionrlogexc)distronicaddrrH/usr/lib/python3/dist-packages/cloudinit/sources/helpers/digitalocean.pyassign_ipv4_link_locals0   rcs.fddtD}|sdSt|dddS)Ncsg|] }j|r|qSr) networking is_physical).0frrr 9s  z&get_link_local_nic..cSs t|dS)Nifindex)cloudnetread_sys_net_int)drrr@s z$get_link_local_nic..)key)r&get_devicelistmin)rnicsrr#rr 8s r c Csr|s tddStdz|j|td|WdSty8}zttd||WYd}~dSd}~ww)zwRemove the ip4LL address. While this is not necessary, the ip4LL address is extraneous and confusing to users. zLno link_local address interface defined, skipping link local address cleanupNzcleaning up ipv4LL addresszremoved ip4LL addresses from %sz)failed to remove ip4LL address from '%s'.)rrr flush_addrrrr)rrerrrdel_ipv4_link_localCs  r0cCsRdd}g}t}td||D]}||d}td||d}||vr1td||f||}|dd } t| |} | |krPtd | ||| n d } t| ||d || d } g} dD]}||d}|snqc||}| dkszd|vr}|d=| |qc| | d<|| td| | q|rtd||d|dd|dS)a}Convert the DigitalOcean Network description into Cloud-init's netconfig format. Example JSON: {'public': [ {'mac': '04:01:58:27:7f:01', 'ipv4': {'gateway': '45.55.32.1', 'netmask': '255.255.224.0', 'ip_address': '45.55.50.93'}, 'anchor_ipv4': { 'gateway': '10.17.0.1', 'netmask': '255.255.0.0', 'ip_address': '10.17.0.9'}, 'type': 'public', 'ipv6': {'gateway': '....', 'ip_address': '....', 'cidr': 64}} ], 'private': [ {'mac': '04:01:58:27:7f:02', 'ipv4': {'gateway': '10.132.0.1', 'netmask': '255.255.0.0', 'ip_address': '10.132.75.35'}, 'type': 'private'} ] } cSsZdd|d|dd}d|dvr$d|d|d|d <|S|d |d <|S) Nstaticauto ip_addressgateway)typecontroladdressr4:z{0}/{1}cidrr7netmask)getr)pcfgsubpartrrr_get_subnet_partusz7convert_network_configuration.._get_subnet_partznic mapping: %srzconsidering %smaczVDid not find network interface on system with mac '%s'. Cannot apply configuration: %sr5unknownz6Found %s interface '%s' on '%s', assigned name of '%s'zfFound interface '%s' on '%s', which is not a public or private interface. Using default system naming.physical)r5 mac_addressname)ipv4ipv6 anchor_ipv4 anchor_ipv6Nranchorr4subnetsznic '%s' configuration: %szadded dns servers: %s nameserver)r5r7r )versionconfig)r&get_interfaces_by_macrrr;rNIC_MAPappend)rL dns_serversr> nic_configs macs_to_nicsnrrB sysfs_namenic_typeif_namemsgncfgrInetdef raw_subnetsub_partrrrconvert_network_configurationXs`             r\cCs6tj||||d}|std|t|jS)N)timeout sec_betweenretrieszunable to read metadata at %s)rreadurlokrjsonloadscontentsdecode)urlr_r`raresponserrr read_metadatas  rjcCsNtd}|dkr dStd}|rtd|d|fSd}t|t|)Nzsystem-manufacturer DigitalOcean)FNzsystem-serial-numberz8system identified via SMBIOS as DigitalOcean Droplet: %szsystem identified via SMBIOS as a DigitalOcean Droplet, but did not provide an ID. Please file a support ticket at: https://cloud.digitalocean.com/support/tickets/newT)r read_dmi_datarrcriticalr) vendor_name droplet_idrWrrr read_sysinfos   rp)N)r]r]r^)rdloggingr cloudinitrrr&rrrN getLogger__name__rrr r0r\rjrprrrrs     &  n