#
+# 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
import logging
import json
-_tickmark = ' (' + u'\u2713' + ')'
-_crossmark = ' (' + u'\u2717' + ')'
-_success_sym = _tickmark
-_error_sym = _crossmark
-
class ifaceStatus():
"""Enumerates iface status """
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
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:
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')
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
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 """
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'):
Returns True or False indicating the caller to proceed with the
operation.
"""
+ # 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)):
+ (not ifupdownobj.is_ifaceobj_noconfig(ifaceobj) and
+ ifupdownobj.config.get('warn_on_ifdown', '0') == '0')):
return True
- # proceed only for down operation
- if 'down' not in ops[0]:
- return True
ulist = ifaceobj.upperifaces
if not ulist:
return True
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
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()