Use dict_diff instead of sets to take diff lag members (#66126)

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>
This commit is contained in:
Nilashish Chakraborty 2020-01-07 13:12:54 +05:30 committed by GitHub
parent 97aefb8e11
commit cb46e5f06b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,9 +14,9 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
from ansible.module_utils.network.common.cfg.base import ConfigBase
from ansible.module_utils.network.common.utils import to_list, remove_empties
from ansible.module_utils.network.common.utils import to_list, remove_empties, dict_diff, search_obj_in_list
from ansible.module_utils.network.nxos.facts.facts import Facts
from ansible.module_utils.network.nxos.utils.utils import normalize_interface, search_obj_in_list
from ansible.module_utils.network.nxos.utils.utils import normalize_interface
class Lag_interfaces(ConfigBase):
@ -184,13 +184,22 @@ class Lag_interfaces(ConfigBase):
commands.extend(self.del_all_commands(h))
return commands
def diff_list_of_dicts(self, w, h):
def diff_list_of_dicts(self, want, have):
if not want:
want = []
if not have:
have = []
diff = []
set_w = set(tuple(d.items()) for d in w)
set_h = set(tuple(d.items()) for d in h)
difference = set_w.difference(set_h)
for element in difference:
diff.append(dict((x, y) for x, y in element))
for w_item in want:
h_item = search_obj_in_list(w_item['member'], have, key='member') or {}
delta = dict_diff(h_item, w_item)
if delta:
if 'member' not in delta.keys():
delta['member'] = w_item['member']
diff.append(delta)
return diff
def intersect_list_of_dicts(self, w, h):