mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
cleanup (mostly cosmetic)
Ticket: CM-1438 Reviewed By: Testing Done: sanity test
This commit is contained in:
265
pkg/iface.py
265
pkg/iface.py
@ -6,20 +6,35 @@
|
|||||||
# iface --
|
# iface --
|
||||||
# interface object
|
# interface object
|
||||||
#
|
#
|
||||||
|
|
||||||
|
"""ifupdown2 network interface object
|
||||||
|
|
||||||
|
It closely resembles the 'iface' object in /etc/network/interfaces
|
||||||
|
file. But can be extended to include any other network interface format
|
||||||
|
|
||||||
|
|
||||||
|
The module contains the following public classes:
|
||||||
|
|
||||||
|
- ifaceState -- enumerates iface object state
|
||||||
|
|
||||||
|
- ifaceStatus -- enumerates iface object status (success/error)
|
||||||
|
|
||||||
|
- ifaceJsonEncoder -- Json encoder for the iface object
|
||||||
|
|
||||||
|
- iface -- network in terface object class
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
#from json import *
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
tickmark = ' (' + u'\u2713'.encode('utf8') + ')'
|
_tickmark = ' (' + u'\u2713'.encode('utf8') + ')'
|
||||||
crossmark = ' (' + u'\u2717'.encode('utf8') + ')'
|
_crossmark = ' (' + u'\u2717'.encode('utf8') + ')'
|
||||||
|
|
||||||
class ifaceFlags():
|
|
||||||
NONE = 0x1
|
|
||||||
FOLLOW_DEPENDENTS = 0x2
|
|
||||||
|
|
||||||
class ifaceStatus():
|
class ifaceStatus():
|
||||||
"""iface status """
|
"""Enumerates iface status """
|
||||||
|
|
||||||
UNKNOWN = 0x1
|
UNKNOWN = 0x1
|
||||||
SUCCESS = 0x2
|
SUCCESS = 0x2
|
||||||
ERROR = 0x3
|
ERROR = 0x3
|
||||||
@ -46,8 +61,8 @@ class ifaceStatus():
|
|||||||
return cls.ERROR
|
return cls.ERROR
|
||||||
|
|
||||||
class ifaceState():
|
class ifaceState():
|
||||||
|
"""Enumerates iface state """
|
||||||
|
|
||||||
""" iface states """
|
|
||||||
UNKNOWN = 0x1
|
UNKNOWN = 0x1
|
||||||
NEW = 0x2
|
NEW = 0x2
|
||||||
PRE_UP = 0x3
|
PRE_UP = 0x3
|
||||||
@ -124,9 +139,34 @@ class ifaceJsonEncoder(json.JSONEncoder):
|
|||||||
'config' : retconfig})
|
'config' : retconfig})
|
||||||
|
|
||||||
class iface():
|
class iface():
|
||||||
""" flags """
|
""" ifupdown2 interface object class
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
name Name of the interface
|
||||||
|
addr_family Address family eg, inet, inet6. Can be None to indicate both address families
|
||||||
|
addr_method Address method eg, static, manual or None for static
|
||||||
|
address method
|
||||||
|
config dictionary of config lines for this interface
|
||||||
|
state Configuration state of an interface as defined by
|
||||||
|
ifaceState
|
||||||
|
status Configuration status of an interface as defined by
|
||||||
|
ifaceStatus
|
||||||
|
flags Internal flags used by iface processing
|
||||||
|
priv_flags private flags owned by module using this class
|
||||||
|
refcnt reference count, indicating number of interfaces
|
||||||
|
dependent on this iface
|
||||||
|
lowerifaces list of interface names lower to this interface or
|
||||||
|
this interface depends on
|
||||||
|
upperifaces list of interface names upper to this interface or
|
||||||
|
the interfaces that depend on this interface
|
||||||
|
auto True if interface belongs to the auto class
|
||||||
|
classes List of classes the interface belongs to
|
||||||
|
env shell environment the interface needs during execution
|
||||||
|
raw_config raw interface config from file
|
||||||
|
"""
|
||||||
|
|
||||||
# flag to indicate that the object was created from pickled state
|
# flag to indicate that the object was created from pickled state
|
||||||
PICKLED = 0x1
|
_PICKLED = 0x1
|
||||||
|
|
||||||
version = '0.1'
|
version = '0.1'
|
||||||
|
|
||||||
@ -135,7 +175,7 @@ class iface():
|
|||||||
self.addr_family = None
|
self.addr_family = None
|
||||||
self.addr_method = None
|
self.addr_method = None
|
||||||
self.config = OrderedDict()
|
self.config = OrderedDict()
|
||||||
self.config_status = {}
|
self._config_status = {}
|
||||||
self.state = ifaceState.NEW
|
self.state = ifaceState.NEW
|
||||||
self.status = ifaceStatus.UNKNOWN
|
self.status = ifaceStatus.UNKNOWN
|
||||||
self.flags = 0x0
|
self.flags = 0x0
|
||||||
@ -146,7 +186,7 @@ class iface():
|
|||||||
self.auto = False
|
self.auto = False
|
||||||
self.classes = []
|
self.classes = []
|
||||||
self.env = None
|
self.env = None
|
||||||
self.raw_lines = []
|
self.raw_config = []
|
||||||
self.linkstate = None
|
self.linkstate = None
|
||||||
|
|
||||||
def inc_refcnt(self):
|
def inc_refcnt(self):
|
||||||
@ -155,38 +195,8 @@ class iface():
|
|||||||
def dec_refcnt(self):
|
def dec_refcnt(self):
|
||||||
self.refcnt -= 1
|
self.refcnt -= 1
|
||||||
|
|
||||||
def get_refcnt(self):
|
|
||||||
return self.refcnt
|
|
||||||
|
|
||||||
def set_refcnt(self, cnt):
|
|
||||||
self.refcnt = 0
|
|
||||||
|
|
||||||
def set_name(self, name):
|
|
||||||
self.name = name
|
|
||||||
|
|
||||||
def get_name(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
def set_addr_family(self, family):
|
|
||||||
self.addr_family = family
|
|
||||||
|
|
||||||
def get_addr_family(self):
|
|
||||||
return self.addr_family
|
|
||||||
|
|
||||||
def set_addr_method(self, method):
|
|
||||||
self.addr_method = method
|
|
||||||
|
|
||||||
def get_addr_method(self):
|
|
||||||
return self.addr_method
|
|
||||||
|
|
||||||
def set_config(self, config_dict):
|
|
||||||
self.config = config_dict
|
|
||||||
|
|
||||||
def get_config(self):
|
|
||||||
return self.config
|
|
||||||
|
|
||||||
def is_config_present(self):
|
def is_config_present(self):
|
||||||
addr_method = self.get_addr_method()
|
addr_method = self.addr_method
|
||||||
if addr_method:
|
if addr_method:
|
||||||
if (addr_method.find('dhcp') != -1 or
|
if (addr_method.find('dhcp') != -1 or
|
||||||
addr_method.find('dhcp6') != -1):
|
addr_method.find('dhcp6') != -1):
|
||||||
@ -196,77 +206,20 @@ class iface():
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_auto(self):
|
|
||||||
return self.auto
|
|
||||||
|
|
||||||
def set_auto(self):
|
|
||||||
self.auto = True
|
|
||||||
|
|
||||||
def reset_auto(self):
|
|
||||||
self.auto = False
|
|
||||||
|
|
||||||
def get_classes(self):
|
|
||||||
return self.classes
|
|
||||||
|
|
||||||
def set_classes(self, classes):
|
|
||||||
""" sets interface class list to the one passed as arg """
|
|
||||||
self.classes = classes
|
|
||||||
|
|
||||||
def set_class(self, classname):
|
def set_class(self, classname):
|
||||||
""" Appends a class to the list """
|
""" Appends a class to the list """
|
||||||
self.classes.append(classname)
|
self.classes.append(classname)
|
||||||
|
|
||||||
def belongs_to_class(self, intfclass):
|
|
||||||
if intfclass in self.classes:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def set_priv_flags(self, priv_flags):
|
|
||||||
self.priv_flags = priv_flags
|
|
||||||
|
|
||||||
def get_priv_flags(self):
|
|
||||||
return self.priv_flags
|
|
||||||
|
|
||||||
def get_state(self):
|
|
||||||
return self.state
|
|
||||||
|
|
||||||
def get_state_str(self):
|
|
||||||
return ifaceState.to_str(self.state)
|
|
||||||
|
|
||||||
def set_state(self, state):
|
|
||||||
self.state = state
|
|
||||||
|
|
||||||
def get_status(self):
|
|
||||||
return self.status
|
|
||||||
|
|
||||||
def get_status_str(self):
|
|
||||||
return ifaceStatus.to_str(self.status)
|
|
||||||
|
|
||||||
def set_status(self, status):
|
|
||||||
self.status = status
|
|
||||||
|
|
||||||
def set_state_n_status(self, state, status):
|
def set_state_n_status(self, state, status):
|
||||||
self.state = state
|
self.state = state
|
||||||
self.status = status
|
self.status = status
|
||||||
|
|
||||||
def state_str_to_hex(self, state_str):
|
|
||||||
return self.state_str_map.get(state_str)
|
|
||||||
|
|
||||||
def set_flag(self, flag):
|
def set_flag(self, flag):
|
||||||
self.flags |= flag
|
self.flags |= flag
|
||||||
|
|
||||||
def clear_flag(self, flag):
|
def clear_flag(self, flag):
|
||||||
self.flags &= ~flag
|
self.flags &= ~flag
|
||||||
|
|
||||||
def set_lowerifaces(self, dlist):
|
|
||||||
self.lowerifaces = dlist
|
|
||||||
|
|
||||||
def get_lowerifaces(self):
|
|
||||||
return self.lowerifaces
|
|
||||||
|
|
||||||
def set_upperifaces(self, dlist):
|
|
||||||
self.upperifaces = dlist
|
|
||||||
|
|
||||||
def add_to_upperifaces(self, upperifacename):
|
def add_to_upperifaces(self, upperifacename):
|
||||||
if self.upperifaces:
|
if self.upperifaces:
|
||||||
if upperifacename not in self.upperifaces:
|
if upperifacename not in self.upperifaces:
|
||||||
@ -274,31 +227,17 @@ class iface():
|
|||||||
else:
|
else:
|
||||||
self.upperifaces = [upperifacename]
|
self.upperifaces = [upperifacename]
|
||||||
|
|
||||||
def get_upperifaces(self):
|
|
||||||
return self.upperifaces
|
|
||||||
|
|
||||||
def set_linkstate(self, l):
|
|
||||||
self.linkstate = l
|
|
||||||
|
|
||||||
def get_linkstate(self):
|
|
||||||
return self.linkstate
|
|
||||||
|
|
||||||
def get_attr_value(self, attr_name):
|
def get_attr_value(self, attr_name):
|
||||||
config = self.get_config()
|
return self.config.get(attr_name)
|
||||||
|
|
||||||
return config.get(attr_name)
|
|
||||||
|
|
||||||
def get_attr_value_first(self, attr_name):
|
def get_attr_value_first(self, attr_name):
|
||||||
config = self.get_config()
|
attr_value_list = self.config.get(attr_name)
|
||||||
attr_value_list = config.get(attr_name)
|
|
||||||
if attr_value_list:
|
if attr_value_list:
|
||||||
return attr_value_list[0]
|
return attr_value_list[0]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_attr_value_n(self, attr_name, attr_index):
|
def get_attr_value_n(self, attr_name, attr_index):
|
||||||
config = self.get_config()
|
attr_value_list = self.config.get(attr_name)
|
||||||
|
|
||||||
attr_value_list = config.get(attr_name)
|
|
||||||
if attr_value_list:
|
if attr_value_list:
|
||||||
try:
|
try:
|
||||||
return attr_value_list[attr_index]
|
return attr_value_list[attr_index]
|
||||||
@ -306,30 +245,24 @@ class iface():
|
|||||||
return None
|
return None
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
def get_env(self):
|
def get_env(self):
|
||||||
if not self.env:
|
if not self.env:
|
||||||
self.generate_env()
|
self.generate_env()
|
||||||
return self.env
|
return self.env
|
||||||
|
|
||||||
def set_env(self, env):
|
|
||||||
self.env = env
|
|
||||||
|
|
||||||
def generate_env(self):
|
def generate_env(self):
|
||||||
env = {}
|
env = {}
|
||||||
config = self.get_config()
|
config = self.config
|
||||||
env['IFACE'] = self.get_name()
|
env['IFACE'] = self.name
|
||||||
for attr, attr_value in config.items():
|
for attr, attr_value in config.items():
|
||||||
attr_env_name = 'IF_%s' %attr.upper()
|
attr_env_name = 'IF_%s' %attr.upper()
|
||||||
env[attr_env_name] = attr_value[0]
|
env[attr_env_name] = attr_value[0]
|
||||||
|
|
||||||
if env:
|
if env:
|
||||||
self.set_env(env)
|
self.env = env
|
||||||
|
|
||||||
def update_config(self, attr_name, attr_value):
|
def update_config(self, attr_name, attr_value):
|
||||||
if not self.config.get(attr_name):
|
self.config.setdefault(attr_name, []).append(attr_value)
|
||||||
self.config[attr_name] = [attr_value]
|
|
||||||
else:
|
|
||||||
self.config[attr_name].append(attr_value)
|
|
||||||
|
|
||||||
def update_config_dict(self, attrdict):
|
def update_config_dict(self, attrdict):
|
||||||
self.config.update(attrdict)
|
self.config.update(attrdict)
|
||||||
@ -338,29 +271,25 @@ class iface():
|
|||||||
if not attr_value:
|
if not attr_value:
|
||||||
attr_value = ''
|
attr_value = ''
|
||||||
|
|
||||||
if self.config.get(attr_name):
|
self.config.setdefault(attr_name, []).append(attr_value)
|
||||||
self.config[attr_name].append(attr_value)
|
self._config_status.setdefault(attr_name, []).append(attr_status)
|
||||||
self.config_status[attr_name].append(attr_status)
|
|
||||||
else:
|
|
||||||
self.config[attr_name] = [attr_value]
|
|
||||||
self.config_status[attr_name] = [attr_status]
|
|
||||||
|
|
||||||
# set global iface state
|
# set global iface state
|
||||||
if attr_status:
|
if attr_status:
|
||||||
self.set_status(ifaceStatus.ERROR)
|
self.status = ifaceStatus.ERROR
|
||||||
elif self.get_status() != ifaceStatus.ERROR:
|
elif self.status != ifaceStatus.ERROR:
|
||||||
# Not already error, mark success
|
# Not already error, mark success
|
||||||
self.set_status(ifaceStatus.SUCCESS)
|
self.status = ifaceStatus.SUCCESS
|
||||||
|
|
||||||
def get_config_attr_status(self, attr_name, idx=0):
|
def get_config_attr_status(self, attr_name, idx=0):
|
||||||
self.config_status.get(attr_name, [])[idx]
|
return self._config_status.get(attr_name, [])[idx]
|
||||||
|
|
||||||
def get_config_attr_status_str(self, attr_name, idx=0):
|
def get_config_attr_status_str(self, attr_name, idx=0):
|
||||||
ret = self.config_status.get(attr_name, [])[idx]
|
ret = self.get_config_attr_status(attr_name, idx)
|
||||||
if ret:
|
if ret:
|
||||||
return crossmark
|
return _crossmark
|
||||||
else:
|
else:
|
||||||
return tickmark
|
return _tickmark
|
||||||
|
|
||||||
def is_different(self, dstiface):
|
def is_different(self, dstiface):
|
||||||
if self.name != dstiface.name: return True
|
if self.name != dstiface.name: return True
|
||||||
@ -368,13 +297,10 @@ class iface():
|
|||||||
if self.addr_method != dstiface.addr_method: return True
|
if self.addr_method != dstiface.addr_method: return True
|
||||||
if self.auto != dstiface.auto: return True
|
if self.auto != dstiface.auto: return True
|
||||||
if self.classes != dstiface.classes: return True
|
if self.classes != dstiface.classes: return True
|
||||||
|
|
||||||
if any(True for k in self.config if k not in dstiface.config):
|
if any(True for k in self.config if k not in dstiface.config):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if any(True for k,v in self.config.items()
|
if any(True for k,v in self.config.items()
|
||||||
if v != dstiface.config.get(k)): return True
|
if v != dstiface.config.get(k)): return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
@ -384,17 +310,17 @@ class iface():
|
|||||||
del odict['lowerifaces']
|
del odict['lowerifaces']
|
||||||
del odict['upperifaces']
|
del odict['upperifaces']
|
||||||
del odict['refcnt']
|
del odict['refcnt']
|
||||||
del odict['config_status']
|
del odict['_config_status']
|
||||||
del odict['flags']
|
del odict['flags']
|
||||||
del odict['priv_flags']
|
del odict['priv_flags']
|
||||||
del odict['raw_lines']
|
del odict['raw_config']
|
||||||
del odict['linkstate']
|
del odict['linkstate']
|
||||||
del odict['env']
|
del odict['env']
|
||||||
return odict
|
return odict
|
||||||
|
|
||||||
def __setstate__(self, dict):
|
def __setstate__(self, dict):
|
||||||
self.__dict__.update(dict)
|
self.__dict__.update(dict)
|
||||||
self.config_status = {}
|
self._config_status = {}
|
||||||
self.state = ifaceState.NEW
|
self.state = ifaceState.NEW
|
||||||
self.status = ifaceStatus.UNKNOWN
|
self.status = ifaceStatus.UNKNOWN
|
||||||
self.refcnt = 0
|
self.refcnt = 0
|
||||||
@ -404,34 +330,34 @@ class iface():
|
|||||||
self.linkstate = None
|
self.linkstate = None
|
||||||
self.env = None
|
self.env = None
|
||||||
self.priv_flags = 0
|
self.priv_flags = 0
|
||||||
self.raw_lines = []
|
self.raw_config = []
|
||||||
self.flags |= self.PICKLED
|
self.flags |= self._PICKLED
|
||||||
|
|
||||||
def dump_raw(self, logger):
|
def dump_raw(self, logger):
|
||||||
indent = ' '
|
indent = ' '
|
||||||
print (self.raw_lines[0])
|
print (self.raw_config[0])
|
||||||
for i in range(1, len(self.raw_lines)):
|
for i in range(1, len(self.raw_config)):
|
||||||
print (indent + self.raw_lines[i])
|
print (indent + self.raw_config[i])
|
||||||
|
|
||||||
def dump(self, logger):
|
def dump(self, logger):
|
||||||
indent = '\t'
|
indent = '\t'
|
||||||
logger.info(self.get_name() + ' : {')
|
logger.info(self.name + ' : {')
|
||||||
logger.info(indent + 'family: %s' %self.get_addr_family())
|
logger.info(indent + 'family: %s' %self.addr_family)
|
||||||
logger.info(indent + 'method: %s' %self.get_addr_method())
|
logger.info(indent + 'method: %s' %self.addr_method)
|
||||||
logger.info(indent + 'flags: %x' %self.flags)
|
logger.info(indent + 'flags: %x' %self.flags)
|
||||||
logger.info(indent + 'state: %s'
|
logger.info(indent + 'state: %s'
|
||||||
%ifaceState.to_str(self.get_state()))
|
%ifaceState.to_str(self.state))
|
||||||
logger.info(indent + 'status: %s'
|
logger.info(indent + 'status: %s'
|
||||||
%ifaceStatus.to_str(self.get_status()))
|
%ifaceStatus.to_str(self.status))
|
||||||
logger.info(indent + 'refcnt: %d' %self.get_refcnt())
|
logger.info(indent + 'refcnt: %d' %self.refcnt)
|
||||||
d = self.get_lowerifaces()
|
d = self.lowerifaces
|
||||||
if d:
|
if d:
|
||||||
logger.info(indent + 'lowerdevs: %s' %str(d))
|
logger.info(indent + 'lowerdevs: %s' %str(d))
|
||||||
else:
|
else:
|
||||||
logger.info(indent + 'lowerdevs: None')
|
logger.info(indent + 'lowerdevs: None')
|
||||||
|
|
||||||
logger.info(indent + 'config: ')
|
logger.info(indent + 'config: ')
|
||||||
config = self.get_config()
|
config = self.config
|
||||||
if config:
|
if config:
|
||||||
logger.info(indent + indent + str(config))
|
logger.info(indent + indent + str(config))
|
||||||
logger.info('}')
|
logger.info('}')
|
||||||
@ -439,15 +365,15 @@ class iface():
|
|||||||
def dump_pretty(self, with_status=False):
|
def dump_pretty(self, with_status=False):
|
||||||
indent = '\t'
|
indent = '\t'
|
||||||
outbuf = ''
|
outbuf = ''
|
||||||
if self.get_auto():
|
if self.auto:
|
||||||
outbuf += 'auto %s\n' %self.get_name()
|
outbuf += 'auto %s\n' %self.name
|
||||||
outbuf += 'iface %s' %self.get_name()
|
outbuf += 'iface %s' %self.name
|
||||||
if self.get_addr_family():
|
if self.addr_family:
|
||||||
outbuf += ' %s' %self.get_addr_family()
|
outbuf += ' %s' %self.addr_family
|
||||||
if self.get_addr_method():
|
if self.addr_method:
|
||||||
outbuf += ' %s' %self.get_addr_method()
|
outbuf += ' %s' %self.addr_method
|
||||||
outbuf += '\n'
|
outbuf += '\n'
|
||||||
config = self.get_config()
|
config = self.config
|
||||||
if config:
|
if config:
|
||||||
for cname, cvaluelist in config.items():
|
for cname, cvaluelist in config.items():
|
||||||
idx = 0
|
idx = 0
|
||||||
@ -458,7 +384,6 @@ class iface():
|
|||||||
else:
|
else:
|
||||||
outbuf += indent + '%s %s\n' %(cname, cv)
|
outbuf += indent + '%s %s\n' %(cname, cv)
|
||||||
idx += 1
|
idx += 1
|
||||||
|
|
||||||
print outbuf
|
print outbuf
|
||||||
|
|
||||||
def dump_json(self, with_status=False):
|
def dump_json(self, with_status=False):
|
||||||
|
@ -79,12 +79,12 @@ class ifupdownMain(ifupdownBase):
|
|||||||
|
|
||||||
# Handlers for ops that ifupdown2 owns
|
# Handlers for ops that ifupdown2 owns
|
||||||
def run_up(self, ifaceobj):
|
def run_up(self, ifaceobj):
|
||||||
ifacename = ifaceobj.get_name()
|
ifacename = ifaceobj.name
|
||||||
if self.link_exists(ifacename):
|
if self.link_exists(ifacename):
|
||||||
self.link_up(ifacename)
|
self.link_up(ifacename)
|
||||||
|
|
||||||
def run_down(self, ifaceobj):
|
def run_down(self, ifaceobj):
|
||||||
ifacename = ifaceobj.get_name()
|
ifacename = ifaceobj.name
|
||||||
if self.link_exists(ifacename):
|
if self.link_exists(ifacename):
|
||||||
self.link_down(ifacename)
|
self.link_down(ifacename)
|
||||||
|
|
||||||
@ -225,15 +225,15 @@ class ifupdownMain(ifupdownBase):
|
|||||||
return self.ifaceobjdict.get(ifacename)[-1]
|
return self.ifaceobjdict.get(ifacename)[-1]
|
||||||
|
|
||||||
def create_n_save_ifaceobjcurr(self, ifaceobj):
|
def create_n_save_ifaceobjcurr(self, ifaceobj):
|
||||||
ifacename = ifaceobj.get_name()
|
ifacename = ifaceobj.name
|
||||||
ifaceobjcurr = self.get_ifaceobjcurr(ifacename)
|
ifaceobjcurr = self.get_ifaceobjcurr(ifacename)
|
||||||
if ifaceobjcurr:
|
if ifaceobjcurr:
|
||||||
return ifaceobjcurr
|
return ifaceobjcurr
|
||||||
|
|
||||||
ifaceobjcurr = iface()
|
ifaceobjcurr = iface()
|
||||||
ifaceobjcurr.set_name(ifacename)
|
ifaceobjcurr.name = ifacename
|
||||||
ifaceobjcurr.set_lowerifaces(ifaceobj.get_lowerifaces())
|
ifaceobjcurr.lowerifaces = ifaceobj.lowerifaces
|
||||||
ifaceobjcurr.set_priv_flags(ifaceobj.get_priv_flags())
|
ifaceobjcurr.priv_flags = ifaceobj.priv_flags
|
||||||
self.ifaceobjcurrdict[ifacename] = ifaceobjcurr
|
self.ifaceobjcurrdict[ifacename] = ifaceobjcurr
|
||||||
|
|
||||||
return ifaceobjcurr
|
return ifaceobjcurr
|
||||||
@ -247,8 +247,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
def get_iface_status(self, ifacename):
|
def get_iface_status(self, ifacename):
|
||||||
ifaceobjs = self.get_ifaceobjs(ifacename)
|
ifaceobjs = self.get_ifaceobjs(ifacename)
|
||||||
for i in ifaceobjs:
|
for i in ifaceobjs:
|
||||||
if i.get_status() != ifaceStatus.SUCCESS:
|
if i.status != ifaceStatus.SUCCESS:
|
||||||
return i.get_status()
|
return i.status
|
||||||
return ifaceStatus.SUCCESS
|
return ifaceStatus.SUCCESS
|
||||||
|
|
||||||
def get_iface_refcnt(self, ifacename):
|
def get_iface_refcnt(self, ifacename):
|
||||||
@ -257,8 +257,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
if not ifaceobjs:
|
if not ifaceobjs:
|
||||||
return 0
|
return 0
|
||||||
for i in ifaceobjs:
|
for i in ifaceobjs:
|
||||||
if i.get_refcnt() > max:
|
if i.refcnt > max:
|
||||||
max = i.get_refcnt()
|
max = i.refcnt
|
||||||
return max
|
return max
|
||||||
|
|
||||||
def create_n_save_ifaceobj(self, ifacename, priv_flags=None,
|
def create_n_save_ifaceobj(self, ifacename, priv_flags=None,
|
||||||
@ -268,9 +268,9 @@ class ifupdownMain(ifupdownBase):
|
|||||||
devices without any user specified configuration.
|
devices without any user specified configuration.
|
||||||
"""
|
"""
|
||||||
ifaceobj = iface()
|
ifaceobj = iface()
|
||||||
ifaceobj.set_name(ifacename)
|
ifaceobj.name = ifacename
|
||||||
ifaceobj.priv_flags = priv_flags
|
ifaceobj.priv_flags = priv_flags
|
||||||
ifaceobj.set_auto()
|
ifaceobj.auto = True
|
||||||
if increfcnt:
|
if increfcnt:
|
||||||
ifaceobj.inc_refcnt()
|
ifaceobj.inc_refcnt()
|
||||||
self.ifaceobjdict[ifacename] = [ifaceobj]
|
self.ifaceobjdict[ifacename] = [ifaceobj]
|
||||||
@ -365,7 +365,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
dlist = module.get_dependent_ifacenames(ifaceobj,
|
dlist = module.get_dependent_ifacenames(ifaceobj,
|
||||||
self.ifaceobjdict.keys())
|
self.ifaceobjdict.keys())
|
||||||
if dlist:
|
if dlist:
|
||||||
self.logger.debug('%s: ' %ifaceobj.get_name() +
|
self.logger.debug('%s: ' %ifaceobj.name +
|
||||||
'got lowerifaces/dependents: %s' %str(dlist))
|
'got lowerifaces/dependents: %s' %str(dlist))
|
||||||
break
|
break
|
||||||
return dlist
|
return dlist
|
||||||
@ -385,26 +385,26 @@ class ifupdownMain(ifupdownBase):
|
|||||||
ifaceobj = self.get_ifaceobj_first(i)
|
ifaceobj = self.get_ifaceobj_first(i)
|
||||||
if not ifaceobj:
|
if not ifaceobj:
|
||||||
continue
|
continue
|
||||||
dlist = ifaceobj.get_lowerifaces()
|
dlist = ifaceobj.lowerifaces
|
||||||
if not dlist:
|
if not dlist:
|
||||||
dlist = self.query_dependents(ifaceobj, ops)
|
dlist = self.query_dependents(ifaceobj, ops)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
if dlist:
|
if dlist:
|
||||||
self.preprocess_dependency_list(ifaceobj.get_name(),
|
self.preprocess_dependency_list(ifaceobj.name,
|
||||||
dlist, ops)
|
dlist, ops)
|
||||||
self.logger.debug('%s: lowerifaces/dependents after processing: %s'
|
self.logger.debug('%s: lowerifaces/dependents after processing: %s'
|
||||||
%(i, str(dlist)))
|
%(i, str(dlist)))
|
||||||
ifaceobj.set_lowerifaces(dlist)
|
ifaceobj.lowerifaces = dlist
|
||||||
[iqueue.append(d) for d in dlist]
|
[iqueue.append(d) for d in dlist]
|
||||||
if not self.dependency_graph.get(i):
|
if not self.dependency_graph.get(i):
|
||||||
self.dependency_graph[i] = dlist
|
self.dependency_graph[i] = dlist
|
||||||
|
|
||||||
def _save_iface(self, ifaceobj):
|
def _save_iface(self, ifaceobj):
|
||||||
if not self.ifaceobjdict.get(ifaceobj.get_name()):
|
if not self.ifaceobjdict.get(ifaceobj.name):
|
||||||
self.ifaceobjdict[ifaceobj.get_name()] = [ifaceobj]
|
self.ifaceobjdict[ifaceobj.name] = [ifaceobj]
|
||||||
else:
|
else:
|
||||||
self.ifaceobjdict[ifaceobj.get_name()].append(ifaceobj)
|
self.ifaceobjdict[ifaceobj.name].append(ifaceobj)
|
||||||
|
|
||||||
def _module_syntax_checker(self, attrname, attrval):
|
def _module_syntax_checker(self, attrname, attrval):
|
||||||
for m, mdict in self.module_attrs.items():
|
for m, mdict in self.module_attrs.items():
|
||||||
@ -618,15 +618,15 @@ class ifupdownMain(ifupdownBase):
|
|||||||
# We check classes first
|
# We check classes first
|
||||||
if allow_classes:
|
if allow_classes:
|
||||||
for i in ifaceobjs:
|
for i in ifaceobjs:
|
||||||
if i.get_classes():
|
if i.classes:
|
||||||
common = Set([allow_classes]).intersection(
|
common = Set([allow_classes]).intersection(
|
||||||
Set(i.get_classes()))
|
Set(i.classes))
|
||||||
if common:
|
if common:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
if auto:
|
if auto:
|
||||||
for i in ifaceobjs:
|
for i in ifaceobjs:
|
||||||
if i.get_auto():
|
if i.auto:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@ -637,8 +637,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
cenv = None
|
cenv = None
|
||||||
iface_env = ifaceobj.get_env()
|
iface_env = ifaceobj.env
|
||||||
if iface_env is not None:
|
if iface_env:
|
||||||
cenv = os.environ
|
cenv = os.environ
|
||||||
if cenv:
|
if cenv:
|
||||||
cenv.update(iface_env)
|
cenv.update(iface_env)
|
||||||
@ -667,7 +667,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self.read_iface_config()
|
self.read_iface_config()
|
||||||
except Exception, e:
|
except Exception:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
if ifacenames:
|
if ifacenames:
|
||||||
@ -936,7 +936,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
ifaceobj.dump_raw(self.logger)
|
ifaceobj.dump_raw(self.logger)
|
||||||
print '\n'
|
print '\n'
|
||||||
if self.WITH_DEPENDS:
|
if self.WITH_DEPENDS:
|
||||||
dlist = ifaceobj.get_lowerifaces()
|
dlist = ifaceobj.lowerifaces
|
||||||
if not dlist: continue
|
if not dlist: continue
|
||||||
self.print_ifaceobjs_pretty(dlist, format)
|
self.print_ifaceobjs_pretty(dlist, format)
|
||||||
|
|
||||||
@ -950,7 +950,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
else:
|
else:
|
||||||
ifaceobj.dump_pretty()
|
ifaceobj.dump_pretty()
|
||||||
if self.WITH_DEPENDS:
|
if self.WITH_DEPENDS:
|
||||||
dlist = ifaceobj.get_lowerifaces()
|
dlist = ifaceobj.lowerifaces
|
||||||
if not dlist: continue
|
if not dlist: continue
|
||||||
self.print_ifaceobjs_pretty(dlist, format)
|
self.print_ifaceobjs_pretty(dlist, format)
|
||||||
|
|
||||||
@ -971,12 +971,12 @@ class ifupdownMain(ifupdownBase):
|
|||||||
for i in ifacenames:
|
for i in ifacenames:
|
||||||
ifaceobj = self.get_ifaceobjcurr(i)
|
ifaceobj = self.get_ifaceobjcurr(i)
|
||||||
if not ifaceobj: continue
|
if not ifaceobj: continue
|
||||||
if ifaceobj.get_status() == ifaceStatus.NOTFOUND:
|
if ifaceobj.status == ifaceStatus.NOTFOUND:
|
||||||
print 'iface %s %s\n' %(ifaceobj.get_name(),
|
print 'iface %s (%s)\n' %(ifaceobj.name,
|
||||||
ifaceStatus.to_str(ifaceStatus.NOTFOUND))
|
ifaceStatus.to_str(ifaceStatus.NOTFOUND))
|
||||||
ret = 1
|
ret = 1
|
||||||
continue
|
continue
|
||||||
elif ifaceobj.get_status() == ifaceStatus.ERROR:
|
elif ifaceobj.status == ifaceStatus.ERROR:
|
||||||
ret = 1
|
ret = 1
|
||||||
|
|
||||||
if (self.is_ifaceobj_noconfig(ifaceobj)):
|
if (self.is_ifaceobj_noconfig(ifaceobj)):
|
||||||
@ -988,7 +988,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
ifaceobj.dump_pretty(with_status=True)
|
ifaceobj.dump_pretty(with_status=True)
|
||||||
|
|
||||||
if self.WITH_DEPENDS:
|
if self.WITH_DEPENDS:
|
||||||
dlist = ifaceobj.get_lowerifaces()
|
dlist = ifaceobj.lowerifaces
|
||||||
if not dlist: continue
|
if not dlist: continue
|
||||||
self.print_ifaceobjscurr_pretty(dlist, format)
|
self.print_ifaceobjscurr_pretty(dlist, format)
|
||||||
return ret
|
return ret
|
||||||
@ -996,8 +996,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
def print_ifaceobjsrunning_pretty(self, ifacenames, format='native'):
|
def print_ifaceobjsrunning_pretty(self, ifacenames, format='native'):
|
||||||
for i in ifacenames:
|
for i in ifacenames:
|
||||||
ifaceobj = self.get_ifaceobj_first(i)
|
ifaceobj = self.get_ifaceobj_first(i)
|
||||||
if ifaceobj.get_status() == ifaceStatus.NOTFOUND:
|
if ifaceobj.status == ifaceStatus.NOTFOUND:
|
||||||
print 'iface %s' %ifaceobj.get_name() + ' (not found)\n'
|
print 'iface %s' %ifaceobj.name + ' (not found)\n'
|
||||||
continue
|
continue
|
||||||
if not ifaceobj.is_config_present():
|
if not ifaceobj.is_config_present():
|
||||||
continue
|
continue
|
||||||
@ -1006,7 +1006,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
else:
|
else:
|
||||||
ifaceobj.dump_pretty()
|
ifaceobj.dump_pretty()
|
||||||
if self.WITH_DEPENDS:
|
if self.WITH_DEPENDS:
|
||||||
dlist = ifaceobj.get_lowerifaces()
|
dlist = ifaceobj.lowerifaces
|
||||||
if not dlist: continue
|
if not dlist: continue
|
||||||
self.print_ifaceobjsrunning_pretty(dlist, format)
|
self.print_ifaceobjsrunning_pretty(dlist, format)
|
||||||
return
|
return
|
||||||
|
@ -54,7 +54,7 @@ class networkInterfaces():
|
|||||||
allow_class = words[0].split('-')[1]
|
allow_class = words[0].split('-')[1]
|
||||||
ifacenames = words[1:]
|
ifacenames = words[1:]
|
||||||
|
|
||||||
if self.allow_classes.get(allow_class) is not None:
|
if self.allow_classes.get(allow_class):
|
||||||
for i in ifacenames:
|
for i in ifacenames:
|
||||||
self.allow_classes[allow_class].append(i)
|
self.allow_classes[allow_class].append(i)
|
||||||
else:
|
else:
|
||||||
@ -65,7 +65,7 @@ class networkInterfaces():
|
|||||||
# Support regex
|
# Support regex
|
||||||
self.logger.debug('processing sourced line ..\'%s\'' %lines[cur_idx])
|
self.logger.debug('processing sourced line ..\'%s\'' %lines[cur_idx])
|
||||||
sourced_file = lines[cur_idx].split(' ', 2)[1]
|
sourced_file = lines[cur_idx].split(' ', 2)[1]
|
||||||
if sourced_file is not None:
|
if sourced_file:
|
||||||
for f in glob.glob(sourced_file):
|
for f in glob.glob(sourced_file):
|
||||||
self.read_file(f)
|
self.read_file(f)
|
||||||
else:
|
else:
|
||||||
@ -112,7 +112,7 @@ class networkInterfaces():
|
|||||||
iface_attrs = iface_line.split()
|
iface_attrs = iface_line.split()
|
||||||
ifacename = iface_attrs[1]
|
ifacename = iface_attrs[1]
|
||||||
|
|
||||||
ifaceobj.raw_lines.append(iface_line)
|
ifaceobj.raw_config.append(iface_line)
|
||||||
|
|
||||||
iface_config = collections.OrderedDict()
|
iface_config = collections.OrderedDict()
|
||||||
for line_idx in range(cur_idx + 1, len(lines)):
|
for line_idx in range(cur_idx + 1, len(lines)):
|
||||||
@ -125,7 +125,7 @@ class networkInterfaces():
|
|||||||
line_idx -= 1
|
line_idx -= 1
|
||||||
break
|
break
|
||||||
|
|
||||||
ifaceobj.raw_lines.append(l)
|
ifaceobj.raw_config.append(l)
|
||||||
|
|
||||||
# preprocess vars (XXX: only preprocesses $IFACE for now)
|
# preprocess vars (XXX: only preprocesses $IFACE for now)
|
||||||
l = re.sub(r'\$IFACE', ifacename, l)
|
l = re.sub(r'\$IFACE', ifacename, l)
|
||||||
@ -149,24 +149,22 @@ class networkInterfaces():
|
|||||||
|
|
||||||
# Create iface object
|
# Create iface object
|
||||||
if ifacename.find(':') != -1:
|
if ifacename.find(':') != -1:
|
||||||
ifaceobj.set_name(ifacename.split(':')[0])
|
ifaceobj.name = ifacename.split(':')[0]
|
||||||
else:
|
else:
|
||||||
ifaceobj.set_name(ifacename)
|
ifaceobj.name = ifacename
|
||||||
|
|
||||||
ifaceobj.set_config(iface_config)
|
ifaceobj.config = iface_config
|
||||||
ifaceobj.generate_env()
|
ifaceobj.generate_env()
|
||||||
if len(iface_attrs) > 2:
|
if len(iface_attrs) > 2:
|
||||||
ifaceobj.set_addr_family(iface_attrs[2])
|
ifaceobj.addr_family = iface_attrs[2]
|
||||||
ifaceobj.set_addr_method(iface_attrs[3])
|
ifaceobj.addr_method = iface_attrs[3]
|
||||||
|
|
||||||
if ifaceobj.get_name() in self.auto_ifaces:
|
if ifaceobj.name in self.auto_ifaces:
|
||||||
ifaceobj.set_auto()
|
ifaceobj.auto = True
|
||||||
|
|
||||||
classes = ifaceobj.set_classes(
|
classes = self.get_allow_classes_for_iface(ifaceobj.name)
|
||||||
self.get_allow_classes_for_iface(ifaceobj.get_name()))
|
|
||||||
if classes:
|
if classes:
|
||||||
for c in classes:
|
[ifaceobj.set_class(c) for c in classes]
|
||||||
ifaceobj.set_class(c)
|
|
||||||
|
|
||||||
# Call iface found callback
|
# Call iface found callback
|
||||||
self.callbacks.get('iface_found')(ifaceobj)
|
self.callbacks.get('iface_found')(ifaceobj)
|
||||||
@ -179,7 +177,6 @@ class networkInterfaces():
|
|||||||
'auto' : process_auto,
|
'auto' : process_auto,
|
||||||
'iface' : process_iface}
|
'iface' : process_iface}
|
||||||
|
|
||||||
|
|
||||||
def is_keyword(self, str):
|
def is_keyword(self, str):
|
||||||
|
|
||||||
# The additional split here is for allow- keyword
|
# The additional split here is for allow- keyword
|
||||||
@ -207,8 +204,8 @@ class networkInterfaces():
|
|||||||
line_idx = 0
|
line_idx = 0
|
||||||
lines_consumed = 0
|
lines_consumed = 0
|
||||||
|
|
||||||
raw_lines = filedata.split('\n')
|
raw_config = filedata.split('\n')
|
||||||
lines = [l.strip(' \n') for l in raw_lines]
|
lines = [l.strip(' \n') for l in raw_config]
|
||||||
|
|
||||||
while (line_idx < len(lines)):
|
while (line_idx < len(lines)):
|
||||||
lineno = lineno + 1
|
lineno = lineno + 1
|
||||||
|
@ -38,19 +38,19 @@ class ifaceScheduler():
|
|||||||
@classmethod
|
@classmethod
|
||||||
def run_iface_op(cls, ifupdownobj, ifaceobj, op, cenv):
|
def run_iface_op(cls, ifupdownobj, ifaceobj, op, cenv):
|
||||||
""" Runs sub operation on an interface """
|
""" Runs sub operation on an interface """
|
||||||
ifacename = ifaceobj.get_name()
|
ifacename = ifaceobj.name
|
||||||
|
|
||||||
if (cls._STATE_CHECK and
|
if (cls._STATE_CHECK and
|
||||||
(ifaceobj.get_state() >= ifaceState.from_str(op)) and
|
(ifaceobj.state >= ifaceState.from_str(op)) and
|
||||||
(ifaceobj.get_status() == ifaceStatus.SUCCESS)):
|
(ifaceobj.status == ifaceStatus.SUCCESS)):
|
||||||
ifupdownobj.logger.debug('%s: already in state %s' %(ifacename, op))
|
ifupdownobj.logger.debug('%s: already in state %s' %(ifacename, op))
|
||||||
return
|
return
|
||||||
|
|
||||||
# first run ifupdownobj handlers
|
# first run ifupdownobj handlers
|
||||||
handler = ifupdownobj.ops_handlers.get(op)
|
handler = ifupdownobj.ops_handlers.get(op)
|
||||||
if handler:
|
if handler:
|
||||||
addr_method = ifaceobj.get_addr_method()
|
if not ifaceobj.addr_method or (ifaceobj.addr_method and
|
||||||
if not addr_method or (addr_method and addr_method != 'manual'):
|
ifaceobj.addr_method != 'manual'):
|
||||||
handler(ifupdownobj, ifaceobj)
|
handler(ifupdownobj, ifaceobj)
|
||||||
|
|
||||||
if not ifupdownobj.ADDONS_ENABLE: return
|
if not ifupdownobj.ADDONS_ENABLE: return
|
||||||
@ -96,7 +96,7 @@ class ifaceScheduler():
|
|||||||
@classmethod
|
@classmethod
|
||||||
def run_iface_ops(cls, ifupdownobj, ifaceobj, ops):
|
def run_iface_ops(cls, ifupdownobj, ifaceobj, ops):
|
||||||
""" Runs all operations on an interface """
|
""" Runs all operations on an interface """
|
||||||
ifacename = ifaceobj.get_name()
|
ifacename = ifaceobj.name
|
||||||
# minor optimization. If operation is 'down', proceed only
|
# minor optimization. If operation is 'down', proceed only
|
||||||
# if interface exists in the system
|
# if interface exists in the system
|
||||||
if 'down' in ops[0] and not ifupdownobj.link_exists(ifacename):
|
if 'down' in ops[0] and not ifupdownobj.link_exists(ifacename):
|
||||||
@ -122,9 +122,9 @@ class ifaceScheduler():
|
|||||||
if 'up' in ops[0] and followdependents:
|
if 'up' in ops[0] and followdependents:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
ifacename = ifaceobj.get_name()
|
ifacename = ifaceobj.name
|
||||||
# Deal with upperdevs first
|
# Deal with upperdevs first
|
||||||
ulist = ifaceobj.get_upperifaces()
|
ulist = ifaceobj.upperifaces
|
||||||
if ulist:
|
if ulist:
|
||||||
tmpulist = ([u for u in ulist if u != parent] if parent
|
tmpulist = ([u for u in ulist if u != parent] if parent
|
||||||
else ulist)
|
else ulist)
|
||||||
@ -170,7 +170,7 @@ class ifaceScheduler():
|
|||||||
cls.run_iface_ops(ifupdownobj, ifaceobj, ops)
|
cls.run_iface_ops(ifupdownobj, ifaceobj, ops)
|
||||||
|
|
||||||
# Run lowerifaces or dependents
|
# Run lowerifaces or dependents
|
||||||
dlist = ifaceobj.get_lowerifaces()
|
dlist = ifaceobj.lowerifaces
|
||||||
if dlist:
|
if dlist:
|
||||||
ifupdownobj.logger.debug('%s:' %ifacename +
|
ifupdownobj.logger.debug('%s:' %ifacename +
|
||||||
' found dependents: %s' %str(dlist))
|
' found dependents: %s' %str(dlist))
|
||||||
@ -243,7 +243,7 @@ class ifaceScheduler():
|
|||||||
cls.run_iface_ops(ifupdownobj, ifaceobj, ops)
|
cls.run_iface_ops(ifupdownobj, ifaceobj, ops)
|
||||||
|
|
||||||
# Run upperifaces
|
# Run upperifaces
|
||||||
ulist = ifaceobj.get_upperifaces()
|
ulist = ifaceobj.upperifaces
|
||||||
if ulist:
|
if ulist:
|
||||||
ifupdownobj.logger.debug('%s:' %ifacename +
|
ifupdownobj.logger.debug('%s:' %ifacename +
|
||||||
' found upperifaces: %s' %str(ulist))
|
' found upperifaces: %s' %str(ulist))
|
||||||
@ -454,7 +454,7 @@ class ifaceScheduler():
|
|||||||
|
|
||||||
for ifaceobj in ifaceobjs:
|
for ifaceobj in ifaceobjs:
|
||||||
# Run dependents
|
# Run dependents
|
||||||
dlist = ifaceobj.get_lowerifaces()
|
dlist = ifaceobj.lowerifaces
|
||||||
if dlist:
|
if dlist:
|
||||||
ifupdownobj.logger.debug('%s:' %ifacename +
|
ifupdownobj.logger.debug('%s:' %ifacename +
|
||||||
' found dependents: %s' %str(dlist))
|
' found dependents: %s' %str(dlist))
|
||||||
|
@ -54,7 +54,7 @@ class stateManager():
|
|||||||
self.state_file = self.state_dir + self.state_filename
|
self.state_file = self.state_dir + self.state_filename
|
||||||
|
|
||||||
def save_ifaceobj(self, ifaceobj):
|
def save_ifaceobj(self, ifaceobj):
|
||||||
self.ifaceobjdict.setdefault(ifaceobj.get_name(),
|
self.ifaceobjdict.setdefault(ifaceobj.name,
|
||||||
[]).append(ifaceobj)
|
[]).append(ifaceobj)
|
||||||
|
|
||||||
def read_saved_state(self, filename=None):
|
def read_saved_state(self, filename=None):
|
||||||
@ -78,8 +78,8 @@ class stateManager():
|
|||||||
return self.ifaceobjdict.get(ifacename)
|
return self.ifaceobjdict.get(ifacename)
|
||||||
|
|
||||||
def compare_iface_state(ifaceobj1, ifaceobj2):
|
def compare_iface_state(ifaceobj1, ifaceobj2):
|
||||||
ifaceobj1_state = ifaceobj1.get_state()
|
ifaceobj1_state = ifaceobj1.state
|
||||||
ifaceobj2_state = ifaceobj2.get_state()
|
ifaceobj2_state = ifaceobj2.state
|
||||||
|
|
||||||
if ifaceobj1_state < ifaceobj2_state:
|
if ifaceobj1_state < ifaceobj2_state:
|
||||||
return -1
|
return -1
|
||||||
@ -94,54 +94,54 @@ class stateManager():
|
|||||||
state_arg = ifaceState.from_str(operation)
|
state_arg = ifaceState.from_str(operation)
|
||||||
if state_arg == ifaceState.UP:
|
if state_arg == ifaceState.UP:
|
||||||
old_ifaceobj = self.ifaceobjdict.get(ifacename)
|
old_ifaceobj = self.ifaceobjdict.get(ifacename)
|
||||||
if old_ifaceobj != None:
|
if old_ifaceobj:
|
||||||
# found old state for iface
|
# found old state for iface
|
||||||
# Check its state
|
# Check its state
|
||||||
if (old_ifaceobj.get_state() == state_arg and
|
if (old_ifaceobj.state == state_arg and
|
||||||
old_ifaceobj.get_status() == ifaceStatus.SUCCESS):
|
old_ifaceobj.status == ifaceStatus.SUCCESS):
|
||||||
self.statemsg = 'iface already up'
|
self.statemsg = 'iface already up'
|
||||||
return 0
|
return 0
|
||||||
elif state_arg == ifaceState.DOWN:
|
elif state_arg == ifaceState.DOWN:
|
||||||
old_ifaceobj = self.ifaceobjdict.get(ifname)
|
old_ifaceobj = self.ifaceobjdict.get(ifname)
|
||||||
if old_ifaceobj != None:
|
if old_ifaceobj:
|
||||||
# found old state for iface
|
# found old state for iface
|
||||||
# Check its state
|
# Check its state
|
||||||
if (old_ifaceobj.get_state() == state_arg and
|
if (old_ifaceobj.state == state_arg and
|
||||||
old_ifaceobj.get_status() == ifaceStatus.SUCCESS):
|
old_ifaceobj.status == ifaceStatus.SUCCESS):
|
||||||
self.statemsg = 'iface already down'
|
self.statemsg = 'iface already down'
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def ifaceobj_compare(self, ifaceobj_a, ifaceobj_b):
|
def ifaceobj_compare(self, ifaceobj_a, ifaceobj_b):
|
||||||
if ifaceobj_a.get_name() != ifaceobj_b.get_name():
|
if ifaceobj_a.name != ifaceobj_b.name:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if (ifaceobj_a.get_addr_family() is None and
|
if (not ifaceobj_a.addr_family and
|
||||||
ifaceobj_b.get_addr_family() is not None):
|
ifaceobj_b.addr_family):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if (ifaceobj_a.get_addr_family() is not None and
|
if (ifaceobj_a.addr_family and
|
||||||
ifaceobj_b.get_addr_family() is None):
|
not ifaceobj_b.addr_family):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if (ifaceobj_a.get_addr_family() is None and
|
if (not ifaceobj_a.addr_family and
|
||||||
ifaceobj_b.get_addr_family() is None):
|
not ifaceobj_b.addr_family):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if ifaceobj_a.get_addr_family() != ifaceobj_b.get_addr_family():
|
if ifaceobj_a.addr_family != ifaceobj_b.addr_family:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def ifaceobj_sync(self, ifaceobj):
|
def ifaceobj_sync(self, ifaceobj):
|
||||||
ifacename = ifaceobj.get_name()
|
ifacename = ifaceobj.name
|
||||||
self.logger.debug('%s: statemanager sync state' %ifacename)
|
self.logger.debug('%s: statemanager sync state' %ifacename)
|
||||||
old_ifaceobjs = self.ifaceobjdict.get(ifacename)
|
old_ifaceobjs = self.ifaceobjdict.get(ifacename)
|
||||||
if not old_ifaceobjs:
|
if not old_ifaceobjs:
|
||||||
self.ifaceobjdict[ifacename] = [ifaceobj]
|
self.ifaceobjdict[ifacename] = [ifaceobj]
|
||||||
else:
|
else:
|
||||||
if old_ifaceobjs[0].flags & iface.PICKLED:
|
if old_ifaceobjs[0].flags & iface._PICKLED:
|
||||||
del self.ifaceobjdict[ifacename]
|
del self.ifaceobjdict[ifacename]
|
||||||
self.ifaceobjdict[ifacename] = [ifaceobj]
|
self.ifaceobjdict[ifacename] = [ifaceobj]
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user