404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@52.14.120.226: ~ $
3

\�mevK�@s�ddlZddlZddlZddlZddlZddlZddlmZmZddl	m
Z
mZmZm
Z
ddlmZmZmZmZmZddlmZmZdZeje�Zdd�Zdeed	�d
d�Zdd
�Zddd�ZGdd�dej �Z ddd�Z!dS)�N)�Optional�cast)�features�safeyaml�subp�util)�IPV6_DYNAMIC_TYPES�
SYS_CLASS_NET�get_devicelist�renderer�subnet_is_ipv6)�NET_CONFIG_TO_V2�NetworkStates4# This is the initial network config.
# It can be overwritten by cloud-init or console-conf.
network:
    version: 2
    ethernets:
        all-en:
            match:
                name: "en*"
            dhcp4: true
        all-eth:
            match:
                name: "eth*"
            dhcp4: true
cst�fdd�|j�D��S)Nc3s$|]\}}|j��r||fVqdS)N)�
startswith)�.0�key�value)�match��/usr/lib/python3.6/netplan.py�	<genexpr>*sz,_get_params_dict_by_match.<locals>.<genexpr>)�dict�items)�configrr)rr�_get_params_dict_by_match(s
r)r�entrycCsld(dd�}|dkrg}g}g}g}g}|jdg�}	|	dkr>g}	�x|	D�]}
|
jd�}|jd�r�|dkrp|d7}|j|d	i�qF|tkr�|jd
d	i�qF|d)krFd
|
jd�}d|
kr�|d|
jd�7}|
jd��rl|
jd�dd�}
yDtj|
d�}tj|dd�}||k�r&tjd|
d|�d	|
d<Wn8t	k
�r`}ztj
d|
d||�WYdd}~XnX|j|
�d|
k�r�|||
jdg��7}d|
k�r�|||
jdg��7}d|
k�r�d}t|
��r�d|k�r�d}|j||
jd�i�xh|
jdg�D]X}d|jd�|jd�f}|jd�|d�}
d |k�r<|
jd |jd d!�i�|j|
��q�W|j|�qFWd|k�r�|jd�}|�r�|d|k�r�tj
d"||d|�n|d|d<t
|�d#k�r�|jd$|i�t
|�d#k�r�|jd|i�t
|�d#k�rd$|i}|jd%|i�t
|�d#k�r6|jd%i�}|jd&|i�|jd%|i�d'|k�rh|d'dk	�rh|jd'tj|jd'��i�dS)*a�This method parse a cloudinit.net.network_state dictionary (config) and
       maps netstate keys/values into a dictionary (entry) to represent
       netplan yaml. (config v1 -> netplan)

    An example config dictionary might look like:

    {'mac_address': '52:54:00:12:34:00',
     'name': 'interface0',
     'subnets': [
        {'address': '192.168.1.2/24',
         'mtu': 1501,
         'type': 'static'},
        {'address': '2001:4800:78ff:1b:be76:4eff:fe06:1000",
         'mtu': 1480,
         'netmask': 64,
         'type': 'static'}],
      'type: physical',
      'accept-ra': 'true'
    }

    An entry dictionary looks like:

    {'set-name': 'interface0',
     'match': {'macaddress': '52:54:00:12:34:00'},
     'mtu': 1501}

    After modification returns

    {'set-name': 'interface0',
     'match': {'macaddress': '52:54:00:12:34:00'},
     'mtu': 1501,
     'address': ['192.168.1.2/24', '2001:4800:78ff:1b:be76:4eff:fe06:1000"],
     'ipv6-mtu': 1480}

    � cSs2|st|t�r|S||kr(|j|�S|gSdS)zT
        Helper to convert strings to list of strings, handle single string
        N)�
isinstance�str�split)�obj�tokenrrr�_listifyUs

z$_extract_addresses.<locals>._listifyN�subnets�typeZdhcp�4TZdhcp6�static�static6z%sZaddress�prefixz/%dZgateway�default)ZviaZtoF)�strictzAGateway %s is not contained within subnet %s, adding on-link flagzon-linkzDFailed to check whether gateway %s is contained within subnet %s: %s�dns_nameserversZ
dns_searchZmtuzipv6-mtu�routesz%s/%s�networkZmetric�dzZNetwork config: ignoring %s device-level mtu:%s because ipv4 subnet-level mtu:%s provided.r�	addresses�nameservers�searchz	accept-ra)r)r&r')�getr�updater�	ipaddressZ
ip_addressZ
ip_network�LOG�debug�
ValueErrorZwarning�appendr�lenrZis_true)rr�ifnamerr"r/r,r0�
searchdomainsr#ZsubnetZsn_typeZaddrZ	new_routeZsubnet_gatewayZsubnet_network�eZmtukeyZrouteZto_netZ	entry_mtu�nsrrr�_extract_addresses0s�%











r>cs8t�fdd�|j�D��}t|�dkr4|jd|i�dS)Ncs$g|]\}}|jdd��kr|�qS)zbond-masterN)r2)r�name�cfg)�bond_masterrr�
<listcomp>�sz0_extract_bond_slaves_by_name.<locals>.<listcomp>r�
interfaces)�sortedrr9r3)rCrrAZbond_slave_namesr)rAr�_extract_bond_slaves_by_name�s

rEcs�tj�d�}tjj|�sdStj|dd�}|tkr6dS�fdd�dD�}d	d�|D�}tj	d
||�x|g|D]}tj
|�qpWdS)Nz etc/netplan/00-snapd-config.yamlF)�decodecsg|]}tj�|��qSr)r�target_path)r�f)�targetrrrB�sz"_clean_default.<locals>.<listcomp>�-run/systemd/network/10-netplan-all-en.network�.run/systemd/network/10-netplan-all-eth.network�#run/systemd/generator/netplan.stampcSsg|]}tjj|�r|�qSr)�os�path�isfile)rrHrrrrB�sz9removing known config '%s' and derived existing files: %s)rJrKrL)rrGrMrNrOrZ	load_file�KNOWN_SNAPD_CONFIGr5r6�unlink)rIZtpath�contentZderivedZexistingrHr)rIr�_clean_default�s"
rSc@szeZdZdZddgZddgZddd�Zedd	��Zde	e
edd
�dd�Zde
e
d�dd�Zddd�Ze	ed�dd�ZdS)�RendererzBRenders network information in a /etc/netplan/network.yaml format.�netplanZgenerate�infoNcCsR|si}|jdd�|_|jdd�|_|jdd�|_|jdd�|_|jdd�|_dS)	N�netplan_pathzetc/netplan/50-cloud-init.yaml�netplan_headerZpostcmdsF�
clean_defaultTr)r2rWrX�	_postcmdsrY�	_features)�selfrrrr�__init__�s
zRenderer.__init__cCs�|jdkr�y0tj|jdd�\}}tj|�}|dd|_WnFtjk
rPYn2ttfk
r�}ztj	d|�WYdd}~XnX|jS)NT)�capturez
netplan.iorz-Failed to list features from netplan info: %s)
r[r�NETPLAN_INFOrZ	load_yaml�ProcessExecutionError�	TypeError�KeyErrorr5r6)r\Z	info_blobZ_errrVr<rrrr�s

zRenderer.features)�
network_state�	templates�returnc
Cs*tjjtj|�|j�}tjtjj|��|j	|�}|j
r>|j
nd}|jd�sT|d7}||}d}tjj|�r�tj
tj|j���}t|d��}	tj
|	�}
WdQRX||
kr�d}tjr�dnd}|r�tjj|�r�tj|�}||@|kr�|}tj|||d�|j�rt|d	�|j|j|d
�|j|jd�dS)N��
F�rbTi�i�)�mode)rI)�run�same_content)rj)rMrN�joinrrGrWrZ
ensure_dir�dirname�_render_contentrX�endswith�existsZhash_buffer�io�BytesIO�encode�openrZNETPLAN_CONFIG_ROOT_READ_ONLYZget_permissionsZ
write_filerYrS�_netplan_generaterZ�_net_setup_link)
r\rcrdrIZfpnplanrR�headerrkZhashed_contentrHZhashed_original_contentriZcurrent_moderrr�render_network_states0	



zRenderer.render_network_stateF)rjrkcCs8|stjd�dS|r$tjd�dStj|jdd�dS)Nz!netplan generate postcmd disabledzEskipping call to `netplan generate`. reason: identical netplan configT)r^)r5r6r�NETPLAN_GENERATE)r\rjrkrrrru8s
zRenderer._netplan_generatecCs�|stjd�dSdddg}t}x�td�D]l}y>x6t�D],}tjjt|�r8t	j	|t|gdd�q8WPWq*t	j
k
r�}z
|}WYdd}~Xq*Xq*Wtd	�|�dS)
z�To ensure device link properties are applied, we poke
        udev to re-evaluate networkd .link files and call
        the setup_link udev builtin command
        z'netplan net_setup_link postcmd disabledNZudevadmztest-builtinZnet_setup_link�T)r^zQ'udevadm test-builtin net_setup_link' unable to run successfully for all devices.)r5r6�	Exception�ranger
rMrN�islinkr	rr`�RuntimeError)r\rjZ	setup_lnkZlast_exception�_Zifacer<rrrrvDs"

