summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Sprygada <psprygada@ansible.com>2016-09-07 19:40:47 -0400
committerPeter Sprygada <psprygada@ansible.com>2016-09-07 19:40:47 -0400
commit08eeb1518aa1332138c5d835392bacb88f114cbb (patch)
tree158a2f3ee187a5356815cb307caef706e9f7d07e
parent715b800ef12cf4aeb5740a6a955a50df52bd34e3 (diff)
downloadansible-08eeb1518aa1332138c5d835392bacb88f114cbb.tar.gz
adds context to diff functions based on config path
* difference() now accepts a path keyword to specify comparision domain
-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':