Use dict_diff instead of sets to take diff lag members (#66126)
Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>
This commit is contained in:
parent
97aefb8e11
commit
cb46e5f06b
1 changed files with 17 additions and 8 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue