Mini Shell

Direktori : /lib64/python3.6/site-packages/pyanaconda/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/pyanaconda/__pycache__/network.cpython-36.pyc

3

C��e�Z�@s6ddlZejdd�ddlmZddlZddlmZmZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlmZddlmZdd	lmZmZmZdd
lmZddlmZmZmZddlm Z dd
l!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(e(e)�Z*dZ+da,ej-�Z.da/ddddddddddddddd d!gZ0d"d �Z1dId#d�Z2dJd%d�Z3d&d'�Z4d(d�Z5d)d�Z6d*d�Z7d+d�Z8d,d-�Z9d.d/�Z:dKd1d�Z;d2d3�Z<d4d�Z=dLd5d!�Z>d6d7�Z?ej@d$fd8d�ZAej@fd9d�ZBd:d�ZCej@fd;d�ZDd<d=�ZEd>d�ZFd?d�ZGd@dA�ZHdMdCdD�ZIdEdF�ZJdGdH�ZKdS)N�N�NMz1.0)r)�util�	constants)�
get_native)�_)�kernel_arguments)� HOSTNAME_PATTERN_WITHOUT_ANCHORS� IPV6_ADDRESS_IN_DRACUT_IP_OPTION�	MAC_OCTET)�conf)�NETWORK�TIMEZONE�STORAGE)�FCOE)�
sync_run_task)�NetworkDeviceInfo)�is_module_available)�get_module_loggerzlocalhost.localdomain�get_supported_devices�status_message�wait_for_connectivity�wait_for_connecting_NM_thread�wait_for_network_devices�wait_for_connected_NM�initialize_network�copy_resolv_conf_to_root�get_hostname�prefix_to_netmask�netmask_to_prefix�get_first_ip_address�is_valid_hostname�check_ip_address�
get_nm_client�write_configurationcCs.tjjrtstjjd�atStjd�dSdS)zGet NetworkManager Client.NzANetworkManager client not available (system does not provide it).)	r�systemZprovides_system_bus�
_nm_clientrZClient�new�log�debug�r)r)�/usr/lib64/python3.6/network.pyr"As
cCsfyL|dkrtj|�n4|dkr*tj|�n |s:tj|�ntjd|�dSdStk
r`dSXdS)a9Check if the given IP address is valid in given version if set.

    :param str address: IP address for testing
    :param int version: ``4`` for IPv4, ``6`` for IPv6 or
                        ``None`` to allow either format
    :returns: ``True`` if IP address is valid or ``False`` if not
    :rtype: bool
    ��zIP version %s is not supportedFTN)�	ipaddressZIPv4AddressZIPv6AddressZ
ip_addressr'�error�
ValueError)Zaddress�versionr)r)r*r!Ms	FcCsh|sdtd�fSt|�dkr(dtd�fS|rD|d
dkrDdtd�fStjdtd	|�sddtd
�fSdS)aSCheck if the given string is (syntactically) a valid hostname.

    :param str hostname: a string to check
    :param bool local: is the hostname static (for this system) or not (on the network)
    :returns: a pair containing boolean value (valid or invalid) and
              an error message (if applicable)
    :rtype: (bool, str)
    Fz,Host name cannot be None or an empty string.�z4Host name must be 255 or fewer characters in length.��.z-Local host name must not end with period '.'.�^�$z�Host names can only contain the characters 'a-z', 'A-Z', '0-9', '-', or '.', parts between periods must contain something and cannot start or end with '-'.T����)Tr6)r�len�re�matchr)�hostnameZlocalr)r)r*r es	cCsDg}g}x2tt��D]$}|t|dd�7}|t|dd�7}qW||S)z5Return a list of IP addresses for all active devices.r+)r0r,)�get_activated_devicesr"�get_device_ip_addresses)Zipv4_addressesZipv6_addresses�devicer)r)r*�get_ip_addresses�sr?cCs xt�D]}|dkr|SqWdS)z�Return the first non-local IP of active devices.

    :return: IP address assigned to an active device
    :rtype: str or None
    �	127.0.0.1�::1N)r@rA)r?)�ipr)r)r*r�scCs.d}x$|dkr(t|�|kr|S|d7}qW|S)z' Convert netmask to prefix (CIDR bits) r�!r2)r)�netmask�prefixr)r)r*r�s
cCsdg}xFtd�D]:}|dkr.|jd�|d8}q|jddd|�d}qWdjdd	�|D��}|S)
z' Convert prefix (CIDR bits) to netmask r+�r1��rr3css|]}t|�VqdS)N)�str)�.0Zbyter)r)r*�	<genexpr>�sz$prefix_to_netmask.<locals>.<genexpr>)�range�append�join)rEZ_bytesZ_irDr)r)r*r�s

cCs�d}x�tt��D]�}t|dd�t|dd�}xd|D]\}ytj|�}Wn2tjk
rv}ztjd||�WYdd}~Xq2Xt|�dkr2|d}Pq2WqW|s�|dkr�tj	�}|s�|dkr�t
}|S)
z=Try to determine what the hostname should be for this system.Nr+)r0r,z2Exception caught trying to get host name of %s: %s�r�(none)�	localhost�localhost.localdomain)rPrQrR)rPrQrR)r<r"r=�socket�
gethostbyaddrZherrorr'r(r8Zgethostname�DEFAULT_HOSTNAME)r;r>ZaddrsZipaddrZhinfo�er)r)r*r�s"

 
cCs~|jdd�}|jd�}|rzx^|jd�D]P}|jd�r@tjd|�}|jd�}t|�dkr&tjt|d�r&|jd�d}q&W|S)	z�Get hostname defined by boot options.

    :param kernel_args: structure holding installer boot options
    :type kernel_args: KernelArguments
    r;r6rB� �[�:r,r+)	�get�split�
startswithr	�subr8r9r:r
)Zkernel_argsr;ZipoptsZipopt�elementsr)r)r*�hostname_from_cmdline�s


r_cCs�tjdddd|g�}|s(tjd|�dS|j�}|d|ks^t|�dks^d	|ks^|jd	�d
krptjd||�dS||jd	�dS)
z+Get interface used to access given host IP.rB�routerZZtoz'Could not get interface for route to %sr6r��devrOz)Unexpected "ip route get to %s" reply: %sr2)rZexecWithCapturer'r.r[r8�index)Zhost_ipr`Z
route_infor)r)r*�iface_for_host_ip�srdr6cCs�d}tjj||jd��}tjj|�s4tjd|�dStjj|�rPtjd|�dStjj|�}tjj|�srt	j
|�tj||�dS)z"Copy resolv.conf to a system root.z/etc/resolv.conf�/z%s does not existNz%s already exists)
�os�pathrN�lstrip�isfiler'r(�dirname�isdirrZ
mkdirChain�shutilZcopyfile)�root�src�dstZdst_dirr)r)r*r�s
cCsHtj|�}tjd|j�t|�t|j��}d|j|f}tj|�dS)z3Run network initialization task and log the result.zRunning task %sz
%s result: %sN)r�	get_proxyr'r(�NamerrZ	GetResult)�	task_path�
task_proxy�result�msgr)r)r*�run_network_initialization_task	s
rvcCs�tjjsdStj�}d}tj|�|j|�tjddd�t�D��t	|j
��t	|j��t	|j��t	|j
��|jtkr�tt�}|r�tjd|�|j|�tjd�|j�tjd�dS)	zInitialize networking.NzInitialization started.zDevices found: %scSsg|]
}|j�qSr))�device_name)rJrbr)r)r*�
<listcomp>sz&initialize_network.<locals>.<listcomp>z(Updating host name from boot options: %sz Creating network configurations.zInitialization finished.)rr$Zcan_configure_networkrrpr'r(ZLogConfigurationStaterrvZ'ConsolidateInitramfsConnectionsWithTaskZApplyKickstartWithTaskZDumpMissingIfcfgFilesWithTaskZ(SetRealOnbootValuesFromKickstartWithTask�HostnamerUr_rZSetHostnameZCreateDeviceConfigurations)�
network_proxyruZbootopts_hostnamer)r)r*rs(




cs�tjt�}|j���fdd�t�D�}tj�}|j|�}tj|�}t|�|j|�}tj|�}t|�|j	|�}tj|�}t|�t
jjr�|j
}|tkr�|j|�dS)z/Install network configuration to target system.csg|]}|j�kr|j�qSr))rw)rJrb)�	fcoe_nicsr)r*rx:sz'write_configuration.<locals>.<listcomp>N)rrprZGetNicsrrZ!ConfigureActivationOnBootWithTaskrZInstallNetworkWithTaskZConfigureHostnameWithTaskrr$Zcan_change_hostnameryrUZSetCurrentHostname)Z	overwriteZ
fcoe_proxyZfcoe_ifacesrzrrrsr;r))r{r*r#6s"






cCs�tt�sdStj�}tt��}tjdt|��g}xP|D]H}ytj	|�d}Wn&tj
k
rttjd|�|}YnX|j|�q8W|j
r�tjjr�|j|�dS)zESet NTP servers of timezone module from dhcp if not set by kickstart.Nzgot %d NTP servers from DHCPrz3getting NTP server host name failed for address: %s)rr
rp�get_ntp_servers_from_dhcpr"r'�infor8rSrTr.r(rMZ
NTPServersr�targetZis_hardwareZ
SetNTPServers)Ztimezone_proxy�ntp_serversZ	hostnamesZserver_addressr;r)r)r*�_set_ntp_servers_from_dhcpPs 


