HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/cloudinit/sources/helpers/__pycache__/digitalocean.cpython-310.pyc
o

�Adr�@s�ddlZddlZddlmZddlmZddlmZddlmZm	Z	m
Z
ddd�Ze�e
�Zdd	d
�Zdd�Zdd
d�Zdd�Zddd�Zdd�ZdS)�N)�dmi)�log)�net)�subp�
url_helper�util�eth0�eth1)�public�privatec	Cs�|st|�}t�d|�|std��d�t�dd�t�dd��}dd	d
|d|g}ddd
d|dg}t�d�s9td��zt�|�t�d||�t�|�t�d|�W|St	yct
�td||��w)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��ip�addr�add�dev�link�set�upz4No '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_nic�LOG�debug�RuntimeError�format�random�randintr�which�	Exceptionr�logexc)�distro�nicr�ip_addr_cmd�ip_link_cmd�r$�H/usr/lib/python3/dist-packages/cloudinit/sources/helpers/digitalocean.py�assign_ipv4_link_locals>��
�

���r&cs.�fdd�t��D�}|sdSt|dd�d�S)Ncsg|]
}�j�|�r|�qSr$)�
networking�is_physical)�.0�f�r r$r%�
<listcomp>Bs
��z&get_link_local_nic.<locals>.<listcomp>cSst�|d�S)N�ifindex)�cloudnet�read_sys_net_int)�dr$r$r%�<lambda>Isz$get_link_local_nic.<locals>.<lambda>)�key)r.�get_devicelist�min)r �nicsr$r+r%rAs
�rc
Cs~|s	t�d�dSt�d�dddd|g}zt�|�t�d|�WdSty>}zt�td	||�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 addressrr�flushrzremoved ip4LL addresses from %sz)failed to remove ip4LL address from '%s'.)rrrrrr)r!r"�er$r$r%�del_ipv4_link_localLs�

��r8cCsRdd�}g}t��}t�d|�|D]�}||d}t�d|�|�d�}||vr1td||f��|�|�}|�dd	�}	t�|	|�}
|
|krPt�d
|	|||
�n	d}t�|||�d||
d
�}g}
dD]}|�|d�}|snqc||�}|	dkszd|vr}|d=|
�|�qc|
|d<|�|�t�d|
|�q|r�t�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'}
        ]
     }
    cSsZdd|�d�|�d�d�}d|�d�vr$d�|�d�|�d��|d	<|S|�d
�|d
<|S)N�static�auto�
ip_address�gateway)�type�control�addressr<�:z{0}/{1}�cidrr?�netmask)�getr)�pcfg�subpartr$r$r%�_get_subnet_part�s���z7convert_network_configuration.<locals>._get_subnet_partznic mapping: %srzconsidering %s�maczVDid 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.�physical)r=�mac_address�name)�ipv4�ipv6�anchor_ipv4�anchor_ipv6Nr
�anchorr<�subnetsznic '%s' configuration: %szadded dns servers: %s�
nameserver)r=r?r)�version�config)r.�get_interfaces_by_macrrrCr�NIC_MAP�append)rT�dns_serversrF�nic_configs�macs_to_nics�nr!rJ�
sysfs_name�nic_type�if_name�msg�ncfgrQ�netdef�
raw_subnet�sub_partr$r$r%�convert_network_configurationcs`
��
�	��

rd��cCs6tj||||d�}|��std|��t�|j���S)N)�timeout�sec_between�retrieszunable to read metadata at %s)r�readurl�okr�json�loads�contents�decode)�urlrgrhri�responser$r$r%�
read_metadata�s�rrcCsNt�d�}|dkrdSt�d�}|rt�d|�d|fSd}t�|�t|��)Nzsystem-manufacturer�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)r�
read_dmi_datarr�criticalr)�vendor_name�
droplet_idr_r$r$r%�read_sysinfo�s

���
rx)N)rererf)rlr�	cloudinitrr�loggingrr.rrrrV�	getLogger�__name__rr&rr8rdrrrxr$r$r$r%�<module>s


/

n