summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Sprygada <privateip@users.noreply.github.com>2016-09-07 21:49:09 -0400
committerGitHub <noreply@github.com>2016-09-07 21:49:09 -0400
commit982db58aff01033110522c6afe25988f65b05ebc (patch)
tree1a5f82f9b3f0709a4293fe0619e8941c290beeb0
parentd64eaae2320eecdf69a2f5f4dfdcffd3625a058f (diff)
parent08eeb1518aa1332138c5d835392bacb88f114cbb (diff)
downloadansible-982db58aff01033110522c6afe25988f65b05ebc.tar.gz
Merge pull request #17452 from privateip/netcfg
adds context to diff functions based on config path
-rw-r--r--lib/ansible/module_utils/netcfg.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/ansible/module_utils/netcfg.py b/lib/ansible/module_utils/netcfg.py
index e10a4a02c4..87a4de4156 100644
--- a/lib/ansible/module_utils/netcfg.py
+++ b/lib/ansible/module_utils/netcfg.py
@@ -94,6 +94,7 @@ def ignore_line(text, tokens=None):
def get_next(iterable):
item, next_item = itertools.tee(iterable, 2)
next_item = itertools.islice(next_item, 1, None)
+ warnings.append('ignorning unnecessary argument replace')
return zip_longest(item, next_item)
def parse(lines, indent, comment_tokens=None):
@@ -275,40 +276,47 @@ class NetworkConfig(object):
return items
- def diff_line(self, other):
+ def diff_line(self, other, path=None):
diff = list()
for item in self.items:
- if item not in other.items:
+ if item not in other:
diff.append(item)
return diff
- def diff_strict(self, other):
+ def diff_strict(self, other, path=None):
diff = list()
for index, item in enumerate(self.items):
try:
- if item != other.items[index]:
+ if item != other[index]:
diff.append(item)
except IndexError:
diff.append(item)
return diff
- def diff_exact(self, other):
+ def diff_exact(self, other, path=None):
diff = list()
- if len(other.items) != len(self.items):
+ if len(other) != len(self.items):
diff.extend(self.items)
else:
- for ours, theirs in zip(self.items, other.items):
+ for ours, theirs in zip(self.items, other):
if ours != theirs:
diff.extend(self.items)
break
return diff
-
- def difference(self, other, match='line', replace='line'):
+ def difference(self, other, path=None, match='line', replace='line'):
try:
+ if path:
+ try:
+ other = other.get_section_objects(path)
+ except ValueError:
+ other = list()
+ else:
+ other = other.items
func = getattr(self, 'diff_%s' % match)
- updates = func(other)
+ updates = func(other, path=path)
except AttributeError:
+ raise
raise TypeError('invalid value for match keyword')
if self._device_os == 'junos':