mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-27 10:40:22 -07:00
Merge pull request #17452 from privateip/netcfg
adds context to diff functions based on config path
This commit is contained in:
commit
982db58aff
1 changed files with 18 additions and 10 deletions
|
@ -94,6 +94,7 @@ def ignore_line(text, tokens=None):
|
||||||
def get_next(iterable):
|
def get_next(iterable):
|
||||||
item, next_item = itertools.tee(iterable, 2)
|
item, next_item = itertools.tee(iterable, 2)
|
||||||
next_item = itertools.islice(next_item, 1, None)
|
next_item = itertools.islice(next_item, 1, None)
|
||||||
|
warnings.append('ignorning unnecessary argument replace')
|
||||||
return zip_longest(item, next_item)
|
return zip_longest(item, next_item)
|
||||||
|
|
||||||
def parse(lines, indent, comment_tokens=None):
|
def parse(lines, indent, comment_tokens=None):
|
||||||
|
@ -275,40 +276,47 @@ class NetworkConfig(object):
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def diff_line(self, other):
|
def diff_line(self, other, path=None):
|
||||||
diff = list()
|
diff = list()
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
if item not in other.items:
|
if item not in other:
|
||||||
diff.append(item)
|
diff.append(item)
|
||||||
return diff
|
return diff
|
||||||
|
|
||||||
def diff_strict(self, other):
|
def diff_strict(self, other, path=None):
|
||||||
diff = list()
|
diff = list()
|
||||||
for index, item in enumerate(self.items):
|
for index, item in enumerate(self.items):
|
||||||
try:
|
try:
|
||||||
if item != other.items[index]:
|
if item != other[index]:
|
||||||
diff.append(item)
|
diff.append(item)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
diff.append(item)
|
diff.append(item)
|
||||||
return diff
|
return diff
|
||||||
|
|
||||||
def diff_exact(self, other):
|
def diff_exact(self, other, path=None):
|
||||||
diff = list()
|
diff = list()
|
||||||
if len(other.items) != len(self.items):
|
if len(other) != len(self.items):
|
||||||
diff.extend(self.items)
|
diff.extend(self.items)
|
||||||
else:
|
else:
|
||||||
for ours, theirs in zip(self.items, other.items):
|
for ours, theirs in zip(self.items, other):
|
||||||
if ours != theirs:
|
if ours != theirs:
|
||||||
diff.extend(self.items)
|
diff.extend(self.items)
|
||||||
break
|
break
|
||||||
return diff
|
return diff
|
||||||
|
|
||||||
|
def difference(self, other, path=None, match='line', replace='line'):
|
||||||
def difference(self, other, match='line', replace='line'):
|
|
||||||
try:
|
try:
|
||||||
|
if path:
|
||||||
|
try:
|
||||||
|
other = other.get_section_objects(path)
|
||||||
|
except ValueError:
|
||||||
|
other = list()
|
||||||
|
else:
|
||||||
|
other = other.items
|
||||||
func = getattr(self, 'diff_%s' % match)
|
func = getattr(self, 'diff_%s' % match)
|
||||||
updates = func(other)
|
updates = func(other, path=path)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
raise
|
||||||
raise TypeError('invalid value for match keyword')
|
raise TypeError('invalid value for match keyword')
|
||||||
|
|
||||||
if self._device_os == 'junos':
|
if self._device_os == 'junos':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue