]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
make a few things configurable (check output err/success string +
authorroopa <roopa@cumulusnetworks.com>
Fri, 9 May 2014 16:10:49 +0000 (09:10 -0700)
committerroopa <roopa@cumulusnetworks.com>
Fri, 9 May 2014 16:10:49 +0000 (09:10 -0700)
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

config/ifupdown2.conf
pkg/iface.py
pkg/ifupdownmain.py
pkg/scheduler.py
sbin/ifupdown

index b20bd42b1f4f2ca5abf34beae3e84231a331caca..bcd1401377f911fe1ba92333c1ac26831a06680e 100644 (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
index 731ba846cb59540cbd57bbbe15ed4d97c3b83fc1..3e1b50b4da794f7ae5fdffb34ed5b42abdad3c51 100644 (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
index 36532bf1fd6488f3077251f9859f650776d13485..ee5666e21390c08152e15fc8fb511481fb418a89 100644 (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'):
index 9bdaf24b94ba8ef5123ceafc819ff3939de965b2..8865ec475887ce3da32008c4ea510cf96109c53d 100644 (file)
@@ -134,14 +134,16 @@ class ifaceScheduler():
         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
@@ -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
 
index 336f55238a57c2165982d058288bc895f88f7b27..b49f283b4fdb5337dd5a5e577a8b20196f046fdf 100755 (executable)
@@ -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()