404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.145.79.236: ~ $
3

\�me��@s�UddlZddlZddlZddlmZmZmZmZddlm	Z	m
Z
ddlmZm
Z
mZmZmZmZmZmZmZer~ddlmZeje�ZdZdddd	giZd
ddd
dddddddddddgZdddddddd d!d"d#d$d%d&d'd(�d)d*d+dd,d-dd.d/d0dd1�d2�Zeeeeeffedd3�d4d5�Z d6d7�Z!Gd8d9�d9e"�Z#d:d;�Z$Gd<d=�d=�Z%Gd>d?�d?�Z&d@dA�Z'ffdBdC�Z(dDdE�Z)dFdG�Z*dLee+e%dI�dJdK�Z,dS)M�N)�
TYPE_CHECKING�Any�Dict�Optional)�safeyaml�util)	�find_interface_name_from_mac�get_interfaces_by_mac�ipv4_mask_to_net_prefix�ipv6_mask_to_net_prefix�
is_ip_network�is_ipv4_network�is_ipv6_address�is_ipv6_network�net_prefix_to_ipv4_mask)�Renderer��version�config�
network_state�	addresses�dhcp4zdhcp4-overrides�dhcp6zdhcp6-overrides�gateway4�gateway6�
interfaces�match�mtu�nameservers�rendererzset-name�	wakeonlanz	accept-raz	ad-selectzarp-intervalz
arp-ip-targetzarp-validatez
down-delayzfail-over-mac-policyz	lacp-ratezmii-monitor-intervalz	min-links�modezgratuitous-arpZprimaryzprimary-reselect-policyzup-delayztransmit-hash-policy)zbond-ad-selectzbond-arp-intervalzbond-arp-ip-targetzbond-arp-validatezbond-downdelayzbond-fail-over-maczbond-lacp-ratezbond-miimonzbond-min-linksz	bond-modezbond-num-grat-arpzbond-primaryzbond-primary-reselectzbond-updelayzbond-xmit-hash-policyzageing-timeZpriorityz
forward-delayz
hello-timezmax-agez	path-costz
port-priority�stp)Z
bridge_ageingZbridge_bridgeprioZ	bridge_fdZbridge_gcintZbridge_helloZ
bridge_maxageZbridge_maxwaitZbridge_pathcostZbridge_portprio�
bridge_stpZbridge_waitport)�bond�bridge)�dikt�returncCs$d|ksd|kr tjdddd�dS)z8Warn about deprecations of v2 properties for all devicesrrz$The use of `gateway4` and `gateway6`z22.4zhFor more info check out: https://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v2.html)Z
deprecatedZdeprecated_versionZ
extra_messageN)rZ	deprecate)r&�r(�#/usr/lib/python3.6/network_state.py�warn_deprecated_all_devicesVs
r*cCs$t|�}x|D]}|j|�qW|S)N)�set�discard)Zexpected�actualZmissing�keyr(r(r)�	diff_keysas
r/c@seZdZdS)�InvalidCommandN)�__name__�
__module__�__qualname__r(r(r(r)r0hsr0cs�fdd�}|S)Ncstj����fdd��}|S)Ncs4�r"t�|�}|r"td|�f���||f|�|�S)Nz&Command missing %s of required keys %s)r/r0)�self�command�args�kwargs�missing_keys)�func�
required_keysr(r)�	decoratorns
z7ensure_command_keys.<locals>.wrapper.<locals>.decorator)�	functools�wraps)r9r;)r:)r9r)�wrappermsz$ensure_command_keys.<locals>.wrapperr()r:r>r()r:r)�ensure_command_keyslsr?c@s�eZdZefeed�dd�Zeed�dd��Zedd��Z	ed	d
��Z
edd��Zed
d��Zddd�Z
ddd�Zdd�Zdd�Zeedd�dd��ZdS)�NetworkState)rrcCs*tj|�|_||_|jdd�|_d|_dS)N�use_ipv6F)�copy�deepcopy�_network_state�_version�getrA�_has_default_route)r4rrr(r(r)�__init__szNetworkState.__init__)r'cCs
|jdS)Nr)rD)r4r(r(r)r�szNetworkState.configcCs|jS)N)rE)r4r(r(r)r�szNetworkState.versioncCs(y|jddStk
r"gSXdS)N�dnsr)rD�KeyError)r4r(r(r)�dns_nameservers�szNetworkState.dns_nameserverscCs(y|jddStk
r"gSXdS)NrI�search)rDrJ)r4r(r(r)�dns_searchdomains�szNetworkState.dns_searchdomainscCs|jdkr|j�|_|jS)N)rG�_maybe_has_default_route)r4r(r(r)�has_default_route�s

zNetworkState.has_default_routeNccsB|jjdi�}x.|j�D]"}|dkr,|Vq||�r|VqWdS)Nr)rDrF�values)r4�filter_funcZifaces�ifacer(r(r)�iter_interfaces�szNetworkState.iter_interfacesccs:x4|jjdg�D]"}|dk	r,||�r2|Vq|VqWdS)N�routes)rDrF)r4rQ�router(r(r)�iter_routes�s
zNetworkState.iter_routescCspx|j�D]}|j|�r
dSq
WxJ|j�D]>}x8|jdg�D](}x"|jdg�D]}|j|�rNdSqNWq<Wq*WdS)NT�subnetsrTF)rV�_is_default_routerSrF)r4rUrR�subnetr(r(r)rN�s

