
    x[h                         S SK r S SKrS SKrS SKJr  S SKJr  S SKJrJr  SSS.r	\R                  " \5      rSS jrS	 rSS
 jrS rSS jrS rg)    N)dmi)net)
url_helperutileth0eth1)publicprivatec                    U(       d!  [        U 5      n[        R                  SU5        U(       d  [        S5      eSR	                  [
        R                  " SS5      [
        R                  " SS5      5      n U R                  R                  X5        U R                  R                  U5        [        R                  SX5        U$ ! [         a    [        R                  " [        S	UU5        e f = f)
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.z169.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randomrandintnet_opsadd_addrlink_up	Exceptionr   logexc)distronicaddrs      H/usr/lib/python3/dist-packages/cloudinit/sources/helpers/digitalocean.pyassign_ipv4_link_localr      s      (		@#F8
 	

  &&q#q# 6D*s#		:CF J  1	
 	s   8AC )C/c                     [         R                  " 5        Vs/ s H'  nU R                  R                  U5      (       d  M%  UPM)     nnU(       d  g [	        US S9$ s  snf )Nc                 0    [         R                  " U S5      $ )Nifindex)cloudnetread_sys_net_int)ds    r   <lambda>$get_link_local_nic.<locals>.<lambda>@   s    8#<#<Q	#J    )key)r#   get_devicelist
networkingis_physicalmin)r   fnicss      r   r   r   8   s\     ((**A((+ 	
* 	 
 tJKKs   $A Ac                 2   U(       d  [         R                  S5        g[         R                  S5         U R                  R                  U5        [         R                  SU5        g! [         a&  n[
        R                  " [         SX5         SnAgSnAff = f)zoRemove 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 cleanupNzcleaning up ipv4LL addresszremoved ip4LL addresses from %sz)failed to remove ip4LL address from '%s'.)r   r   r   
flush_addrr   r   r   )r   r   es      r   del_ipv4_link_localr3   C   sw     		$	
 	II*+N!!#&		3S9 NCDcMMNs   1A& &
B0BBc                 L   S n/ n[         R                  " 5       n[        R                  SU5        U  GH8  nX   S   n[        R                  SU5        UR	                  S5      nXt;  a  [        SU< SU< 35      eUR	                  U5      nUR	                  SS	5      n	[        R	                  X5      n
X:w  a  [        R                  S
U	UUU
5        OSn[        R                  XU5        SUU
S.n/ nS HF  nUR	                  US5      nU(       d  M  U" U5      nU	S:w  d  SU;   a  US	 UR                  U5        MH     XS'   UR                  U5        [        R                  SX5        GM;     U(       a*  [        R                  SU5        UR                  SUS.5        SU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'}
    ]
 }
c                    SSU R                  S5      U R                  S5      S.nSU R                  S5      ;   a5  SR                  U R                  S5      U R                  S5      5      US	'   U$ U R                  S
5      US
'   U$ )Nstaticauto
ip_addressgateway)typecontroladdressr9   :z{0}/{1}cidrr<   netmask)getr   )pcfgsubparts     r   _get_subnet_part7convert_network_configuration.<locals>._get_subnet_partu   s    xx-xx	*	
 $((<((!*!1!1&(8"GI  "&)!4GIr(   znic mapping: %sr   zconsidering %smacz3Did not find network interface on system with mac 'z'. Cannot apply configuration: r:   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.physical)r:   mac_addressname)ipv4ipv6anchor_ipv4anchor_ipv6Nr	   anchorr9   subnetsznic '%s' configuration: %szadded dns servers: %s
nameserver)r:   r<   r   )versionconfig)r#   get_interfaces_by_macr   r   r@   r   NIC_MAPappend)rR   dns_serversrC   nic_configsmacs_to_nicsnr   rH   
sysfs_namenic_typeif_namemsgncfgrO   netdef
raw_subnetsub_parts                    r   convert_network_configurationrb   X   s   :" K113LII.il		"C(ggen* %  "%%k2
7769-++h3 IIHE  IIc
3 &
 DF.J'
3H8#x6'9Y'NN8$ E "Y4 		.>g j 		);7L[IJK00r(   c                     [         R                  " XX#S9nUR                  5       (       d  [        SU -  5      e[        R
                  " UR                  R                  5       5      $ )N)timeoutsec_betweenretrieszunable to read metadata at %s)r   readurlokr   jsonloadscontentsdecode)urlrd   re   rf   responses        r   read_metadataro      sS    !!+H ;;==:S@AA::h''..011r(   c                      [         R                  " S5      n U S:w  a  g[         R                  " S5      nU(       a  [        R                  SU5        SU4$ Sn[        R	                  U5        [        U5      e)Nzsystem-manufacturerDigitalOcean)FNzsystem-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_datar   r   criticalr   )vendor_name
droplet_idr]   s      r   read_sysinforv      sw    
 ##$9:Kn$""#9:J		F	
 *A 	 	S3r(   )N)   rw      )ri   loggingr   	cloudinitr   r   r#   r   r   rT   	getLogger__name__r   r   r   r3   rb   ro   rv    r(   r   <module>r~      sV   
     % &
/!#LLN*k1\2r(   