]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
Misc fixes. Add a --skip-upperifaces option to ifup (given the confusion
authorRoopa Prabhu <roopa@cumulusnetworks.com>
Tue, 25 Nov 2014 18:19:35 +0000 (10:19 -0800)
committerRoopa Prabhu <roopa@cumulusnetworks.com>
Tue, 25 Nov 2014 18:19:35 +0000 (10:19 -0800)
over ifup handling of upperifaces by default) + some fixes in the
reserved vlan check

Ticket: CM-3346
Reviewed By:
Testing Done: Tested ifupdown sanity.

addons/bridge.py
ifupdown/ifupdownmain.py
ifupdown/scheduler.py
ifupdownaddons/modulebase.py
sbin/ifupdown

index 2b33a7acf7ca848ac190feee7378ec69e65d1a44..696adb1b3e05dc675abb97b0fb276a42a6284390 100644 (file)
@@ -336,6 +336,15 @@ class bridge(moduleBase):
             b = list(b)
             yield b[0][1], b[-1][1]
 
+    def _handle_reserved_vlan(self, vlanid):
+        if vlanid in range(self._resv_vlan_range[0],
+                           self._resv_vlan_range[1]):
+           self.logger.warn('skipping reserved vlan %d' %vlanid +
+                   ' (reserved vlan range %d-%d)' %(self._resv_vlan_range[0],
+                   self._resv_vlan_range[1]))
+           return True
+        return False
+
     def _ranges_to_ints(self, rangelist):
         """ returns expanded list of integers given set of string ranges
         example: ['1', '2-4', '6'] returns [1, 2, 3, 4, 6]
@@ -345,9 +354,14 @@ class bridge(moduleBase):
             if '-' in part:
                 a, b = part.split('-')
                 a, b = int(a), int(b)
+                if (self._handle_reserved_vlan(a) or
+                    self._handle_reserved_vlan(b)):
+                    continue
                 result.extend(range(a, b + 1))
             else:
                 a = int(part)
+                if self._handle_reserved_vlan(a):
+                   continue
                 result.append(a)
         return result
 
index 0521da722d6a015fe57bfaf540857e097a1ad34d..e807267ad22f165cf49d904c45925a5708647b6c 100644 (file)
@@ -625,7 +625,7 @@ class ifupdownMain(ifupdownBase):
                 # continue reading
                 pass
 
-    def _sched_ifaces(self, ifacenames, ops):
+    def _sched_ifaces(self, ifacenames, ops, skipupperifaces=False):
         self.logger.debug('scheduling \'%s\' for %s'
                           %(str(ops), str(ifacenames)))
         self._pretty_print_ordered_dict('dependency graph',
@@ -635,7 +635,8 @@ class ifupdownMain(ifupdownBase):
                         order=ifaceSchedulerFlags.INORDER
                             if 'down' in ops[0]
                                 else ifaceSchedulerFlags.POSTORDER,
-                        followdependents=True if self.WITH_DEPENDS else False)
+                        followdependents=True if self.WITH_DEPENDS else False,
+                        skipupperifaces=skipupperifaces)
 
     def _render_ifacename(self, ifacename):
         new_ifacenames = []
@@ -753,7 +754,7 @@ class ifupdownMain(ifupdownBase):
 
     def up(self, ops, auto=False, allow_classes=None, ifacenames=None,
            excludepats=None, printdependency=None, syntaxcheck=False,
-           type=None):
+           type=None, skipupperifaces=False):
         """This brings the interface(s) up
         
         Args:
@@ -806,7 +807,8 @@ class ifupdownMain(ifupdownBase):
             self.populate_dependency_info(ops)
 
         try:
-            self._sched_ifaces(filtered_ifacenames, ops)
+            self._sched_ifaces(filtered_ifacenames, ops,
+                    skipupperifaces=skipupperifaces)
         finally:
             if not self.DRYRUN and self.ADDONS_ENABLE:
                 self._save_state()
index 1d84a803d43fd06d248462a55b54858cb7c929b6..448b332f474ff08d2112484a4736d2191c2787f9 100644 (file)
@@ -336,7 +336,7 @@ class ifaceScheduler():
     def sched_ifaces(cls, ifupdownobj, ifacenames, ops,
                 dependency_graph=None, indegrees=None,
                 order=ifaceSchedulerFlags.POSTORDER,
-                followdependents=True):
+                followdependents=True, skipupperifaces=False):
         """ runs interface configuration modules on interfaces passed as
             argument. Runs topological sort on interface dependency graph.
 
@@ -426,7 +426,8 @@ class ifaceScheduler():
         if not cls._SCHED_RETVAL:
             raise Exception()
 
-        if (ifupdownobj.config.get('skip_upperifaces', '0') == '0' and
+        if (not skipupperifaces and
+                ifupdownobj.config.get('skip_upperifaces', '0') == '0' and
                 ((not ifupdownobj.ALL and followdependents) or
                 followupperifaces) and
                 'up' in ops[0]):
index 7d42cd2facacf080b285208fd204353a874d11fb..50a1e7c33364139ddfb5d949c90789a5be3b66c0 100644 (file)
@@ -325,7 +325,9 @@ class moduleBase(object):
         start = end = 0
         get_resvvlan = '/usr/share/python-ifupdown2/get_reserved_vlan_range.sh'
         try:
-            (start, end) = self.exec_command(get_resvvlan).split('-')
+            (s, e) = self.exec_command(get_resvvlan).strip('\n').split('-')
+            start = int(s)
+            end = int(e)
         except:
             # ignore errors
             pass
index b6120b2cc3770d16ce743e54a323e97b05997d90..13874ac232ac3f2c48d65b307a052903edf9acaa 100755 (executable)
@@ -51,13 +51,15 @@ def run_up(args):
             ifupdown_handle.up(['up'], args.all, args.CLASS, iflist,
                                excludepats=args.excludepats,
                                printdependency=args.printdependency,
-                               syntaxcheck=args.syntaxcheck, type=args.type)
+                               syntaxcheck=args.syntaxcheck, type=args.type,
+                               skipupperifaces=args.skipupperifaces)
         else:
             ifupdown_handle.up(['pre-up', 'up', 'post-up'],
                                args.all, args.CLASS, iflist,
                                excludepats=args.excludepats,
                                printdependency=args.printdependency,
-                               syntaxcheck=args.syntaxcheck, type=args.type)
+                               syntaxcheck=args.syntaxcheck, type=args.type,
+                               skipupperifaces=args.skipupperifaces)
     except:
         raise
 
@@ -260,6 +262,13 @@ def update_ifup_argparser(argparser):
     argparser.add_argument('-s', '--syntax-check', dest='syntaxcheck',
                 action='store_true',
                 help='Only run the interfaces file parser')
+    argparser.add_argument('-k', '--skip-upperifaces', dest='skipupperifaces',
+                action='store_true',
+                help='ifup by default tries to add newly created interfaces' +
+                ' into its upper/parent interfaces. Eg. if a bridge port is' +
+                ' created as a result of ifup on the port, ifup automatically' +
+                ' adds the port to the bridge. This option can be used to ' +
+                'disable this default behaviour')
     update_ifupdown_argparser(argparser)
 
 def update_ifdown_argparser(argparser):