Current File : //usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyo |
�
oB�]c @ sv d d l Z d d l Z d d l Z d d l m Z d d l m Z e j e � Z d � Z
d e f d � � YZ d S( i����N( t mask_to_net_prefix( t utilc C s� | j d � } | j d � } g } x? t t d � � D]+ } | j t | | � t | | � @� q7 Wd j g | D] } t | � ^ qs � S( s�
Return the subnet for a given ip address and a netmask
@return (str): the subnet
@param ip: ip address
@param netmask: netmask
t .i ( t splitt listt ranget appendt intt joint str( t ipt netmaskt ip_arrayt
mask_arrayt resultt indext x( ( sS /usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyt
gen_subnet s )t NicConfiguratorc B sw e Z e d � Z d � Z d � Z d � Z d � Z d � Z d � Z d � Z
e d d � Z
d � Z d d
� Z RS( c C sw | | _ i | _ d | _ d | _ | r7 | j � n- x* | j D] } | j | j | j j � <qA W| j � | _
d S( s
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( t nicst mac2Namet Nonet ipv4PrimaryGatewayt ipv6PrimaryGatewayt find_devicest namet mact lowert get_primary_nict _primaryNic( t selfR t use_system_devicest nic( ( sS /usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyt __init__# s
c C su g | j D] } | j r
| ^ q
} | s/ d St | � d k ri t d g | D] } | j ^ qN � � n | d Sd S( s|
Retrieve the primary nic if it exists
@return (NicBase): the primary nic if exists, None otherwise
i s! There can only be one primary nici N( R t primaryR t lent ExceptionR ( R R t primary_nics( ( sS /usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyR 8 s %"c
C s� d d d g } t j | � \ } } t j d d | � d } d } xd | D]\ } t j | | � } | so qK n | j d � j � } | j d d � d } | | j | <qK Wd
S( sb
Create the mac2Name dictionary
The mac address(es) are in the lower case
R
t addrt shows \n\d+: s
i s3 link/ether (([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2}))t :i N( R t subpt reR t searcht groupR R (
R t cmdt outputt _errt sectionst macPatt sectiont matchR R ( ( sS /usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyR F s
c
C s | j j � } | j j | � } | s= t d | j � � n g } i d d 6| d 6| d 6} g } g } | j | | � \ } } | j | � | j | � | j | | � \ } } | j | � | j | � | j i | d 6� | j | � | r| j | � n | S( s�
Return the config list needed to configure a nic
@return (list): the subnets and routes list to configure the nic
@param nic (NicBase): the nic to configure
s No known device has MACADDR: %st physicalt typeR t mac_addresst subnets(
R R R t gett
ValueErrort gen_ipv4t extendt gen_ipv6t updateR (
R R R R t
nics_cfg_listt cfgt subnet_listt
route_listR7 t routes( ( sS /usr/lib/python2.7/site-packages/cloudinit/sources/helpers/vmware/imc/config_nic.pyt gen_one_nicX s&