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]
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
# 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',
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 = []
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:
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()
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.
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]):
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
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
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):