PHP WebShell

Текущая директория: /usr/lib/python3/dist-packages/cloudinit/sources/helpers/vmware/imc/__pycache__

Просмотр файла: config_nic.cpython-310.pyc

o

x[h�"�@s`ddlZddlZddlZddlZddlmZmZmZddlm	Z	m
Z
e�e�Z
Gdd�d�ZdS)�N)�net�subp�util)�ipv4_mask_to_net_prefix�ipv6_mask_to_net_prefixc@s�eZdZ	d"dd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zd#dd�Zdd�Zd$d d!�ZdS)%�NicConfiguratorTcCsR||_||_||_i|_|r|��n|jD]}|j|j|j��<q|��|_	dS)a
        Initialize the Nic Configurator
        @param nics (list) an array of nics to configure
        @param use_system_devices (Bool) Get the MAC names from the system
        if this is True. If False, then mac names will be retrieved from
         the specified nics.
        N)
�nics�name_servers�dns_suffixes�mac2Name�find_devices�name�mac�lower�get_primary_nic�_primaryNic)�selfrr	r
�use_system_devices�nic�r�Q/usr/lib/python3/dist-packages/cloudinit/sources/helpers/vmware/imc/config_nic.py�__init__s


zNicConfigurator.__init__cCs@dd�|jD�}|sdSt|�dkrtddd�|D���|dS)z|
        Retrieve the primary nic if it exists
        @return (NicBase): the primary nic if exists, None otherwise
        cSsg|]}|jr|�qSr)�primary��.0rrrr�
<listcomp>6sz3NicConfigurator.get_primary_nic.<locals>.<listcomp>N�z!There can only be one primary niccSsg|]}|j�qSr)rrrrrr<sr)r�len�RuntimeError)r�primary_nicsrrrr1s�zNicConfigurator.get_primary_nicc
Cszgd�}t�|�\}}t�dd|�dd�}d}|D]}t�||�}|s&q|�d���}|�dd�d}	|	|j|<qdS)	zb
        Create the mac2Name dictionary
        The mac address(es) are in the lower case
        )�ip�addr�showz\n\d+: �
rNz3link/ether (([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2}))�:r)r�re�split�search�grouprr)
r�cmd�output�_err�sections�macPat�section�matchrr
rrrrAs�zNicConfigurator.find_devicesc	Cs�|j��}|j�|�}|std|j��i}|�|�|�|�|�|�|�|�|�	|�|�
|�|�|�|��g}|D]	}|rB|�
|�q9||iS)z�
        Return the config dict needed to configure a nic
        @return (dict): the config dict to configure the nic
        @param nic (NicBase): the nic to configure
        zNo known device has MACADDR: %s)rrr�get�
ValueError�	gen_match�gen_set_name�
gen_wakeonlan�	gen_dhcp4�	gen_dhcp6�
gen_addresses�
gen_routes�gen_nameservers�update)rrrr
�nic_config_dict�
generators�valuerrr�gen_one_nic_v2Ss&
�

�zNicConfigurator.gen_one_nic_v2cCsdd|iiS)Nr/�
macaddressr)rrrrrr2oszNicConfigurator.gen_matchcCsd|iS)Nzset-namer)rr
rrrr3rszNicConfigurator.gen_set_namecCs
d|jiS)N�	wakeonlan)�onboot)rrrrrr4us
zNicConfigurator.gen_wakeonlancCsji}|j��}|j��dkrd}|dkr,|�ddi�|js!|jr*|�dddii�|S|�ddi�|S)	N�disabled�manual�static�dhcp4Tzdhcp4-overrideszuse-dnsF)�	bootProtor�	ipv4_moder:r	r
)rrrE�	bootprotorrrr5xs
�zNicConfigurator.gen_dhcp4cCsi}|jr|�ddi�|S)N�dhcp6F)�
staticIpv6r:)rrrIrrrr6�szNicConfigurator.gen_dhcp6c	Cs�g}d}|j}|r#|d}|jrt|j�}|jr#|�|j�d|���|j}|r=|D]}t|j�}|�|j�d|���q*|rCd|iSiS)N� r�/�	addresses)�
staticIpv4�netmaskrr �appendrJr)	rr�address_list�v4_cidr�v4_addrs�v4�v6_addrs�v6�v6_cidrrrrr7�s"

zNicConfigurator.gen_addressescCsg}d}|j}|rG|d}|jr|jr|�d|jdd��|jsG|jrG|jr,t|j�}|jD]}tj|�d|��dd�}|�|�|d��q/|j	}|r�|D]3}	t
|	j�}
|jrd|	jrd|�d|	jd��|js�|	jr�tj|	j�d|
��dd�}|�|�|	jd��qN|r�d	|iSiS)
NrKrz	0.0.0.0/0)�to�viarLF)�strictz::/0�routes)
rNr�gatewaysrPrrOr�	ipaddress�IPv4NetworkrJr�gateway�IPv6Network)rr�
route_listrRrSrTr_�	v4_subnetrUrVrW�	v6_subnetrrrr8�s@

�
���zNicConfigurator.gen_routescCsxi}g}g}|jr|jD]}|�|�q|jr"|jD]}|�|�q|r+|�d|i�|r4|�d|i�|r:d|iSiS)Nr'rM�nameservers)r
rPr	r:)r�nameservers_dict�search_list�addresses_list�
dns_suffix�name_serverrrrr9�s 

zNicConfigurator.gen_nameserversFNcCs<|rt�d�|�|�i}|jD]
}|�|�|��q|S)z@Return the config elements that are needed to configure the nicszConfiguring the interfaces file)�logger�info�	configurerr:r>)rrl�osfamily�ethernets_dictrrrr�generate�s


zNicConfigurator.generatecCst�d�tjj��dS)NzClearing DHCP leases)rjrkr�dhcp�IscDhclient�clear_leases)rrrr�
clear_dhcp�s
zNicConfigurator.clear_dhcpcCs�|r|dkr
t�d�dSd}tj�|d�}tj�|d�}tj�|�s/tj�|�r/t�||�gd�}tj|d�|�d	�|�	�dS)
z^
        Configure the /etc/network/interfaces
        Make a back up of the original
        �debianz3Debian OS not detected. Skipping the configure stepNz/etc/network�
interfacesz&interfaces.before_vmware_customization)zH# DO NOT EDIT THIS FILE BY HAND -- AUTOMATICALLY GENERATED BY cloud-initz"source /etc/network/interfaces.d/*z*source-directory /etc/network/interfaces.dr#)�content)
rjrk�os�path�join�exists�renamer�
write_filers)rrm�
containingDir�
interfaceFile�originalFile�linesrrrrl�s
�zNicConfigurator.configure)T)FN)N)�__name__�
__module__�__qualname__rrrr>r2r3r4r5r6r7r8r9rorsrlrrrrrs"
�*

r)r]�loggingrwr%�	cloudinitrrr�cloudinit.net.network_staterr�	getLoggerr�rjrrrrr�<module>s



Выполнить команду


Для локальной разработки. Не используйте в интернете!