܍~crddlZddlZddlmZddlmZddlmZddlmZm Z m Z dddZ ej e Zdd Zd Zdd Zd ZddZdZdS)N)dmi)log)net)subp url_helperutileth0eth1)publicprivatecv|s*t|}td||stddt jddt jdd}dd d |d |g}dd d d |dg}tjdstd tj|td||tj|td|n+#t$rtj td||wxYw|S)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}/16ripaddradddevlinksetupz4No 'ip' command available to configure ip4LL addressz#assigned ip4LL address '%s' to '%s'zbrought device '%s' upzRip4LL address assignment of '%s' to '%s' failed. Droplet networking will be broken) get_link_local_nicLOGdebug RuntimeErrorformatrandomrandintrwhich Exceptionrlogexc)distronicr ip_addr_cmd ip_link_cmds H/usr/lib/python3/dist-packages/cloudinit/sources/helpers/digitalocean.pyassign_ipv4_link_localr'sl G (( @#FFF   8   & &q#q# 6 6  DeS9KsD9K :d    B     + 7sCCC + *C0000   1        Js .AD(D6cnfdtjD}|sdSt|dS)NcHg|]}j||S) networking is_physical).0fr"s r& z&get_link_local_nic..Bs@      ( ( + +     c,tj|dS)Nifindex)cloudnetread_sys_net_int)ds r&z$get_link_local_nic..Is8#Ls   $    II*+++%5KN + 3S99999 NNN CDc1MMMMMMMMMNs/A22 B#<BB#cd}g}tj}td||D]l}||d}td||d}||vrt d|d|||}|dd } t | |} | |krtd | ||| nd } t| ||d || d } g} dD]H}||d}|s||}| dksd|vr|d=| |I| | d<|| td| | n|r3td||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'} ] } c>dd|d|dd}d|dvr@d|d|d|d <n|d |d <|S) Nstaticauto ip_addressgateway)typecontroladdressrD:z{0}/{1}cidrrGnetmask)getr)pcfgsubparts r&_get_subnet_partz7convert_network_configuration.._get_subnet_partsxx --xx **    $((<(( ( (!*!1!1&&(8(8""GI  "&)!4!4GI r0znic mapping: %srzconsidering %smacz3Did not find network interface on system with mac 'z'. Cannot apply configuration: rEunknownz6Found %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)rE mac_addressname)ipv4ipv6 anchor_ipv4 anchor_ipv6Nr anchorrDsubnetsznic '%s' configuration: %szadded dns servers: %s nameserver)rErGr)versionconfig)r3get_interfaces_by_macrrrKrNIC_MAPappend)r\ dns_serversrN nic_configs macs_to_nicsnr#rR sysfs_namenic_typeif_namemsgncfgrYnetdef raw_subnetsub_parts r&convert_network_configurationrlcsK:"K133LII... 3?3?Qil "C(((ggenn l * *,;;%  "%%k22 7769--++h 33 j IIH     E  IIc; 3 3 3&   D % %F..J '' 33H8##x6'9'9Y' NN8 $ $ $ $!Y4    .>>>>K );777L[IIJJJK 0 00r0ctj||||}|std|zt j|jS)N)timeout sec_betweenretrieszunable to read metadata at %s)rreadurlokrjsonloadscontentsdecode)urlrprqrrresponses r& read_metadatar{sh! W+wH ;;==B:S@AAA :h'..00 1 11r0ctjd}|dkrdStjd}|rtd|n+d}t|t |d|fS)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_idrgs r& read_sysinfors #$9::Kn$$}"#9::J   F      A S3 * r0)N)rmrmrn)rur cloudinitrrloggingrr3rrrr^ getLogger__name__rr'rr>rlr{rr*r0r&rs   $$$$$$%%%%%%,,,,,,,,,, / /g!!,,,,^LLLNNNN.k1k1k1\2222r0