z%NetworkState._maybe_has_default_routecCs d}|jd�dko|jd�|kS)N�::�0.0.0.0�prefixr�network)rZr[)rF)r4rUZdefault_netsr(r(r)rX�szNetworkState._is_default_route)rr'cCs(i}d|kr|d|d<|d|if|�S)z�Instantiates a `NetworkState` without interpreting its data.

        That means only `config` and `version` are copied.

        :param network_state: Network state data.
        :return: Instance of `NetworkState`.
        rrr()�clsrr7r(r(r)�to_passthrough�s	zNetworkState.to_passthrough)N)N)r1r2r3�NETWORK_STATE_VERSION�dict�intrH�propertyrrrKrMrOrSrVrNrX�classmethodr_r(r(r(r)r@~s
	
r@c@s�eZdZigggd�ddd�Zeddfdd�dd�Zeed	�d
d��Zedd
��Z	e	j
dd
��Z	dd�Zdd�Zdd�Z
dd�ZdJdd�ZdKdd�ZdLdd�Zedg�dd ��Zedg�d!d"��Zedd#d$g�d%d&��Zedd'd(g�d)d*��Zedd+g�d,d-��Zedg�d.d/��Zd0d1�Zed2g�d3d4��Zed2g�d5d6��Zed7g�d8d9��Zd:d;�Zd<d=�Zd>d?�Zd@dA�Z dBdC�Z!dd	�dDdE�Z"dMdFdG�Z#dHdI�Z$dS)N�NetworkStateInterpreter)rrLFN)rrTrIrArzOptional[Renderer])rcCsv||_||_tj|j�|_||jd<d|_i|_||_|j	|j
|j|j|j
|j|j|j|j|j|j|j|jd�
|_dS)NrF)
r$Zbondsr%ZbridgesZ	ethernetsZ
infinibandZloopback�
nameserver�physicalrU�vlanZvlansZwifis)rE�_configrBrC�initial_network_staterD�_parsed�_interface_dns_map�	_renderer�handle_bond�handle_bonds�
handle_bridge�handle_bridges�handle_ethernets�handle_infiniband�handle_loopback�handle_nameserver�handle_physical�handle_route�handle_vlan�handle_vlans�handle_wifis�command_handlers)r4rrrr(r(r)rH�s(
z NetworkStateInterpreter.__init__)r'cCsHddlm}|jdkr8t|j|�r8tjd�tj|j	�St|j
|jd�S)Nr)r�zPassthrough netplan v2 config)r)�cloudinit.net.netplanrrE�
isinstancerm�LOG�debugr@r_rirD)r4�NetplanRendererr(r(r)r�s

z%NetworkStateInterpreter.network_statecCs|jjd�S)NrA)rDrF)r4r(r(r)rAsz NetworkStateInterpreter.use_ipv6cCs|jjd|i�dS)NrA)rD�update)r4�valr(r(r)rA
scCs|j|j|jd�}tj|�S)N)rrr)rErirDr�dumps)r4�stater(r(r)�dumps
zNetworkStateInterpreter.dumpcCszd|krtjd�td��t|d}t||�}|rNd|}tj|�t|��x&dd�|D�D]}t||||�q^WdS)Nrz$Invalid state, missing version fieldzInvalid state, missing keys: %scSsg|]}|dkr|�qS)r)rr()�.0�kr(r(r)�
<listcomp>#sz0NetworkStateInterpreter.load.<locals>.<listcomp>)r�error�
ValueError�NETWORK_STATE_REQUIRED_KEYSr/�setattr)r4r�r:r8�msgr.r(r(r)�loads


zNetworkStateInterpreter.loadcCstj|j�S)N)rr�rD)r4r(r(r)�dump_network_state&sz*NetworkStateInterpreter.dump_network_statecCs|j|jd�S)N)rr)rEri)r4r(r(r)�as_dict)szNetworkStateInterpreter.as_dictTcCs>|jdkr|j|d�d|_n|jdkr:|j|d�d|_dS)Nr)�skip_brokenTr|)rE�parse_config_v1rk�parse_config_v2)r4r�r(r(r)�parse_config,s

z$NetworkStateInterpreter.parse_configcCs x�|jD]�}|d}y|j|}Wn0tk
rR}ztd|�|�WYdd}~XnXy||�Wqtk
r�|sx�ntjd|dd�tj|j��YqXqWxz|j	j
�D]l\}}d}y|jd|}Wn2tk
r�}ztdj
|��|�WYdd}~XnX|r�|\}	}
|	|
d�|d	<q�WdS)
N�typez"No handler found for  command '%s'zSkipping invalid command: %sT)�exc_inforzINameserver specified for interface {0}, but interface {0} does not exist!)rrLrI)rir{rJ�RuntimeErrorr0r�warningr�r�rl�itemsrDr��format)r4r�r5�command_type�handler�e�	interfacerIrRrrLr(r(r)r�4s:z'NetworkStateInterpreter.parse_config_v1cCs�ddlm}t|j|�rdSx�|jj�D]�\}}|d	kr:q(y|j|}Wn0tk
rx}ztd|�|�WYdd}~XnXy||�|j	|�Wq(t
k
r�|s��ntjd|dd�tj
|j��Yq(Xq(WdS)
Nr)rrrz!No handler found for command '%s'zSkipping invalid command: %sT)r�)rr)r}rr~rmrir�r{rJr��
_v2_commonr0rr�r�r�)r4r�r�r�r5r�r�r(r(r)r�Ws*z'NetworkStateInterpreter.parse_config_v2�namecCs
|j|�S)N)rv)r4r5r(r(r)rtssz'NetworkStateInterpreter.handle_loopbackc

Cs.|jjdi�}|j|di�}x*|jdi�j�D]\}}|j||i�q0Wt|jd��}|js�x2|D]*}|jd�jd�s�t|jd��rdd|_PqdW|jd	d
�}|d
k	r�tj	|�}|jdd
�}	|	d
k	r�tj	|	�}	|j|jd�|jd�|jd�d
d|jd�d
d
|||	d��|jdj|jd�|i�|j
�d
S)z�
        command = {
            'type': 'physical',
            'mac_address': 'c0:d6:9f:2c:e8:80',
            'name': 'eth0',
            'subnets': [
                {'type': 'dhcp4'}
             ],
            'accept-ra': 'true'
        }
        rr��paramsrWr��6�addressTz	accept-raNr �mac_address�inetZmanualr)r�r�r�r�r!rr��gatewayrWz	accept-rar )rDrFr�r��_normalize_subnetsrA�endswithrrZis_truer�)