r�cCs�tj�}|jrdS|r2|j�r,tjd|�q>dSntjd|�d}xF||kr�|tj7}tj	tj�|jrxtjd|�dS|rD|j�sDPqDWtjd|�dS)a�Wait for NM being connected.

    If only_connecting is set, wait only if NM is in connecting state and
    return immediately after leaving this state (regardless of the new state).
    Used to wait for dhcp configuration in progress.

    :param timeout: timeout in seconds
    :type timeout: int
    :parm only_connecting: wait only for the result of NM being connecting
    :type only_connecting: bool
    :return: NM is connected
    :rtype: bool
    Tz9waiting for connecting NM (dhcp in progress?), timeout=%dFz$waiting for connected NM, timeout=%drzNM connected, waited %d secondsz#NM not connected, waited %d seconds)
rrpZ	ConnectedZIsConnectingr'r(rZ NETWORK_CONNECTED_CHECK_INTERVAL�time�sleep)�timeout�only_connectingrz�ir)r)r*rjs(

cCs\t|�}d}tjd|�x>||krVtj�}|j�}|t|�sBdS|d7}tjd�qWdS)z;Wait for network devices to be activated with a connection.rz.waiting for connection of devices %s for iscsiTr2F)�setr'r(rrpZGetActivatedInterfacesr�r�)Zdevicesr�r�rz�activated_devicesr)r)r*r�s
c	Cs4tdd�}|rt�t�|atj�WdQRXdS)aIWait for connecting NM in thread, do some work and signal connectivity.

    This function is called from a thread which is run at startup to wait for
    NetworkManager being in connecting state (eg getting IP from DHCP). When NM
    leaves connecting state do some actions and signal new state if NM becomes
    connected.
    T)r�N)rr��network_connected_condition�network_connectedZ
