File: //snap/core18/2956/usr/lib/python3/dist-packages/cloudinit/net/__pycache__/ephemeral.cpython-36.pyc
3
�Ad�9 � @ s� d Z ddlZddlZddlmZmZmZmZ ddlj Z ddl
mZ ddlm
Z
mZmZ eje�ZG dd� d�ZG dd � d �ZG d
d� d�ZG dd
� d
�ZdS )z.Module for ephemeral network context managers
� N)�Any�Dict�List�Optional)�subp)�NoDHCPLeaseError�maybe_perform_dhcp_discovery�parse_static_routesc @ s\ e Zd ZdZdeeeef d�dd�Zdd� Z dd � Z
d
d� Zdd
� Zdd� Z
dd� ZdS )�EphemeralIPv4Networka� Context manager which sets up temporary static network configuration.
No operations are performed if the provided interface already has the
specified configuration.
This can be verified with the connectivity_url_data.
If unconnected, bring up the interface with valid ip, prefix and broadcast.
If router is provided setup a default route for that interface. Upon
context exit, clean up the interface leaving no configuration behind.
N)�connectivity_url_datac C s� t ||||g�s$tdj||||���ytj|�| _W n2 tk
rf } ztdj|��|�W Y dd}~X nX || _|| _|| _|| _ || _
|| _g | _dS )aX Setup context manager and validate call signature.
@param interface: Name of the network interface to bring up.
@param ip: IP address to assign to the interface.
@param prefix_or_mask: Either netmask of the format X.X.X.X or an int
prefix.
@param broadcast: Broadcast address for the IPv4 network.
@param router: Optionally the default gateway IP.
@param connectivity_url_data: Optionally, a URL to verify if a usable
connection already exists.
@param static_routes: Optionally a list of static routes from DHCP
z5Cannot init network on {0} with {1}/{2} and bcast {3}z4Cannot setup network, invalid prefix or netmask: {0}N)
�all�
ValueError�format�netZipv4_mask_to_net_prefix�prefixr � interface�ip� broadcast�router�
static_routes�cleanup_cmds) �selfr r �prefix_or_maskr r r r �e� r �9/usr/lib/python3/dist-packages/cloudinit/net/ephemeral.py�__init__ s$ zEphemeralIPv4Network.__init__c C sR | j r(tj| j �r(tjd| j d � dS | j� | jr@| j� n| jrN| j � dS )z>Perform ephemeral network setup if interface is not connected.z=Skip ephemeral network setup, instance has connectivity to %sZurlN)
r r �has_url_connectivity�LOG�debug�_bringup_devicer �_bringup_static_routesr �_bringup_router)r r r r � __enter__L s
zEphemeralIPv4Network.__enter__c C s"