Ë
    x[hê  ã                   óv   — d dl Z d dlZd dlmZ d dlmZ d dlmZ  ej                  e«      Z	d„ Z
d„ Zd	d„Zd„ Zy)
é    N)Údmi)Únet)Ú
url_helperc           
      ó  — d„ }g }t        j                  «       }t        j                  d|«       | j	                  d«      D ]å  }t        j                  d|«       |j	                  d«      }||vrt        d|›d|›�«      ‚|j	                  d«      }|j	                  |«      }t        j                  d	||||j	                  d
«      «       d||dœ}g }	|j	                  d«      D ]+  }
 ||
| j	                  d«      «      }|	j                  |«       Œ- |	|d<   |j                  |«       Œç | j	                  d«      rHt        j                  d| j	                  d«      «       |j                  d| j	                  d«      dœ«       d|dœS )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                 óè  — | j                  d«      rd}| j                  d«      dk(  rd}d|iS d}| j                  d«      dk(  rd}|d| j                  d	«      d
œ}| j                  d«      r| j                  d«      |d<   d| j                  d«      v r&| j                  d«      j                  d«      d   |d<   || j                  d«      k7  r%| j                  d«      r| j                  d«      |d<   |S )NÚdhcpÚfamilyÚIPv6zipv6_dhcpv6-statelessÚtypeÚstaticÚstatic6ÚautoÚaddress)r   Úcontrolr   Úgatewayú/Únetworké   ÚnetmaskÚdnsÚdns_nameservers)ÚgetÚsplit)Úip_addrr   Ú	dhcp_typeÚstatic_typeÚsubparts        úC/usr/lib/python3/dist-packages/cloudinit/sources/helpers/upcloud.pyÚ_get_subnet_configz8convert_to_network_config_v1.<locals>._get_subnet_configr   sô   € Ø�;‰;�vÔØˆIØ�{‰{˜8Ó$¨Ò.ð 4�	Ø˜IÐ&Ð&àˆØ�;‰;�xÓ  FÒ*Ø#ˆKàØØ—{‘{ 9Ó-ñ
ˆð �;‰;�yÔ!Ø!(§¡¨YÓ!7ˆG�IÑà�'—+‘+˜iÓ(Ñ(Ø!(§¡¨YÓ!7×!=Ñ!=¸cÓ!BÀ1Ñ!EˆG�IÑà�'—+‘+˜eÓ$Ò$¨¯©°UÔ);Ø)0¯©°UÓ);ˆGÐ%Ñ&àˆó    zNIC mapping: %sÚ
interfaceszConsidering %sÚmacz3Did not find network interface on system with mac 'z'. Cannot apply configuration: r   z4Found %s interface '%s' with address '%s' (index %d)ÚindexÚphysical)r   ÚnameÚmac_addressÚip_addressesr   ÚsubnetszSetting DNS nameservers to %sÚ
nameserver)r   r   r   )ÚversionÚconfig)ÚcloudnetÚget_interfaces_by_macÚLOGÚdebugr   ÚRuntimeErrorÚappend)r+   r   Únic_configsÚmacs_to_interfacesÚ	raw_ifacer&   Ú
iface_typeÚ
sysfs_nameÚ	interfacer(   Ú
ip_addressÚsub_parts               r   Úconvert_to_network_config_v1r:      s‰  € òFð: €KÜ!×7Ñ7Ó9ÐÜ‡I�IÐÐ!3Ô4à—Z‘Z Ó-ò "&ˆ	Ü�	‰	Ð" IÔ.à—m‘m EÓ*ˆØÐ0Ñ0Ýò ¡	ð+óð ð —]‘] 6Ó*ˆ
Ø'×+Ñ+¨KÓ8ˆ
ä�	‰	ØBØØØØ�M‰M˜'Ó"ô	
ð ØØ&ñ
ˆ	ð ˆØ#Ÿ-™-¨Ó7ò 	%ˆJÙ)¨*°f·j±jÀÓ6GÓHˆHØ�N‰N˜8Õ$ð	%ð  'ˆ	�)ÑØ×Ñ˜9Õ%ðE"&ðH ‡z�z�%ÔÜ�	‰	Ð1°6·:±:¸eÓ3DÔEØ×ÑØ!¨f¯j©j¸Ó.?Ñ@ô	
ð  KÑ0Ð0r    c                 ó   — t        | «      S )N)r:   )r+   s    r   Úconvert_network_configr<   À   s   € Ü'¨Ó/Ð/r    c                 óÊ   — t        j                  | |||¬«      }|j                  «       st        d| z  «      ‚t	        j
                  |j                  j                  «       «      S )N)ÚtimeoutÚsec_betweenÚretrieszunable to read metadata at %s)r   ÚreadurlÚokr0   ÚjsonÚloadsÚcontentsÚdecode)Úurlr>   r?   r@   Úresponses        r   Úread_metadatarI   Ä   sU   € Ü×!Ñ!Ø�W¨+¸wô€Hð �;‰;Œ=ÜÐ:¸SÑ@ÓAÐAÜ�:‰:�h×'Ñ'×.Ñ.Ó0Ó1Ð1r    c                  óÞ   — t        j                  d«      } | dk7  ryt        j                  d«      }|rt        j                  d|«       d|fS d}t        j	                  |«       t        |«      ‚)Nzsystem-manufacturerÚUpCloud)FNzsystem-uuidz2system identified via SMBIOS as UpCloud server: %sz¤system 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_uuidÚmsgs      r   Úread_sysinforQ   Í   su   € ô ×#Ñ#Ð$9Ó:€KØ�iÒØä×#Ñ# MÓ2€KÙÜ�	‰	Ø@À+ô	
ð �ÐÐðLð 	ô
 	�‰�SÔÜ˜3ÓÐr    )é   rR   é   )rC   ÚloggingÚ	cloudinitr   r   r,   r   Ú	getLoggerÚ__name__r.   r:   r<   rI   rQ   © r    r   ú<module>rY      s>   ðó
 Û å Ý %Ý  à€g×Ñ˜Ó!€òn1òb0ó2ór    