notify_all)�	connectedr)r)r*r�s
cCs0d}tj�tdkr tj|d�t}tj�|S)z�Wait for network connectivty to become available

    :param timeout: how long to wait in seconds
    :type timeout: integer of floatFN)r�)r��acquirer��wait�release)r�r�r)r)r*r�scCsPg}|s|Sx>|j�D]2}|j�tjjkr,qx|j�D]}|j|�q6WqW|S)z%Get activated NetworkManager devices.)Zget_active_connections�	get_staterZActiveConnectionStateZ	ACTIVATEDZget_devicesrM)�	nm_clientr�Zacr>r)r)r*r<�sr<cs�td�}|std�}|S|j�}|tjjkr8td�}�n<|tjjkrPtd�}�n$dd�t|�D�}|�rli}i}g}xt|D]l}g}t|d�r�dd�|j�D�}|j	�}	|||	<|j
�tjjkrzd	}
|j
�}|r�|j�j�j�}
|
||	<qzWttjj|j�����fd
d�|D�}t|�dk�r:|d}|j��p6|j	�}	|j
�}t|��r\td
�d|	i}n�|tjjk�r�td�d||	i}n�|tjjk�r�td�|	dj||	�d�}n�|tjjk�r�td�|	dj||	�d�}n^|tjjk�rtd�|	dj||	�d�}n2|tjjk�rj|j�}
|j�}td�|	|
|d�}�qtt|�dk�rtg}�x|D]�}|j��ph|j	�}	|j
�}t|��r�|j d|	�n�|tjjk�r�|j d||	�n�|tjjk�r�|j d|	dj||	�f�nt|tjjk�r|j d|	dj||	�f�nH|tjjk�r2|j d|	dj||	�f�n|tjjk�rT|j d|	��qTWtd�ddj|�i}ntd�}t!��s�td�}|S)z6A short string describing which devices are connected.ZUnknownzStatus not availablez
Connecting...zDisconnecting...cSs$g|]}t|j�p|j��s|�qSr))�is_libvirt_device�get_ip_iface�	get_iface)rJ�dr)r)r*rx�sz"status_message.<locals>.<listcomp>�
get_slavescSsg|]}|j��qSr))r�)rJZ	slave_devr)r)r*rx�sr6csg|]}|j��kr|�qSr))r�)rJrb)�
all_slavesr)r*rx�sr2rz$Wired (%(interface_name)s) connected�interface_namez&Wireless connected to %(access_point)sZaccess_pointz6Bond %(interface_name)s (%(list_of_slaves)s) connected�,)r�Zlist_of_slavesz6Team %(interface_name)s (%(list_of_slaves)s) connectedz8Bridge %(interface_name)s (%(list_of_slaves)s) connectedzDVLAN %(interface_name)s (%(parent_device)s, ID %(vlanid)s) connected)r�Z
parent_device�vlanidz%sz%s (%s)z&Connected: %(list_of_interface_names)sZlist_of_interface_namesz, z
Not connectedzNo network devices available)"rr�rZStateZ
CONNECTINGZ
DISCONNECTINGr<�hasattrr�r�Zget_device_type�
DeviceTypeZWIFIZget_active_access_pointZget_ssid�get_data�decoder��	itertools�chain�
from_iterable�valuesr8r��device_type_is_supported_wiredZBONDrNZTEAMZBRIDGEZVLANZ
get_parentZget_vlan_idrMr)r�ru�stateZactive_devsZslavesZssidsZ	nonslavesr>Z
device_slaves�ifaceZssidZap�device_type�parentr�Zdevlistr))r�r*r�s�



