]> git.proxmox.com Git - mirror_ifupdown2.git/blobdiff - pkg/ifupdownmain.py
prefix ethtool attributes with "link-" to be compatible with
[mirror_ifupdown2.git] / pkg / ifupdownmain.py
index 8cb3ae2a7e85ee9ebe814b1b2efa561ac2612440..67c1d81b705921eefd67ac0b060c9c0f948fdb61 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 """
 
@@ -183,21 +188,26 @@ class ifupdownMain(ifupdownBase):
         return ifaceobj
 
     def create_n_save_ifaceobjcurr(self, ifaceobj):
-        """ creates a copy of iface object and adds it to the iface dict containing current iface objects 
+        """ creates a copy of iface object and adds it to the iface
+            dict containing current iface objects 
         """
-        ifaceobjcurr = self.get_ifaceobjcurr(ifaceobj.name)
-        if ifaceobjcurr:
-            return ifaceobjcurr
         ifaceobjcurr = iface()
         ifaceobjcurr.name = ifaceobj.name
         ifaceobjcurr.lowerifaces = ifaceobj.lowerifaces
         ifaceobjcurr.priv_flags = ifaceobj.priv_flags
         ifaceobjcurr.auto = ifaceobj.auto
-        self.ifaceobjcurrdict[ifaceobj.name] = ifaceobjcurr
+        self.ifaceobjcurrdict.setdefault(ifaceobj.name,
+                                     []).append(ifaceobjcurr)
         return ifaceobjcurr
 
-    def get_ifaceobjcurr(self, ifacename):
-        return self.ifaceobjcurrdict.get(ifacename)
+    def get_ifaceobjcurr(self, ifacename, idx=0):
+        ifaceobjlist = self.ifaceobjcurrdict.get(ifacename)
+        if not ifaceobjlist:
+            return None
+        if not idx:
+            return ifaceobjlist
+        else:
+            return ifaceobjlist[idx]
 
     def get_ifaceobjrunning(self, ifacename):
         return self.ifaceobjrunningdict.get(ifacename)
@@ -344,6 +354,8 @@ class ifupdownMain(ifupdownBase):
         if ifaceobj.compare(currentifaceobjlist[0]):
             self.logger.warn('duplicate interface %s found' %ifaceobj.name)
             return
+        currentifaceobjlist[0].flags |= iface.HAS_SIBLINGS
+        ifaceobj.flags |= iface.HAS_SIBLINGS
         self.ifaceobjdict[ifaceobj.name].append(ifaceobj)
 
     def _iface_configattr_syntax_checker(self, attrname, attrval):
@@ -471,7 +483,7 @@ class ifupdownMain(ifupdownBase):
 
                     validrange = attrvaldict.get('validrange')
                     if validrange:
-                        print('%svalidrange: %d-%d'
+                        print('%svalidrange: %s-%s'
                               %(indent + '  ', validrange[0], validrange[1]))
 
                     validvals = attrvaldict.get('validvals')
@@ -538,8 +550,7 @@ class ifupdownMain(ifupdownBase):
             if not ifaceobjs:
                 err_iface += ' ' + i
         if err_iface:
-            self.logger.error('cannot find interfaces: %s' %err_iface)
-            return False
+            raise Exception('cannot find interfaces:%s' %err_iface)
         return True
 
     def _iface_whitelisted(self, auto, allow_classes, excludepats, ifacename):
@@ -630,8 +641,7 @@ class ifupdownMain(ifupdownBase):
         if ifacenames:
             # If iface list is given by the caller, always check if iface
             # is present
-           if not self._validate_ifaces(ifacenames):
-               raise Exception('all or some interfaces not found')
+            self._validate_ifaces(ifacenames)
 
         # if iface list not given by user, assume all from config file
         if not ifacenames: ifacenames = self.ifaceobjdict.keys()
@@ -674,7 +684,6 @@ class ifupdownMain(ifupdownBase):
             self.read_old_iface_config()
         else:
             # If no old state available 
-            self.logger.info('Loading current iface config file')
             try:
                 self.read_iface_config()
             except Exception, e:
@@ -682,8 +691,12 @@ class ifupdownMain(ifupdownBase):
         if ifacenames:
             # If iface list is given by the caller, always check if iface
             # is present
-           if not self._validate_ifaces(ifacenames):
-               raise Exception('interface(s) was probably never up')
+            try:
+               self._validate_ifaces(ifacenames)
+            except Exception, e:
+               raise Exception('%s' %str(e) +
+                       ' (interface was probably never up ?)')
+
         # if iface list not given by user, assume all from config file
         if not ifacenames: ifacenames = self.ifaceobjdict.keys()
 
@@ -694,10 +707,12 @@ class ifupdownMain(ifupdownBase):
         if not filtered_ifacenames:
             raise Exception('no ifaces found matching given allow lists')
 
-        self.populate_dependency_info(ops, filtered_ifacenames)
         if printdependency:
+            self.populate_dependency_info(ops, filtered_ifacenames)
             self.print_dependency(filtered_ifacenames, printdependency)
             return
+        else:
+            self.populate_dependency_info(ops)
 
         try:
             self._sched_ifaces(filtered_ifacenames, ops)
@@ -734,8 +749,7 @@ class ifupdownMain(ifupdownBase):
 
         if ifacenames and ops[0] != 'query-running':
             # If iface list is given, always check if iface is present
-           if not self._validate_ifaces(ifacenames):
-               raise Exception('all or some interfaces not found')
+           self._validate_ifaces(ifacenames)
 
         # if iface list not given by user, assume all from config file
         if not ifacenames: ifacenames = self.ifaceobjdict.keys()
@@ -931,19 +945,20 @@ class ifupdownMain(ifupdownBase):
     def _get_ifaceobjscurr_pretty(self, ifacenames, ifaceobjs):
         ret = 0
         for i in ifacenames:
-            ifaceobj = self.get_ifaceobjcurr(i)
-            if not ifaceobj: continue
-            if (ifaceobj.status == ifaceStatus.NOTFOUND or
-                ifaceobj.status == ifaceStatus.ERROR):
-                ret = 1
-            if self.is_ifaceobj_noconfig(ifaceobj):
-                continue
-            ifaceobjs.append(ifaceobj)
-            if self.WITH_DEPENDS and not self.ALL:
-                dlist = ifaceobj.lowerifaces
-                if not dlist: continue
-                dret = self._get_ifaceobjscurr_pretty(dlist, ifaceobjs)
-                if dret: ret = 1
+            ifaceobjscurr = self.get_ifaceobjcurr(i)
+            if not ifaceobjscurr: continue
+            for ifaceobj in ifaceobjscurr:
+                if (ifaceobj.status == ifaceStatus.NOTFOUND or
+                    ifaceobj.status == ifaceStatus.ERROR):
+                    ret = 1
+                if self.is_ifaceobj_noconfig(ifaceobj):
+                    continue
+                ifaceobjs.append(ifaceobj)
+                if self.WITH_DEPENDS and not self.ALL:
+                    dlist = ifaceobj.lowerifaces
+                    if not dlist: continue
+                    dret = self._get_ifaceobjscurr_pretty(dlist, ifaceobjs)
+                    if dret: ret = 1
         return ret
 
     def print_ifaceobjscurr_pretty(self, ifacenames, format='native'):
@@ -961,7 +976,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'):