/usr/lib/python3/dist-packages/cloudinit/net/__pycache__
Edit: /usr/lib/python3/dist-packages/cloudinit/net/__pycache__/ephemeral.cpython-310.pyc (16568B)
o
th,V @ s d Z ddlZddlZddlmZ ddlmZmZmZm Z m
Z
mZmZ ddl
mZ ddlmZ ddlmZmZ ddlmZ ddlmZmZ eeZG dd d ZG d
d dZG dd
d
ZG dd dZde ee ef dee fddZ!dS )z-Module for ephemeral network context managers N)partial)AnyCallableDictListLiteralOptionalTuple)NoDHCPLeaseErrormaybe_perform_dhcp_discovery)ProcessExecutionError)UrlErrorwait_for_urlc @ sL e Zd ZdZ ddefddZdd Zdd Zd
d Zdd
Z dd Z
dS )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_urls_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.
Ninterface_addrs_before_dhcpc
C s t ||||gstd||||zt|| _W n ty. } ztd| | d} ~ ww || _|| _|| _|| _ || _
g | _|| _| j d| j | _
|| ji | _dS )a 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 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
ValueErrorformatnetipv4_mask_to_net_prefixprefix interfaceip broadcastrouter
static_routescleanup_cmdsdistrocidrgetr )
selfr r r prefix_or_maskr r r r e r$ 9/usr/lib/python3/dist-packages/cloudinit/net/ephemeral.py__init__ s8
zEphemeralIPv4Network.__init__c
C s z?z| W n! ty( } zdt|jvrdt|jvr W Y d}~nd}~ww | jr3| W dS | jr=| W dS W dS tyN | ddd w )zSet up ephemeral network if interface is not connected.
This context manager handles the lifecycle of the network interface,
addresses, routes, etc
zFile existszAddress already assignedN) _bringup_devicer strstderrr _bringup_static_routesr _bringup_router__exit__)r! r# r$ r$ r% __enter__M s( zEphemeralIPv4Network.__enter__c C s | j D ]}| qdS )zTeardown anything we set up.N)r )r! excp_type
excp_valueexcp_tracebackcmdr$ r$ r% r, q s
zEphemeralIPv4Network.__exit__c C s: t d| j| j| j t | ji }|d}| jd}| j dd |di D v }| j dd | jdi D v }|rHt d| j| j n| j
j| j| j| j |r^t d| j n
| j
jj
| jd d
|rrt d| j n| jt| j
jj| jd d
|rt d| j d
S | jt| j
jj| j| j d
S )af Perform the ip commands to fully set up the device.
Dhcp clients behave differently in how they leave link state and ip
address assignment.
Attempt assigning address and setting up link if needed to be done.
Set cleanup_cmds to return the interface state to how it was prior
to execution of the dhcp client.
z:Attempting setup of ephemeral network on %s with %s brd %supc S g | ]}| d qS r r .0r r$ r$ r%