cCstj�}tj|j��S)z�Get existing network devices supported by the installer.

    :return: basic information about the devices
    :rtype: list(NetworkDeviceInfo)
    )rrprZfrom_structure_listZGetSupportedDevices)rzr)r)r*r3scCsTg}|s|SxBt|�D]6}|j�}|r|j�}|jd�}|r|j|jd��qW|S)z�Return IPs of NTP servers obtained by DHCP.

    :param nm_client: instance of NetworkManager client
    :type nm_client: NM.Client
    :return: IPs of NTP servers obtained by DHCP
    :rtype: list of str
    rrW)r<Zget_dhcp4_configZget_optionsrZ�extendr[)r�rr>Zdhcp4_configZoptionsZntp_servers_stringr)r)r*r|=s
r|r+cCsdg}|dkr,|j�}|r`dd�|j�D�}n4|dkr`|j�}|r`dd�|j�D�}dd�|D�}|S)z�Get IP addresses of the device.

    Ignores ipv6 link-local addresses.

    :param device: NetworkManager device object
    :type device: NMDevice
    :param version: IP version (4 or 6)
    :type version: int
    r+cSsg|]}|j��qSr))�get_address)rJ�addrr)r)r*rxesz+get_device_ip_addresses.<locals>.<listcomp>r,cSsg|]}|j��qSr))r�)rJr�r)r)r*rxiscSsg|]}|jd�s|�qS)zfe80:)r\)rJr�r)r)r*rxjs)Zget_ip4_configZ
get_addressesZget_ip6_config)r>r0Z	addressesZipv4_configZipv6_configZ
all_addressesr)r)r*r=Vs
r=cCs|o|jd�S)NZvirbr)r\)r�r)r)r*r�osr�cCs|tjjtjjgkS)N)rr�ZETHERNETZ
INFINIBAND)r�r)r)r*r�ssr�)N)F)r6)F)r+)LZgiZrequire_versionZ
gi.repositoryrrlZpyanaconda.corerrrSr�rfr�Z	threadingr9r-Z
dasbus.typingrZpyanaconda.core.i18nrZpyanaconda.core.kernelrZpyanaconda.core.regexesrr	r
Z&pyanaconda.core.configuration.anacondarZ,pyanaconda.modules.common.constants.servicesrr
rZ+pyanaconda.modules.common.constants.objectsrZpyanaconda.modules.common.taskrZ,pyanaconda.modules.common.structures.networkrZpyanaconda.modules.common.utilrZpyanaconda.anaconda_loggersr�__name__r'rUr�Z	Conditionr�r%�__all__r"r!r r?rrrrr_rdrrvrr#r�ZNETWORK_CONNECTION_TIMEOUTrrrrr<rrr|r=r�r�r)r)r)r*�<module>st




#
*]