zRenderer._net_setup_link)rcrec+Csd|jdkr*tjd�tjd|jiddd�Si}i}i}i}i}g}|jjdg�}|j}	|j	}
�x4|j
�D�]&}|jd�}ttdd	�|j
���}
|
jd
�}|dk�r||
jdd�d
�}|ddkr�|
jdd�}|dk	r�d|j�i|d<n|d=|d=t|
|||j�|j||i�qh|dk�ri}i}tttjd��}x^d/D]V}t|
|�}xD|j
�D]8\}}|j|jdd��}|dk�rz�qR|j||i��qRW�q:Wt|�dk�r�|jd|i�|
jd��r�|
dj�|d<|
jd�}|dk�r�t|||�t|
|||j�|j||i�qh|dk�r2|
jd�}ttj|��}d|i}d}t|
|�}i}tttjd��} x�|j
�D]t\}}| j|�}|dk�r��qb|j||i�|d0k�rbi}!x&|D]}"|"j�\}#}$t|$�|!|#<�q�W|j||!i��qbWt|�dk�r�|jd|i�|
jd��r|
dj�|d<t|
|||j�|j||i�qh|dkrh|
jd �|
jd!�d"�}%|
jdd�}|dk	�rr|j�|%d<t|
|%||j�|j||%i�qhW|	�s�|
�r|	|
d#�}&xV|||||gD]D}'x<|'j
�D]0\}(})d$|)k�s�d%|)k�r�q�|)jd$|&i��q�W�q�Wd&d'�}*|jd(�||*d)|�7}||*d*|�7}||*d+|�7}||*d,|�7}||*d-|�7}d.j|�S)1N�zV2 to V2 passthroughr-F)�explicit_start�explicit_endrCr?cSs|ddk	S)N�r)�itrrr�<lambda>}sz*Renderer._render_content.<locals>.<lambda>r$Zphysicalr)zset-namerZmac_addressZ
macaddresszset-name�bond�bond_�bond-r�-rZ
parameterszbond-slavesZnone�bridge�bridge_portsZbridge_�	path-cost�
port-priority�vlanZvlan_idzvlan-raw-device)�id�link)r/r1r0r/cSs0|r,tj||idddd�}tj|d�}|gSgS)NFT)r�r�Znoaliasr�z    )r�dumps�textwrap�indent)r?�section�dumpZtxtrrr�_render_section�sz1Renderer._render_content.<locals>._render_sectionznetwork:
    version: 2