r4r5rrR�paramr�rWrYZ	accept_rar r(r(r)rvws>



z'NetworkStateInterpreter.handle_physical�vlan_id�	vlan_linkcCs\|jjdi�}|j|�|j|jd�i�}|jd�|d<|jd�|d<|j|d|i�dS)z�
        auto eth0.222
        iface eth0.222 inet static
                address 10.10.10.1
                netmask 255.255.255.0
                hwaddress ether BC:76:4E:06:96:B3
                vlan-raw-device eth0
        rr�r�zvlan-raw-devicer�N)rDrFrvr�)r4r5rrRr(r(r)rx�s

z#NetworkStateInterpreter.handle_vlan�bond_interfacesr�c	Cs|j|�|jjd�}|j|jd�i�}x(|jd�j�D]\}}|j||i�q8W|jddi�|jdj|d|i�x�|jd�D]�}||kr�|dd�}|j|�|jjdi�}|j|�}|jd�|d	<x(|jd�j�D]\}}|j||i�q�W|jdj||i�q�Wd
S)aU
        #/etc/network/interfaces
        auto eth0
        iface eth0 inet manual
            bond-master bond0
            bond-mode 802.3ad

        auto eth1
        iface eth1 inet manual
            bond-master bond0
            bond-mode 802.3ad

        auto bond0
        iface bond0 inet static
             address 192.168.0.10
             gateway 192.168.0.1
             netmask 255.255.255.0
             bond-slaves none
             bond-mode 802.3ad
             bond-miimon 100
             bond-downdelay 200
             bond-updelay 200
             bond-lacp-rate 4
        rr�r�zbond-slavesZnoner�r$)r�r�zbond-masterN)rvrDrFr�r�)	r4r5rrRr�r��ifname�cmdZbond_ifr(r(r)rn�s$


z#NetworkStateInterpreter.handle_bond�bridge_interfacesc	Cs|jjdi�}x.|jd�D] }||kr(qd|i}|j|�qW|jjdi�}|j|�|j|jd�i�}|d|d<x*|jdi�j�D]\}}|j||i�q�W|jd�}|dk	o�t|t��r�|dkr�d}n|dkr�d}ntdj|d���|jd|i�|j|d|i�dS)a�
            auto br0
            iface br0 inet static
                    address 10.10.10.1
                    netmask 255.255.255.0
                    bridge_ports eth0 eth1
                    bridge_stp off
                    bridge_fd 0
                    bridge_maxwait 0

        bridge_params = [
            "bridge_ports",
            "bridge_ageing",
            "bridge_bridgeprio",
            "bridge_fd",
            "bridge_gcint",
            "bridge_hello",
            "bridge_hw",
            "bridge_maxage",
            "bridge_maxwait",
            "bridge_pathcost",
            "bridge_portprio",
            "bridge_stp",
            "bridge_waitport",
        ]
        rr�r�Zbridge_portsr�r#N�on�1rT�off�0rFz2Cannot convert bridge_stp value ({stp}) to boolean)r")r�r�r)r�r�r)	rDrFrvr�r�r~�boolr�r�)	r4r5rr�r�rRr�r�r#r(r(r)rp�s.


z%NetworkStateInterpreter.handle_bridgecCs|j|�dS)N)rv)r4r5r(r(r)rs5sz)NetworkStateInterpreter.handle_infinibandcCs�g}g}d|kr@|d}t|t�s(|g}x|D]}|j|�q.Wd|krx|d}t|t�s`|g}x|D]}|j|�qfW||fS)Nr�rL)r~�list�append)r4r5rrLZaddrs�addr�paths�pathr(r(r)�
_parse_dns9s



z"NetworkStateInterpreter._parse_dnsr�cCsV|jjd�}|j|�\}}d|kr6||f|j|d<n|dj|�|dj|�dS)NrIr�rrL)rDrFr�rl�extend)r4r5rIrrLr(r(r)ruJsz)NetworkStateInterpreter.handle_nameservercCs0|jjd�}|j|�\}}||d�||d<dS)Nr)rrLrI)rDrFr�)r4r5rRZ_ifacerrLr(r(r)�_handle_individual_nameserverWsz5NetworkStateInterpreter._handle_individual_nameserver�destinationcCs|jdjt|��dS)NrT)rDr��_normalize_route)r4r5r(r(r)rw]sz$NetworkStateInterpreter.handle_routecCs|j|dd�dS)a�
        v2_command = {
          bond0: {
            'interfaces': ['interface0', 'interface1'],
            'parameters': {
               'mii-monitor-interval': 100,
               'mode': '802.3ad',
               'xmit_hash_policy': 'layer3+4'}},
          bond1: {
            'bond-slaves': ['interface2', 'interface7'],
            'parameters': {
                'mode': 1,
            }
          }
        }

        v1_command = {
            'type': 'bond'
            'name': 'bond0',
            'bond_interfaces': [interface0, interface1],
            'params': {
                'bond-mode': '802.3ad',
                'bond_miimon: 100,
                'bond_xmit_hash_policy': 'layer3+4',
            }
        }

        r$)�cmd_typeN)�_handle_bond_bridge)r4r5r(r(r)robsz$NetworkStateInterpreter.handle_bondscCs|j|dd�dS)a�
        v2_command = {
          br0: {
            'interfaces': ['interface0', 'interface1'],
            'forward-delay': 0,
            'stp': False,
            'maxwait': 0,
          }
        }

        v1_command = {
            'type': 'bridge'
            'name': 'br0',
            'bridge_interfaces': [interface0, interface1],
            'params': {
                'bridge_stp': 'off',
                'bridge_fd: 0,
                'bridge_maxwait': 0
            }
        }

        r%)r�N)r�)r4r5r(r(r)rq�sz&NetworkStateInterpreter.handle_bridgescCs$t�}�x|j�D�]\}}ddi}|jdi�}|jdd�}|sRtjd|t|��||d<|}|jd�}	|	rr|	}n |r�|r�|j�}
t|
�}|r�|}||d	<|jd
d�}|r�d
|i|d<x dD]}
|
|kr�||
||
<q�Wt|�|j	|�}t
|�dk�r|jd|i�tjd|�|j|�qWdS)a�
        ethernets:
          eno1:
            match:
              macaddress: 00:11:22:33:44:55
              driver: hv_netvsc
            wakeonlan: true
            dhcp4: true
            dhcp6: false
            addresses:
              - 192.168.14.2/24
              - 2001:1::1/64
            gateway4: 192.168.14.1
            gateway6: 2001:1::2
            nameservers:
              search: [foo.local, bar.local]
              addresses: [8.8.8.8, 8.8.4.4]
          lom:
            match:
              driver: ixgbe
            set-name: lom1
            dhcp6: true
            accept-ra: true
          switchports:
            match:
              name: enp2*
            mtu: 1280

        command = {
            'type': 'physical',
            'mac_address': 'c0:d6:9f:2c:e8:80',
            'name': 'eth0',
            'subnets': [
                {'type': 'dhcp4'}
             ]
        }
        r�rgr�
macaddressNzHNetworkState Version2: missing "macaddress" info in config entry: %s: %sr�zset-namer��driverr�rr �	accept-rarrWz!v2(ethernets) -> v1(physical):
%s)rrr r�)
r	r�rFrr��str�lowerrr*�_v2_to_v1_ipcfg�lenr�rv)r4r5Z
ifaces_by_macZeth�cfgZphy_cmdrr�r�Zset_nameZlcase_mac_addressZmacr�r.rWr(r(r)rr�sB-



z(NetworkStateInterpreter.handle_ethernetscCs�x�|j�D]x\}}d||jd�|jd�d�}d|kr@|d|d<t|�|j|�}t|�dkrl|jd|i�tjd|�|j|�q
Wd	S)
aq
        v2_vlans = {
            'eth0.123': {
                'id': 123,
                'link': 'eth0',
                'dhcp4': True,
            }
        }

        v1_command = {
            'type': 'vlan',
            'name': 'eth0.123',
            'vlan_link': 'eth0',
            'vlan_id': 123,
            'subnets': [{'type': 'dhcp4'}],
        }
        rh�id�link)r�r�r�r�rrrWzv2(vlans) -> v1(vlan):
%sN)	r�rFr*r�r�r�rr�rx)r4r5rhr�Zvlan_cmdrWr(r(r)ry�s
z$NetworkStateInterpreter.handle_vlanscCstjd�dS)NzOWifi configuration is only available to distros with netplan rendering support.)rr�)r4r5r(r(r)rzsz$NetworkStateInterpreter.handle_wifisc
Cs�tjd|�x�|j�D]�\}}d|kr8|jd�}|r8|}d|kr|jd�jdg�}|jd�jdg�}ddi}t|�dkr�|jd|i�t|�dkr�|jd	|i�|j|�|jd
i�jd�}|r�t|�}	|	r�|	}|j||�qWdS)Nzv2_common: handling config:
%szset-namerrLrr�rfrr�rr�)	rr�r�rFr�r�rurr�)
r4r�rRZdev_cfgZset_name_ifacerLrIZname_cmdr�Zreal_if_namer(r(r)r� s,

z"NetworkStateInterpreter._v2_commonc
s4tdd�tj|�j�D����x|j�D�]\}}tdd�|j�D��}|jdi�}|jdd�}|rl||d<d|d	||d
|jd�dt�fd
d�|j�D��i}d|kr�|d|d<t|�|j|�}	t|	�dkr�|jd|	i�t	j
d|||�|dk�r|j|�q(|dk�r|j|�q(t
dj|d���q(WdS)z(Common handler for bond and bridge typescss|]\}}||fVqdS)Nr()r�r��vr(r(r)�	<genexpr>@sz>NetworkStateInterpreter._handle_bond_bridge.<locals>.<genexpr>css"|]\}}|tkr||fVqdS)N)�NETWORK_V2_KEY_FILTER)r�r.�valuer(r(r)r�EsZ
parameterszgratuitious-arpNzgratuitous-arpr�r�Z_interfacesrr�c3s|]\}}�||fVqdS)Nr()r�r�r�)�v2key_to_v1r(r)r�TsrrrWzv2(%s) -> v1(%s):
%sr%r$z Unknown command type: {cmd_type})r�)ra�NET_CONFIG_TO_V2rFr��popr*r�r�r�rr�rprnr�r�)
r4r5r�Z	item_nameZitem_cfgZitem_paramsr�Z
grat_valueZv1_cmdrWr()r�r)r�;s8


z+NetworkStateInterpreter._handle_bond_bridgec
Cs�dd�}g}|jd�r:ddi}||jdi�|�|j|�|jd�rnddi}d|_||jdi�|�|j|�d	}d	}i}x�|jd
g�D]�}d|d�}d
|kr�d|kr�|d	kr�|jd�}|jd|i�n(d|kr�|d	kr�|jd�}|jd|i�d|ko�|�rF|jd�jd
�}	|	�r|	|d<|jd�jd�}
|
�r<|
|d<|j|�|j|�q�Wg}x>|jdg�D].}|jt|jd�|jd�|jd�d����qfWt|��r�t|��r�||dd<|S)z7Common ipconfig extraction from v2 to v1 subnets array.cSsd|kr|d|d<dS)Nzroute-metric�metricr()Z	overridesrYr(r(r)�_add_dhcp_overridesmszDNetworkStateInterpreter._v2_to_v1_ipcfg.<locals>._add_dhcp_overridesrr�zdhcp4-overridesrTzdhcp6-overridesNr�static)r�r��:rr�rrrKrL�
dns_searchrTZtoZviar�)r�r�r�r)rFr�rAr�r�r�)
r4r�r�rWrYrrrr�rrLrTrUr(r(r)r�jsV






z'NetworkStateInterpreter._v2_to_v1_ipcfg)T)T)T)N)%r1r2r3rjr`rHrcr@rrA�setterr�r�r�r�r�r�r�r?rtrvrxrnrprsr�rur�rwrorqrrryrzr�r�r�r(r(r(r)re�sL

#
75A
^"
/recCs~tj|�}tdd�|j�D��}|jd�dkr@|jt|dd��d	d
�|jdg�D�|d<dd
�}xdD]}|||�qhW|S)Ncss|]\}}|r||fVqdS)Nr()r�r�r�r(r(r)r��sz$_normalize_subnet.<locals>.<genexpr>r�r��static6r��
ip_address)�address_keyscSsg|]}t|��qSr()r�)r��rr(r(r)r��sz%_normalize_subnet.<locals>.<listcomp>rTcSs,||kr(t||t�r(||j�||<dS)N)r~r��split)Zsnetr�r(r(r)�listify�sz"_normalize_subnet.<locals>.listifyr�rK)r�r�)r�r�)r�rK)rBrCrar�rFr��_normalize_net_keys)rYZ
normal_subnetr�r�r(r(r)�_normalize_subnet�s


r�cCs�dd�|j�D�}d}x|D]}|j|�r|}PqW|s\ddj|�|f}tj|�t|��t|j|��}t|�s�tjd|�td|�d���t|�}t	|�}|jd	�}	d
|k�r|j
d
�\}
}}|
||<|r�t|�}
n*|r�t|�}
ntjd|�td|�d���nRd|k�rt
|d�}
n:|	�r2|�r2t|	�}
n$|	�rH|�rHt|	�}
n|�rRdnd
}
d|k�r�t|d�t|
�k�r�tjd|
|�|
|d<|�r�d	|k�r�|d	=n|�r�t|d�|d	<|S)a�Normalize dictionary network keys returning prefix and address keys.

    @param network: A dict of network-related definition containing prefix,
        netmask and address_keys.
    @param address_keys: A tuple of keys to search for representing the address
        or cidr. The first address_key discovered will be used for
        normalization.

    @returns: A dict containing normalized prefix and matching addr_key.
    cSs"i|]\}}|s|dkr||�qS)rr()r�r�r�r(r(r)�
