1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

make a few things configurable (check output err/success string +

warnings on ifupdown)

Ticket: CM-1438
Reviewed By:
Testing Done: Tested ifupdown2 sanity

Some of the above mentioned configurable items can be specified in
ifupdown2.conf
This commit is contained in:
roopa
2014-05-09 09:10:49 -07:00
parent 615234a10d
commit 86fc62e20c
5 changed files with 43 additions and 30 deletions

View File

@@ -1,7 +1,11 @@
#
# ifupdown2 configuration file
#
# This file contains default settings for ifupdown
#
TEMPLATE_ENGINE=mako
TEMPLATE_LOOKUPPATH=/etc/network/ifupdown2/templates
# default template engine (only mako is currently supported)
template_engine=mako
# default template lookup path during template rendering
template_lookuppath=/etc/network/ifupdown2/templates

View File

@@ -29,11 +29,6 @@ from collections import OrderedDict
import logging
import json
_tickmark = ' (' + u'\u2713' + ')'
_crossmark = ' (' + u'\u2717' + ')'
_success_sym = _tickmark
_error_sym = _crossmark
class ifaceStatus():
"""Enumerates iface status """
@@ -292,13 +287,6 @@ class iface():
def get_config_attr_status(self, attr_name, idx=0):
return self._config_status.get(attr_name, [])[idx]
def get_config_attr_status_str(self, attr_name, idx=0):
ret = self.get_config_attr_status(attr_name, idx)
if ret:
return _error_sym
else:
return _success_sym
def compare(self, dstiface):
""" Compares two objects
@@ -376,7 +364,8 @@ class iface():
logger.info(indent + indent + str(config))
logger.info('}')
def dump_pretty(self, with_status=False):
def dump_pretty(self, with_status=False,
successstr='success', errorstr='error'):
indent = '\t'
outbuf = ''
if self.auto:
@@ -389,9 +378,9 @@ class iface():
if with_status:
if (self.status == ifaceStatus.NOTFOUND or
self.status == ifaceStatus.ERROR):
outbuf += ' %s' %_error_sym
else:
outbuf += ' %s' %_success_sym
outbuf += ' (%s)' %errorstr
elif self.status == ifaceStatus.SUCCESS:
outbuf += ' (%s)' %successstr
if self.status == ifaceStatus.NOTFOUND:
if with_status:
outbuf = (outbuf.encode('utf8')
@@ -406,8 +395,13 @@ class iface():
for cv in cvaluelist:
if not cv: continue
if with_status:
outbuf += indent + '%s %s %s\n' %(cname, cv,
self.get_config_attr_status_str(cname, idx))
s = self.get_config_attr_status(cname, idx)
if s:
outbuf += (indent + '%s %s (%s)\n'
%(cname, cv, errorstr))
elif s == 0:
outbuf += (indent + '%s %s (%s)\n'
%(cname, cv, successstr))
else:
outbuf += indent + '%s %s\n' %(cname, cv)
idx += 1

View File

@@ -24,6 +24,11 @@ from collections import OrderedDict
from graph import *
from sets import Set
_tickmark = u'\u2713'
_crossmark = u'\u2717'
_success_sym = _tickmark
_error_sym = _crossmark
class ifupdownMain(ifupdownBase):
""" ifupdown2 main class """
@@ -963,7 +968,11 @@ class ifupdownMain(ifupdownBase):
print json.dumps(ifaceobjs, cls=ifaceJsonEncoder, indent=2,
separators=(',', ': '))
else:
map(lambda i: i.dump_pretty(with_status=True), ifaceobjs)
map(lambda i: i.dump_pretty(with_status=True,
successstr=self.config.get('check_success_str',
_success_sym),
errorstr=self.config.get('check_error_str', _error_sym)),
ifaceobjs)
return ret
def print_ifaceobjsrunning_pretty(self, ifacenames, format='native'):

View File

@@ -134,14 +134,16 @@ class ifaceScheduler():
Returns True or False indicating the caller to proceed with the
operation.
"""
if (ifupdownobj.FORCE or
not ifupdownobj.ADDONS_ENABLE or
not ifupdownobj.is_ifaceobj_noconfig(ifaceobj)):
return True
# proceed only for down operation
if 'down' not in ops[0]:
return True
if (ifupdownobj.FORCE or
not ifupdownobj.ADDONS_ENABLE or
(not ifupdownobj.is_ifaceobj_noconfig(ifaceobj) and
ifupdownobj.config.get('warn_on_ifdown', '0') == '0')):
return True
ulist = ifaceobj.upperifaces
if not ulist:
return True
@@ -156,8 +158,12 @@ class ifaceScheduler():
for u in tmpulist:
if ifupdownobj.link_exists(u):
if not ifupdownobj.ALL:
ifupdownobj.logger.info('%s: skipping interface down,'
%ifaceobj.name + ' upperiface %s still around ' %u)
if ifupdownobj.is_ifaceobj_noconfig(ifaceobj):
ifupdownobj.logger.info('%s: skipping interface down,'
%ifaceobj.name + ' upperiface %s still around ' %u)
else:
ifupdownobj.logger.warn('%s: skipping interface down,'
%ifaceobj.name + ' upperiface %s still around ' %u)
return False
return True

View File

@@ -391,8 +391,8 @@ def main(argv):
logger.error(str(e))
else:
print str(e)
if args and not args.debug:
print '\nrerun the command with \'-d\' for a detailed errormsg'
#if args and not args.debug:
# print '\nrerun the command with \'-d\' for a detailed errormsg'
exit(1)
finally:
deinit()