Viewing 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&