<dictcomp>�sz'_normalize_net_keys.<locals>.<dictcomp>Nz/No config network address keys [%s] found in %s�,z$Address %s is not a valid ip networkzAddress z is not a valid ip address�netmask�/r\�@�z;Overwriting existing 'prefix' with '%s' in network info: %s)r�rF�joinrr�r�r�rrr
�	partitionrr
rbr�r)r]r�ZnetZaddr_keyr.�messager�Zipv6Zipv4r�Z	addr_part�_Zmaybe_prefixr\r(r(r)r��s^









 
r�cCs�tdd�|j�D��}d|kr0|d|d<|d=|jt|d	d��|jd�}|r�yt|�|d<Wn2tk
r�}ztdj|��|�WYdd}~XnX|S)
a�normalize a route.
    return a dictionary with only:
       'type': 'route' (only present if it was present in input)
       'network': the network portion of the route as a string.
       'prefix': the network prefix for address as an integer.
       'metric': integer metric (only if present in input).
       'netmask': netmask (string) equivalent to prefix iff network is ipv4.
    css"|]\}}|dkr||fVqdS)�N)r�Nr()r�r�r�r(r(r)r�!sz#_normalize_route.<locals>.<genexpr>r�r])r�r�z(Route config metric {} is not an integerN)r]r�)	rar�r�r�rFrbr��	TypeErrorr�)rUZnormal_router�r�r(r(r)r�s"


r�cCs|sg}dd�|D�S)NcSsg|]}t|��qSr()r�)r��sr(r(r)r�;sz&_normalize_subnets.<locals>.<listcomp>r()rWr(r(r)r�8sr�T)�
net_configr�r'cCsfd}|jd�}|jd�}|dkr$|}|rP|dk	rPt|||d�}|j|d�|j}|sbtd|����|S)zfParses the config, returns NetworkState object

    :param net_config: curtin network config dict
    Nrrr|)rrr)r�zpNo valid network_state object created from network config. Did you specify the correct version? Network config:
)rFrer�rr�)r�r�rr�rrZnsir(r(r)�parse_net_config_data>s	

r�)TN)-rBr<ZloggingZtypingrrrrZ	cloudinitrrZ
cloudinit.netrr	r
rrr
rrrZcloudinit.net.rendererrZ	getLoggerr1rr`r�r�r�r�rar*r/�	Exceptionr0r?r@rer�r�r�r�r�r�r(r(r(r)�<module>s�,
 V^L"

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