|
|
@ -207,24 +207,19 @@ class Inventory(object):
|
|
|
|
a tuple of (start, stop) or None
|
|
|
|
a tuple of (start, stop) or None
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
if not "[" in pattern or pattern.startswith('~'):
|
|
|
|
# The regex used to match on the range, which can be [x] or [x-y].
|
|
|
|
return (pattern, None)
|
|
|
|
pattern_re = re.compile("^(.*)\[([0-9]+)(?:(?:-)([0-9]+))?\](.*)$")
|
|
|
|
(first, rest) = pattern.split("[")
|
|
|
|
m = pattern_re.match(pattern)
|
|
|
|
rest = rest.replace("]","")
|
|
|
|
if m:
|
|
|
|
try:
|
|
|
|
(target, first, last, rest) = m.groups()
|
|
|
|
# support selectors like webservers[0]
|
|
|
|
first = int(first)
|
|
|
|
x = int(rest)
|
|
|
|
if last:
|
|
|
|
return (first, (x,x))
|
|
|
|
last = int(last)
|
|
|
|
except:
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
last = first
|
|
|
|
if "-" in rest:
|
|
|
|
return (target, (first, last))
|
|
|
|
(left, right) = rest.split("-",1)
|
|
|
|
|
|
|
|
return (first, (left, right))
|
|
|
|
|
|
|
|
elif ":" in rest:
|
|
|
|
|
|
|
|
(left, right) = rest.split(":",1)
|
|
|
|
|
|
|
|
return (first, (left, right))
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return (first, (rest, rest))
|
|
|
|
return (pattern, None)
|
|
|
|
|
|
|
|
|
|
|
|
def _apply_ranges(self, pat, hosts):
|
|
|
|
def _apply_ranges(self, pat, hosts):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|