mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
remove dhclient -nw option + cleanup
Ticket: CM-1438 Reviewed By: Testing Done:
This commit is contained in:
@@ -29,13 +29,13 @@ class graph():
|
|||||||
if indegree == 0:
|
if indegree == 0:
|
||||||
Q.append(ifname)
|
Q.append(ifname)
|
||||||
|
|
||||||
while len(Q) != 0:
|
while len(Q):
|
||||||
# initialize queue
|
# initialize queue
|
||||||
x = Q.popleft()
|
x = Q.popleft()
|
||||||
|
|
||||||
# Get dependents of x
|
# Get dependents of x
|
||||||
dlist = dependency_graphs.get(x)
|
dlist = dependency_graphs.get(x)
|
||||||
if dlist == None or len(dlist) == 0:
|
if not dlist:
|
||||||
S.append(x)
|
S.append(x)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -60,13 +60,13 @@ class graph():
|
|||||||
|
|
||||||
Q.append(rootifname)
|
Q.append(rootifname)
|
||||||
|
|
||||||
while len(Q) != 0:
|
while len(Q):
|
||||||
# initialize queue
|
# initialize queue
|
||||||
x = Q.popleft()
|
x = Q.popleft()
|
||||||
|
|
||||||
# Get dependents of x
|
# Get dependents of x
|
||||||
dlist = dependency_graph.get(x)
|
dlist = dependency_graph.get(x)
|
||||||
if dlist == None or len(dlist) == 0:
|
if not dlist:
|
||||||
S.append(x)
|
S.append(x)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
33
pkg/iface.py
33
pkg/iface.py
@@ -190,15 +190,14 @@ class iface():
|
|||||||
|
|
||||||
def is_config_present(self):
|
def is_config_present(self):
|
||||||
addr_method = self.get_addr_method()
|
addr_method = self.get_addr_method()
|
||||||
if addr_method is not None:
|
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):
|
||||||
return True
|
return True
|
||||||
|
if not self.config:
|
||||||
if self.config is None:
|
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
return (len(self.config) != 0)
|
return True
|
||||||
|
|
||||||
def set_config_current(self, config_current):
|
def set_config_current(self, config_current):
|
||||||
self.config_current = config_current
|
self.config_current = config_current
|
||||||
@@ -298,7 +297,7 @@ class iface():
|
|||||||
def get_attr_value_first(self, attr_name):
|
def get_attr_value_first(self, attr_name):
|
||||||
config = self.get_config()
|
config = self.get_config()
|
||||||
attr_value_list = config.get(attr_name)
|
attr_value_list = config.get(attr_name)
|
||||||
if attr_value_list is not None:
|
if attr_value_list:
|
||||||
return attr_value_list[0]
|
return attr_value_list[0]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -306,16 +305,15 @@ class iface():
|
|||||||
config = self.get_config()
|
config = self.get_config()
|
||||||
|
|
||||||
attr_value_list = config.get(attr_name)
|
attr_value_list = config.get(attr_name)
|
||||||
if attr_value_list is not None:
|
if attr_value_list:
|
||||||
try:
|
try:
|
||||||
return attr_value_list[attr_index]
|
return attr_value_list[attr_index]
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_env(self):
|
def get_env(self):
|
||||||
if self.env is None or len(self.env) == 0:
|
if not self.env:
|
||||||
self.generate_env()
|
self.generate_env()
|
||||||
return self.env
|
return self.env
|
||||||
|
|
||||||
@@ -330,11 +328,11 @@ class iface():
|
|||||||
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 len(env) > 0:
|
if env:
|
||||||
self.set_env(env)
|
self.set_env(env)
|
||||||
|
|
||||||
def update_config(self, attr_name, attr_value):
|
def update_config(self, attr_name, attr_value):
|
||||||
if self.config.get(attr_name) is None:
|
if not self.config.get(attr_name):
|
||||||
self.config[attr_name] = [attr_value]
|
self.config[attr_name] = [attr_value]
|
||||||
else:
|
else:
|
||||||
self.config[attr_name].append(attr_value)
|
self.config[attr_name].append(attr_value)
|
||||||
@@ -419,14 +417,14 @@ class iface():
|
|||||||
%ifaceStatus.to_str(self.get_status()))
|
%ifaceStatus.to_str(self.get_status()))
|
||||||
logger.info(indent + 'refcnt: %d' %self.get_refcnt())
|
logger.info(indent + 'refcnt: %d' %self.get_refcnt())
|
||||||
d = self.get_lowerdevs()
|
d = self.get_lowerdevs()
|
||||||
if d is not None:
|
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.get_config()
|
||||||
if config is not None:
|
if config:
|
||||||
logger.info(indent + indent + str(config))
|
logger.info(indent + indent + str(config))
|
||||||
logger.info('}')
|
logger.info('}')
|
||||||
|
|
||||||
@@ -436,16 +434,13 @@ class iface():
|
|||||||
if self.get_auto():
|
if self.get_auto():
|
||||||
outbuf += 'auto %s\n' %self.get_name()
|
outbuf += 'auto %s\n' %self.get_name()
|
||||||
outbuf += 'iface %s' %self.get_name()
|
outbuf += 'iface %s' %self.get_name()
|
||||||
if self.get_addr_family() is not None:
|
if self.get_addr_family():
|
||||||
outbuf += ' %s' %self.get_addr_family()
|
outbuf += ' %s' %self.get_addr_family()
|
||||||
|
if self.get_addr_method():
|
||||||
if self.get_addr_method() is not None:
|
|
||||||
outbuf += ' %s' %self.get_addr_method()
|
outbuf += ' %s' %self.get_addr_method()
|
||||||
|
|
||||||
outbuf += '\n'
|
outbuf += '\n'
|
||||||
|
|
||||||
config = self.get_config()
|
config = self.get_config()
|
||||||
if config is not None:
|
if config:
|
||||||
for cname, cvaluelist in config.items():
|
for cname, cvaluelist in config.items():
|
||||||
idx = 0
|
idx = 0
|
||||||
for cv in cvaluelist:
|
for cv in cvaluelist:
|
||||||
|
@@ -343,7 +343,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
continue
|
continue
|
||||||
dlist = module.get_dependent_ifacenames(ifaceobj,
|
dlist = module.get_dependent_ifacenames(ifaceobj,
|
||||||
self.ifaceobjdict.keys())
|
self.ifaceobjdict.keys())
|
||||||
if dlist and len(dlist):
|
if dlist:
|
||||||
self.logger.debug('%s: ' %ifaceobj.get_name() +
|
self.logger.debug('%s: ' %ifaceobj.get_name() +
|
||||||
'got lowerifaces/dependents: %s' %str(dlist))
|
'got lowerifaces/dependents: %s' %str(dlist))
|
||||||
break
|
break
|
||||||
@@ -599,7 +599,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
if ifaceobjs is None:
|
if ifaceobjs is None:
|
||||||
err_iface += ' ' + i
|
err_iface += ' ' + i
|
||||||
|
|
||||||
if len(err_iface):
|
if err_iface:
|
||||||
self.logger.error('could not find interfaces: %s' %err_iface)
|
self.logger.error('could not find interfaces: %s' %err_iface)
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
@@ -614,7 +614,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
# If the interface matches
|
# If the interface matches
|
||||||
if excludepats and len(excludepats):
|
if excludepats:
|
||||||
for e in excludepats:
|
for e in excludepats:
|
||||||
if re.search(e, ifacename):
|
if re.search(e, ifacename):
|
||||||
return False
|
return False
|
||||||
@@ -625,12 +625,12 @@ class ifupdownMain(ifupdownBase):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# We check classes first
|
# We check classes first
|
||||||
if allow_classes and len(allow_classes):
|
if allow_classes:
|
||||||
for i in ifaceobjs:
|
for i in ifaceobjs:
|
||||||
if len(i.get_classes()):
|
if i.get_classes():
|
||||||
common = Set([allow_classes]).intersection(
|
common = Set([allow_classes]).intersection(
|
||||||
Set(i.get_classes()))
|
Set(i.get_classes()))
|
||||||
if len(common):
|
if common:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -684,7 +684,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
filtered_ifacenames = [i for i in ifacenames
|
filtered_ifacenames = [i for i in ifacenames
|
||||||
if self.iface_whitelisted(auto, allow_classes,
|
if self.iface_whitelisted(auto, allow_classes,
|
||||||
excludepats, i)]
|
excludepats, i)]
|
||||||
if not len(filtered_ifacenames):
|
if not filtered_ifacenames:
|
||||||
raise Exception('no ifaces found matching given allow lists')
|
raise Exception('no ifaces found matching given allow lists')
|
||||||
|
|
||||||
self.populate_dependency_info(filtered_ifacenames, ops)
|
self.populate_dependency_info(filtered_ifacenames, ops)
|
||||||
@@ -723,20 +723,17 @@ class ifupdownMain(ifupdownBase):
|
|||||||
# for down we need to look at old state
|
# for down we need to look at old state
|
||||||
self.logger.debug('Looking at old state ..')
|
self.logger.debug('Looking at old state ..')
|
||||||
|
|
||||||
if len(self.statemanager.get_ifaceobjdict()):
|
if self.statemanager.get_ifaceobjdict():
|
||||||
self.read_old_iface_config()
|
self.read_old_iface_config()
|
||||||
elif self.FORCE:
|
else:
|
||||||
# If no old state available
|
# If no old state available
|
||||||
self.logger.info('old state not available. ' +
|
self.logger.info('old state not available. ' +
|
||||||
'Force option set. Loading new iface config file')
|
'Loading new iface config file')
|
||||||
try:
|
try:
|
||||||
self.read_iface_config()
|
self.read_iface_config()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
raise Exception('error reading iface config (%s)' %str(e))
|
raise Exception('error reading iface config (%s)' %str(e))
|
||||||
loaded_newconfig = True
|
loaded_newconfig = True
|
||||||
else:
|
|
||||||
raise Exception('old state not available...aborting.' +
|
|
||||||
' try running with --force option')
|
|
||||||
|
|
||||||
if ifacenames:
|
if ifacenames:
|
||||||
# If iface list is given by the caller, always check if iface
|
# If iface list is given by the caller, always check if iface
|
||||||
@@ -745,13 +742,13 @@ class ifupdownMain(ifupdownBase):
|
|||||||
raise Exception('all or some interfaces not found')
|
raise Exception('all or some interfaces not found')
|
||||||
|
|
||||||
# if iface list not given by user, assume all from config file
|
# if iface list not given by user, assume all from config file
|
||||||
if ifacenames is None: ifacenames = self.ifaceobjdict.keys()
|
if not ifacenames: ifacenames = self.ifaceobjdict.keys()
|
||||||
|
|
||||||
# filter interfaces based on auto and allow classes
|
# filter interfaces based on auto and allow classes
|
||||||
filtered_ifacenames = [i for i in ifacenames
|
filtered_ifacenames = [i for i in ifacenames
|
||||||
if self.iface_whitelisted(auto, allow_classes,
|
if self.iface_whitelisted(auto, allow_classes,
|
||||||
excludepats, i)]
|
excludepats, i)]
|
||||||
if not len(filtered_ifacenames):
|
if not filtered_ifacenames:
|
||||||
raise Exception('no ifaces found matching given allow lists')
|
raise Exception('no ifaces found matching given allow lists')
|
||||||
|
|
||||||
self.populate_dependency_info(filtered_ifacenames, ops)
|
self.populate_dependency_info(filtered_ifacenames, ops)
|
||||||
@@ -816,7 +813,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
filtered_ifacenames = [i for i in ifacenames
|
filtered_ifacenames = [i for i in ifacenames
|
||||||
if self.iface_whitelisted(auto, allow_classes,
|
if self.iface_whitelisted(auto, allow_classes,
|
||||||
excludepats, i)]
|
excludepats, i)]
|
||||||
if len(filtered_ifacenames) == 0:
|
if not filtered_ifacenames:
|
||||||
raise Exception('no ifaces found matching ' +
|
raise Exception('no ifaces found matching ' +
|
||||||
'given allow lists')
|
'given allow lists')
|
||||||
|
|
||||||
@@ -870,7 +867,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
new_ifaceobjdict = dict(self.get_ifaceobjdict())
|
new_ifaceobjdict = dict(self.get_ifaceobjdict())
|
||||||
new_dependency_graph = dict(self.get_dependency_graph())
|
new_dependency_graph = dict(self.get_dependency_graph())
|
||||||
|
|
||||||
if len(self.statemanager.get_ifaceobjdict()) > 0:
|
if self.statemanager.get_ifaceobjdict():
|
||||||
# if old state is present, read old state and mark op for 'down'
|
# if old state is present, read old state and mark op for 'down'
|
||||||
# followed by 'up' aka: reload
|
# followed by 'up' aka: reload
|
||||||
# old interface config is read into self.ifaceobjdict
|
# old interface config is read into self.ifaceobjdict
|
||||||
@@ -883,8 +880,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
|
|
||||||
if ifacenames is None: ifacenames = self.ifaceobjdict.keys()
|
if ifacenames is None: ifacenames = self.ifaceobjdict.keys()
|
||||||
|
|
||||||
if (op == 'reload' and ifacenames is not None and
|
if op == 'reload' and ifacenames:
|
||||||
len(ifacenames) != 0):
|
|
||||||
filtered_ifacenames = [i for i in ifacenames
|
filtered_ifacenames = [i for i in ifacenames
|
||||||
if self.iface_whitelisted(auto, allow_classes,
|
if self.iface_whitelisted(auto, allow_classes,
|
||||||
excludepats, i)]
|
excludepats, i)]
|
||||||
@@ -925,7 +921,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
if ifacedownlist is not None and len(ifacedownlist) > 0:
|
if ifacedownlist:
|
||||||
self.logger.info('Executing down on interfaces: %s'
|
self.logger.info('Executing down on interfaces: %s'
|
||||||
%str(ifacedownlist))
|
%str(ifacedownlist))
|
||||||
# Generate dependency info for old config
|
# Generate dependency info for old config
|
||||||
@@ -998,7 +994,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
print '\n'
|
print '\n'
|
||||||
if self.WITH_DEPENDS:
|
if self.WITH_DEPENDS:
|
||||||
dlist = ifaceobj.get_lowerifaces()
|
dlist = ifaceobj.get_lowerifaces()
|
||||||
if not dlist or not len(dlist): continue
|
if not dlist: continue
|
||||||
self.print_ifaceobjs_pretty(dlist, format)
|
self.print_ifaceobjs_pretty(dlist, format)
|
||||||
|
|
||||||
def print_ifaceobjs_pretty(self, ifacenames, format='native'):
|
def print_ifaceobjs_pretty(self, ifacenames, format='native'):
|
||||||
@@ -1013,7 +1009,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
|
|
||||||
if self.WITH_DEPENDS:
|
if self.WITH_DEPENDS:
|
||||||
dlist = ifaceobj.get_lowerifaces()
|
dlist = ifaceobj.get_lowerifaces()
|
||||||
if not dlist or not len(dlist): continue
|
if not dlist: continue
|
||||||
self.print_ifaceobjs_pretty(dlist, format)
|
self.print_ifaceobjs_pretty(dlist, format)
|
||||||
|
|
||||||
def dump_ifaceobjs(self, ifacenames):
|
def dump_ifaceobjs(self, ifacenames):
|
||||||
@@ -1051,7 +1047,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
|
|
||||||
if self.WITH_DEPENDS:
|
if self.WITH_DEPENDS:
|
||||||
dlist = ifaceobj.get_lowerifaces()
|
dlist = ifaceobj.get_lowerifaces()
|
||||||
if not dlist or not len(dlist): continue
|
if not dlist: continue
|
||||||
self.print_ifaceobjscurr_pretty(dlist, format)
|
self.print_ifaceobjscurr_pretty(dlist, format)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@@ -1072,6 +1068,6 @@ class ifupdownMain(ifupdownBase):
|
|||||||
|
|
||||||
if self.WITH_DEPENDS:
|
if self.WITH_DEPENDS:
|
||||||
dlist = ifaceobj.get_lowerifaces()
|
dlist = ifaceobj.get_lowerifaces()
|
||||||
if dlist is None or len(dlist) == 0: continue
|
if not dlist: continue
|
||||||
self.print_ifaceobjsrunning_pretty(dlist, format)
|
self.print_ifaceobjsrunning_pretty(dlist, format)
|
||||||
return
|
return
|
||||||
|
@@ -39,10 +39,8 @@ class networkInterfaces():
|
|||||||
|
|
||||||
def ignore_line(self, line):
|
def ignore_line(self, line):
|
||||||
l = line.strip('\n ')
|
l = line.strip('\n ')
|
||||||
|
if not l or l[0] == '#':
|
||||||
if len(l) == 0 or l[0] == '#':
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def process_allow(self, lines, cur_idx, lineno):
|
def process_allow(self, lines, cur_idx, lineno):
|
||||||
@@ -166,7 +164,7 @@ class networkInterfaces():
|
|||||||
|
|
||||||
classes = ifaceobj.set_classes(
|
classes = ifaceobj.set_classes(
|
||||||
self.get_allow_classes_for_iface(ifaceobj.get_name()))
|
self.get_allow_classes_for_iface(ifaceobj.get_name()))
|
||||||
if classes is not None and len(classes) > 0:
|
if classes:
|
||||||
for c in classes:
|
for c in classes:
|
||||||
ifaceobj.set_class(c)
|
ifaceobj.set_class(c)
|
||||||
|
|
||||||
@@ -247,7 +245,7 @@ class networkInterfaces():
|
|||||||
|
|
||||||
def read_file(self, filename=None):
|
def read_file(self, filename=None):
|
||||||
ifaces_file = filename
|
ifaces_file = filename
|
||||||
if ifaces_file == None:
|
if not ifaces_file:
|
||||||
ifaces_file=self.ifaces_file
|
ifaces_file=self.ifaces_file
|
||||||
|
|
||||||
self.logger.debug('reading interfaces file %s' %ifaces_file)
|
self.logger.debug('reading interfaces file %s' %ifaces_file)
|
||||||
@@ -260,9 +258,7 @@ class networkInterfaces():
|
|||||||
|
|
||||||
# run through template engine
|
# run through template engine
|
||||||
filedata = self.run_template_engine(filedata)
|
filedata = self.run_template_engine(filedata)
|
||||||
|
|
||||||
self.process_filedata(filedata)
|
self.process_filedata(filedata)
|
||||||
|
|
||||||
|
|
||||||
def load(self, filename=None):
|
def load(self, filename=None):
|
||||||
return self.read_file(filename)
|
return self.read_file(filename)
|
||||||
|
@@ -8,9 +8,7 @@
|
|||||||
#
|
#
|
||||||
import cPickle
|
import cPickle
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from exceptions import *
|
|
||||||
import logging
|
import logging
|
||||||
import pprint
|
|
||||||
import os
|
import os
|
||||||
from iface import *
|
from iface import *
|
||||||
|
|
||||||
@@ -61,7 +59,7 @@ class stateManager():
|
|||||||
|
|
||||||
def read_saved_state(self, filename=None):
|
def read_saved_state(self, filename=None):
|
||||||
pickle_filename = filename
|
pickle_filename = filename
|
||||||
if pickle_filename == None:
|
if not pickle_filename:
|
||||||
pickle_filename = self.state_file
|
pickle_filename = self.state_file
|
||||||
|
|
||||||
if not os.path.exists(pickle_filename):
|
if not os.path.exists(pickle_filename):
|
||||||
@@ -80,12 +78,10 @@ class stateManager():
|
|||||||
|
|
||||||
def save_state(self, ifaceobjs, filename=None):
|
def save_state(self, ifaceobjs, filename=None):
|
||||||
pickle_filename = filename
|
pickle_filename = filename
|
||||||
if pickle_filename == None:
|
if not pickle_filename:
|
||||||
pickle_filename = self.state_file
|
pickle_filename = self.state_file
|
||||||
|
|
||||||
pickling.save(pickle_filename, ifaceobjs)
|
pickling.save(pickle_filename, ifaceobjs)
|
||||||
|
|
||||||
|
|
||||||
def compare_iface_state(ifaceobj1, ifaceobj2):
|
def compare_iface_state(ifaceobj1, ifaceobj2):
|
||||||
ifaceobj1_state = ifaceobj1.get_state()
|
ifaceobj1_state = ifaceobj1.get_state()
|
||||||
ifaceobj2_state = ifaceobj2.get_state()
|
ifaceobj2_state = ifaceobj2.get_state()
|
||||||
@@ -110,7 +106,7 @@ class stateManager():
|
|||||||
|
|
||||||
# compare config items
|
# compare config items
|
||||||
unmatched_item = set(ifaceobj.items()) ^ set(old_ifaceobj.items())
|
unmatched_item = set(ifaceobj.items()) ^ set(old_ifaceobj.items())
|
||||||
if len(unmatched_item) != 0:
|
if unmatched_item:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -254,7 +250,7 @@ class stateManager():
|
|||||||
|
|
||||||
def dump(self, ifacenames=None):
|
def dump(self, ifacenames=None):
|
||||||
print 'iface state:'
|
print 'iface state:'
|
||||||
if ifacenames is not None and len(ifacenames) > 0:
|
if ifacenames:
|
||||||
for i in ifacenames:
|
for i in ifacenames:
|
||||||
ifaceobj = self.ifaces.get(i)
|
ifaceobj = self.ifaces.get(i)
|
||||||
if ifaceobj is None:
|
if ifaceobj is None:
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import argparse
|
import argparse
|
||||||
from ifupdown.ifupdownmain import *
|
from ifupdown.ifupdownmain import *
|
||||||
|
|
||||||
@@ -41,8 +40,6 @@ def run_down(args):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
iflist = args.iflist
|
iflist = args.iflist
|
||||||
if len(args.iflist) == 0:
|
|
||||||
iflist = None
|
|
||||||
logger.debug('creating ifupdown object ..')
|
logger.debug('creating ifupdown object ..')
|
||||||
cachearg=(False if (iflist or args.nocache or
|
cachearg=(False if (iflist or args.nocache or
|
||||||
args.perfmode or args.noact)
|
args.perfmode or args.noact)
|
||||||
@@ -66,12 +63,10 @@ def run_query(args):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
iflist = args.iflist
|
iflist = args.iflist
|
||||||
if len(args.iflist) == 0:
|
|
||||||
iflist = None
|
|
||||||
if args.checkcurr:
|
if args.checkcurr:
|
||||||
qop='query-checkcurr'
|
qop='query-checkcurr'
|
||||||
elif args.running:
|
elif args.running:
|
||||||
if iflist is None:
|
if not iflist:
|
||||||
iflist = [i for i in os.listdir('/sys/class/net/')
|
iflist = [i for i in os.listdir('/sys/class/net/')
|
||||||
if os.path.isdir('/sys/class/net/%s' %i)]
|
if os.path.isdir('/sys/class/net/%s' %i)]
|
||||||
qop='query-running'
|
qop='query-running'
|
||||||
@@ -123,11 +118,9 @@ def init(args):
|
|||||||
global logger
|
global logger
|
||||||
|
|
||||||
log_level = logging.WARNING
|
log_level = logging.WARNING
|
||||||
|
if args.verbose:
|
||||||
if args.verbose == True:
|
|
||||||
log_level = logging.INFO
|
log_level = logging.INFO
|
||||||
|
if args.debug:
|
||||||
if args.debug == True:
|
|
||||||
log_level = logging.DEBUG
|
log_level = logging.DEBUG
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -264,7 +257,6 @@ def parse_args(argsv, op):
|
|||||||
update_ifquery_argparser(argparser)
|
update_ifquery_argparser(argparser)
|
||||||
elif op == 'reload':
|
elif op == 'reload':
|
||||||
update_ifreload_argparser(argparser)
|
update_ifreload_argparser(argparser)
|
||||||
|
|
||||||
return argparser.parse_args(argsv)
|
return argparser.parse_args(argsv)
|
||||||
|
|
||||||
handlers = {'up' : run_up,
|
handlers = {'up' : run_up,
|
||||||
@@ -277,13 +269,13 @@ def main(argv):
|
|||||||
args = None
|
args = None
|
||||||
try:
|
try:
|
||||||
op = None
|
op = None
|
||||||
if re.search(r'ifup', argv[0]) != None:
|
if argv[0].endswith('ifup'):
|
||||||
op = 'up'
|
op = 'up'
|
||||||
elif re.search(r'ifdown', argv[0]) != None:
|
elif argv[0].endswith('ifdown'):
|
||||||
op = 'down'
|
op = 'down'
|
||||||
elif re.search(r'ifquery', argv[0]) != None:
|
elif argv[0].endswith('ifquery'):
|
||||||
op = 'query'
|
op = 'query'
|
||||||
elif re.search(r'ifreload', argv[0]) != None:
|
elif argv[0].endswith('ifreload'):
|
||||||
op = 'reload'
|
op = 'reload'
|
||||||
else:
|
else:
|
||||||
print ('Unexpected executable.' +
|
print ('Unexpected executable.' +
|
||||||
@@ -291,18 +283,18 @@ def main(argv):
|
|||||||
exit(1)
|
exit(1)
|
||||||
# Command line arg parser
|
# Command line arg parser
|
||||||
args = parse_args(argv[1:], op)
|
args = parse_args(argv[1:], op)
|
||||||
if not len(args.iflist) and not args.all:
|
if not args.iflist and not args.all:
|
||||||
if op != 'query' or not args.syntaxhelp:
|
if op != 'query' or not args.syntaxhelp:
|
||||||
print '\'-a\' option or interface list are required'
|
print '\'-a\' option or interface list are required'
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if len(args.iflist) and args.all:
|
if args.iflist and args.all:
|
||||||
print '\'-a\' option and interface list are mutually exclusive'
|
print '\'-a\' option and interface list are mutually exclusive'
|
||||||
exit(1)
|
exit(1)
|
||||||
init(args)
|
init(args)
|
||||||
handlers.get(op)(args)
|
handlers.get(op)(args)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
if str(e) == '':
|
if not str(e):
|
||||||
exit(1)
|
exit(1)
|
||||||
if args and args.debug:
|
if args and args.debug:
|
||||||
raise
|
raise
|
||||||
|
Reference in New Issue
Block a user