�	ethernets�wifis�bonds�bridges�vlansrf)r�r�)r�r�)�versionr5r6rr�rZ_network_stater2r+Zdns_searchdomainsZiter_interfacesr�filterr�lowerr>rr3rr
r�replacer9rErD�copyr�intr8rl)+r\rcr�r�r�r�r�rRrCr0r;rr:ZifcfgZif_typeZethZmacaddrr�Zbond_configZv2_bond_maprZbond_paramsZparamrZnewnameZslave_interfacesr�Zportsr�Zmatch_prefixZparamsZ	br_configZ
v2_bridge_mapZnewvalue�valZportZportvalr�Znscfgr��_namer@r�rrrrncs�




















zRenderer._render_content)N)NN)FF)F)�__name__�
__module__�__qualname__�__doc__ryr_r]�propertyrrrrrx�boolrurvrrnrrrrrT�s

'
rTcCs4dg}ddg}x |D]}tj|||d�sdSqWdS)NrUz	/usr/sbinz/sbin)r1rIFT)rZwhich)rIZexpectedr1�prrr�	availables
r�)N)N)N)"r�rqr4ZloggingrMr�ZtypingrrZ	cloudinitrrrrZ
cloudinit.netrr	r
rrZcloudinit.net.network_stater
rrPZ	getLoggerr�r5rrr>rErSrTr�rrrr�<module>s(



Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 33.43 KB 0644
__init__.cpython-36.pyc File 33.43 KB 0644
activators.cpython-36.opt-1.pyc File 9.52 KB 0644
activators.cpython-36.pyc File 9.52 KB 0644
bsd.cpython-36.opt-1.pyc File 5.74 KB 0644
bsd.cpython-36.pyc File 5.74 KB 0644
cmdline.cpython-36.opt-1.pyc File 7.2 KB 0644
cmdline.cpython-36.pyc File 7.2 KB 0644
dhcp.cpython-36.opt-1.pyc File 15.98 KB 0644
dhcp.cpython-36.pyc File 15.98 KB 0644
eni.cpython-36.opt-1.pyc File 12.89 KB 0644
eni.cpython-36.pyc File 12.89 KB 0644
ephemeral.cpython-36.opt-1.pyc File 10.51 KB 0644
ephemeral.cpython-36.pyc File 10.51 KB 0644
freebsd.cpython-36.opt-1.pyc File 2.54 KB 0644
freebsd.cpython-36.pyc File 2.54 KB 0644
netbsd.cpython-36.opt-1.pyc File 1.69 KB 0644
netbsd.cpython-36.pyc File 1.69 KB 0644
netplan.cpython-36.opt-1.pyc File 11.91 KB 0644
netplan.cpython-36.pyc File 11.91 KB 0644
network_manager.cpython-36.opt-1.pyc File 12.83 KB 0644
network_manager.cpython-36.pyc File 12.83 KB 0644
network_state.cpython-36.opt-1.pyc File 27.57 KB 0644
network_state.cpython-36.pyc File 27.57 KB 0644
networkd.cpython-36.opt-1.pyc File 8.21 KB 0644
networkd.cpython-36.pyc File 8.21 KB 0644
openbsd.cpython-36.opt-1.pyc File 2.18 KB 0644
openbsd.cpython-36.pyc File 2.18 KB 0644
renderer.cpython-36.opt-1.pyc File 1.82 KB 0644
renderer.cpython-36.pyc File 1.82 KB 0644
renderers.cpython-36.opt-1.pyc File 1.53 KB 0644
renderers.cpython-36.pyc File 1.53 KB 0644
sysconfig.cpython-36.opt-1.pyc File 23.07 KB 0644
sysconfig.cpython-36.pyc File 23.07 KB 0644
udev.cpython-36.opt-1.pyc File 1.22 KB 0644
udev.cpython-36.pyc File 1.31 KB 0644