mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
Enhance globbing in ifupdown2 to support breakout cables
Ticket: CM-5365 Reviewed By: roopa,dwalton Testing Done: Ran regression suite and hand tested. This patch extends the globbing support in ifupdown2 to handle two levels of square brackets so that breakout cables can be handled (e.g. swp[2-7]s[0-3]). Also modified the user's guide and the man pages.
This commit is contained in:
@@ -317,6 +317,10 @@ bridge ports and bond slaves::
|
|||||||
iface br1
|
iface br1
|
||||||
bridge-ports glob swp7-9.100 swp11.100 glob swp15-18.100
|
bridge-ports glob swp7-9.100 swp11.100 glob swp15-18.100
|
||||||
|
|
||||||
|
auto br2
|
||||||
|
iface br2
|
||||||
|
bridge-ports glob swp[1-6]s[0-3].100
|
||||||
|
|
||||||
Using Templates
|
Using Templates
|
||||||
===============
|
===============
|
||||||
|
|
||||||
|
@@ -148,33 +148,58 @@ class moduleBase(object):
|
|||||||
|
|
||||||
def parse_glob(self, expr):
|
def parse_glob(self, expr):
|
||||||
errmsg = ('error parsing glob expression \'%s\'' %expr +
|
errmsg = ('error parsing glob expression \'%s\'' %expr +
|
||||||
' (supported glob syntax: swp1-10 or swp[1-10])')
|
' (supported glob syntax: swp1-10.300 or swp[1-10].300' +
|
||||||
start_index = 0
|
' or swp[1-10]sub[0-4].300')
|
||||||
end_index = 0
|
|
||||||
try:
|
# explanations are shown below in each if clause
|
||||||
regexs = [re.compile(r"([A-Za-z0-9\-]+[A-Za-z])(\d+)\-(\d+)(.*)"),
|
regexs = [re.compile(r"([A-Za-z0-9\-]+)\[(\d+)\-(\d+)\]([A-Za-z0-9\-]+)\[(\d+)\-(\d+)\](.*)"),
|
||||||
re.compile(r"([A-Za-z0-9\-]+)\[(\d+)\-(\d+)\](.*)")]
|
re.compile(r"([A-Za-z0-9\-]+[A-Za-z])(\d+)\-(\d+)(.*)"),
|
||||||
for r in regexs:
|
re.compile(r"([A-Za-z0-9\-]+)\[(\d+)\-(\d+)\](.*)")]
|
||||||
m = r.match(expr)
|
|
||||||
if not m:
|
if regexs[0].match(expr):
|
||||||
continue
|
# the first regex checks for exactly two levels of ranges defined only with square brackets
|
||||||
mlist = m.groups()
|
# (e.g. swpxyz[10-23]subqwe[0-4].100) to handle naming with two levels of port names.
|
||||||
if len(mlist) != 4:
|
m = regexs[0].match(expr)
|
||||||
raise Exception(errmsg + '(unexpected len)')
|
mlist = m.groups()
|
||||||
prefix = mlist[0]
|
if len(mlist) < 7:
|
||||||
suffix = mlist[3]
|
# we have problems and should not continue
|
||||||
start_index = int(mlist[1])
|
raise Exception('Error: unhandled glob expression %s\n%s' % (expr,errmsg))
|
||||||
end_index = int(mlist[2])
|
|
||||||
except:
|
prefix = mlist[0]
|
||||||
self.logger.warn(errmsg)
|
suffix = mlist[6]
|
||||||
pass
|
start_index = int(mlist[1])
|
||||||
if not start_index and not end_index:
|
end_index = int(mlist[2])
|
||||||
self.logger.warn(errmsg)
|
sub_string = mlist[3]
|
||||||
yield expr
|
start_sub = int(mlist[4])
|
||||||
else:
|
end_sub = int(mlist[5])
|
||||||
|
for i in range(start_index, end_index + 1):
|
||||||
|
for j in range(start_sub, end_sub + 1):
|
||||||
|
yield prefix + '%d%s%d' % (i,sub_string,j) + suffix
|
||||||
|
|
||||||
|
elif regexs[1].match(expr) or regexs[2].match(expr):
|
||||||
|
# the second regex for 1 level with a range (e.g. swp10-14.100
|
||||||
|
# the third regex checks for 1 level with [] (e.g. swp[10-14].100)
|
||||||
|
start_index = 0
|
||||||
|
end_index = 0
|
||||||
|
if regexs[1].match(expr):
|
||||||
|
m = regexs[1].match(expr)
|
||||||
|
else:
|
||||||
|
m = regexs[2].match(expr)
|
||||||
|
mlist = m.groups()
|
||||||
|
if len(mlist) != 4:
|
||||||
|
raise Exception(errmsg + '(unexpected len)')
|
||||||
|
prefix = mlist[0]
|
||||||
|
suffix = mlist[3]
|
||||||
|
start_index = int(mlist[1])
|
||||||
|
end_index = int(mlist[2])
|
||||||
for i in range(start_index, end_index + 1):
|
for i in range(start_index, end_index + 1):
|
||||||
yield prefix + '%d' %i + suffix
|
yield prefix + '%d' %i + suffix
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Could not match anything.
|
||||||
|
self.logger.warn('Warning: could not glob properly with %s\n%s' % (expr,errmsg))
|
||||||
|
yield expr
|
||||||
|
|
||||||
def parse_port_list(self, port_expr, ifacenames=None):
|
def parse_port_list(self, port_expr, ifacenames=None):
|
||||||
""" parse port list containing glob and regex
|
""" parse port list containing glob and regex
|
||||||
|
|
||||||
|
@@ -321,6 +321,8 @@ EXAMPLES
|
|||||||
|
|
||||||
bridge-ports glob swp1-3.100
|
bridge-ports glob swp1-3.100
|
||||||
|
|
||||||
|
bridge-ports glob swp[1-3]s[0-4].100
|
||||||
|
|
||||||
bridge-ports regex (swp[1|2|3].100)
|
bridge-ports regex (swp[1|2|3].100)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user