Your IP : 216.73.217.13


Current Path : /lib/python3/dist-packages/cloudinit/sources/helpers/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/sources/helpers/__pycache__/digitalocean.cpython-38.pyc

U

�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�utilZeth0Zeth1)�publicZprivatec	Cs�|st|�}t�d|�|s$td��d�t�dd�t�dd��}dd	d
|d|g}ddd
d|dg}t�d�srtd��z2t�|�t�d||�t�|�t�d|�Wn&t	k
r�t
�td||��YnX|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��ip�addr�add�dev�link�setZupz4No '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�randomZrandintrZwhich�	Exceptionr�logexc)�distro�nicr
�ip_addr_cmdZip_link_cmd�r�H/usr/lib/python3/dist-packages/cloudinit/sources/helpers/digitalocean.py�assign_ipv4_link_locals>�

�
�

�rcs.�fdd�t��D�}|sdSt|dd�d�S)Ncsg|]}�j�|�r|�qSr)Z
networkingZis_physical)�.0�f�rrr�
<listcomp>Bs�z&get_link_local_nic.<locals>.<listcomp>cSst�|d�S)NZifindex)�cloudnetZread_sys_net_int)�drrr�<lambda>I�z$get_link_local_nic.<locals>.<lambda>)�key)r$Zget_devicelist�min)rZnicsrr"rrAs
�rc
Cs||st�d�dSt�d�dddd|g}zt�|�t�d|�Wn2tk
rv}zt�td	||�W5d}~XYnXdS)
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 addressrr
�flushrzremoved ip4LL addresses from %sz)failed to remove ip4LL address from '%s'.)rrrrrr)rr�errr�del_ipv4_link_localLs�

r,cCsVdd�}g}t��}t�d|�|D�]}||d}t�d|�|�d�}||krdtd||f��|�|�}|�dd	�}	t�|	|�}
|
|kr�t�d
|	|||
�nd}t�|||�d||
d
�}g}
dD]>}|�|d�}|s�q�||�}|	dks�d|kr�|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�krFd�|�d�|�d��|d	<n|�d
�|d
<|S)NZstatic�autoZ
ip_address�gateway)�typeZcontrol�addressr.�:z{0}/{1}Zcidrr0Znetmask)�getr)ZpcfgZsubpartrrr�_get_subnet_part�s��
z7convert_network_configuration.<locals>._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)Zipv4Zipv6Zanchor_ipv4Zanchor_ipv6NrZanchorr.�subnetsznic '%s' configuration: %szadded dns servers: %sZ
nameserver)r/r0r	)�version�config)r$Zget_interfaces_by_macrrr2r�NIC_MAP�append)r9Zdns_serversr3Znic_configsZmacs_to_nics�nrr5Z
sysfs_nameZnic_typeZif_name�msgZncfgr7ZnetdefZ
raw_subnetZsub_partrrr�convert_network_configurationcs`

��
�	��
r>��cCs6tj||||d�}|��s&td|��t�|j���S)N)�timeout�sec_between�retrieszunable to read metadata at %s)rZreadurl�okr�json�loads�contents�decode)ZurlrArBrCZresponserrr�
read_metadata�s�rIcCsPt�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_datarrZcriticalr)Zvendor_nameZ
droplet_idr=rrr�read_sysinfo�s

��
rJ)N)N)r?r?r@)rErZ	cloudinitrrZloggingrr$rrrr:Z	getLogger�__name__rrrr,r>rIrJrrrr�<module>s


/
n