a '¡Dgÿã@sŽddlZddlZddlZddlmZddlmZddlmZmZdddœZ e  e ¡Z ddd „Z d d „Zdd d „Zdd„Zddd„Zdd„ZdS)éN)Údmi)Únet)Ú url_helperÚutilZeth0Zeth1)ÚpublicZprivatec Cs–|st|ƒ}t d|¡|s$tdƒ‚d t dd¡t dd¡¡}z,|j ||¡|j  |¡t d||¡Wn$t yt   td ||¡‚Yn0|S) zäBring 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}/16éé¨réÿz&brought device '%s' up with address %szRip4LL address assignment of '%s' to '%s' failed. Droplet networking will be broken) Úget_link_local_nicÚLOGÚdebugÚ RuntimeErrorÚformatÚrandomZrandintÚnet_opsZadd_addrZlink_upÚ ExceptionrÚlogexc)ÚdistroÚnicÚaddr©rúJ/usr/lib/python3.9/site-packages/cloudinit/sources/helpers/digitalocean.pyÚassign_ipv4_link_locals. ÿÿ  ûrcs.‡fdd„t ¡Dƒ}|sdSt|dd„dS)Ncsg|]}ˆj |¡r|‘qSr)Z networkingZ is_physical)Ú.0Úf©rrrÚ 9s þz&get_link_local_nic..cSs t |d¡S)NZifindex)ÚcloudnetZread_sys_net_int)ÚdrrrÚ@óz$get_link_local_nic..)Úkey)rZget_devicelistÚmin)rZnicsrrrr 8s  þr c Csr|st d¡dSt d¡z|j |¡t d|¡Wn4tyl}zt td||¡WYd}~n d}~00dS)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'.)r r rZ flush_addrrrr)rrÚerrrÚdel_ipv4_link_localCsÿ  r$cCsVdd„}g}t ¡}t d|¡|D]}||d}t d|¡| d¡}||vrdtd||fƒ‚| |¡}| dd ¡} t | |¡} | |kr¢t d | ||| ¡nd } t | ||¡d || d œ} g} dD]>}| |d¡}|sÞqÈ||ƒ}| dksöd|vrü|d=|  |¡qÈ| | d<| | ¡t d| | ¡q$|rLt d|¡| d|dœ¡d|dœS)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'} ] } cSsXdd| d¡| d¡dœ}d| d¡vrFd | d¡| d¡¡|d <n| d ¡|d <|S) NZstaticÚautoÚ ip_addressÚgateway)ÚtypeZcontrolÚaddressr'ú:z{0}/{1}Zcidrr)Únetmask)Úgetr)ZpcfgZsubpartrrrÚ_get_subnet_partusüÿ z7convert_network_configuration.._get_subnet_partznic mapping: %srzconsidering %sZmaczVDid not find network interface on system with mac '%s'. Cannot apply configuration: %sr(Úunknownz6Found %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.Zphysical)r(Ú mac_addressÚname)Zipv4Zipv6Z anchor_ipv4Z anchor_ipv6NrÚanchorr'Úsubnetsznic '%s' configuration: %szadded dns servers: %sZ nameserver)r(r)r)ÚversionÚconfig)rZget_interfaces_by_macr r r,r ÚNIC_MAPÚappend)r4Z dns_serversr-Z nic_configsZ macs_to_nicsÚnrr/Z sysfs_nameZnic_typeZif_nameÚmsgZncfgr2ZnetdefZ raw_subnetZsub_partrrrÚconvert_network_configurationXs`     þÿ   û ÿý    r9éécCs6tj||||d}| ¡s&td|ƒ‚t |j ¡¡S)N)ÚtimeoutÚ sec_betweenÚretrieszunable to read metadata at %s)rZreadurlÚokr ÚjsonÚloadsÚcontentsÚdecode)Úurlr<r=r>ZresponserrrÚ read_metadataÆs ÿ rEcCsPt d¡}|dkrdSt d¡}|r2t d|¡nd}t |¡t|ƒ‚d|fS)Nzsystem-manufacturerZ DigitalOcean)FNzsystem-serial-numberz8system identified via SMBIOS as DigitalOcean Droplet: %sz¦system 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)rZ read_dmi_datar r Zcriticalr )Z vendor_nameZ droplet_idr8rrrÚ read_sysinfoÏs  þÿ rF)N)N)r:r:r;)r@ZloggingrZ cloudinitrrrrrr5Z getLoggerÚ__name__r rr r$r9rErFrrrrÚs     & n