[stable-2.9] Eos vlan override (#63639) (#63687)

* [stable-2.9] Eos vlan override (#63639)

* Fix overridden & deleted in eos_vlans

* Fix vlan creation in overridden

* Right, Python 2.6
(cherry picked from commit 741d529)

Co-authored-by: Nathaniel Case <ncase@redhat.com>

* eos_vlans: Never try to set vlan_id as a property (#63689)

(cherry picked from commit d98482c294)

* Add changelog
pull/64802/head
Nathaniel Case 5 years ago committed by Matt Davis
parent 65ab51082b
commit 1e0d7ac25b

@ -0,0 +1,2 @@
bugfixes:
- "eos_vlans - Fixed behavior of when state=overridden"

@ -94,8 +94,8 @@ class Vlans(ConfigBase):
to the desired configuration
"""
state = self._module.params['state']
want = param_list_to_dict(want, "vlan_id", False)
have = param_list_to_dict(have, "vlan_id", False)
want = param_list_to_dict(want, "vlan_id", remove_key=False)
have = param_list_to_dict(have, "vlan_id", remove_key=False)
if state == 'overridden':
commands = self._state_overridden(want, have)
elif state == 'deleted':
@ -115,16 +115,16 @@ class Vlans(ConfigBase):
to the desired configuration
"""
commands = []
for key, desired in want.items():
if key in have:
extant = have[key]
for vlan_id, desired in want.items():
if vlan_id in have:
extant = have[vlan_id]
else:
extant = dict(vlan_id=key)
extant = dict()
add_config = dict_diff(extant, desired)
del_config = dict_diff(desired, extant)
commands.extend(generate_commands(key, add_config, del_config))
commands.extend(generate_commands(vlan_id, add_config, del_config))
return commands
@ -137,16 +137,25 @@ class Vlans(ConfigBase):
to the desired configuration
"""
commands = []
for key, extant in have.items():
if key in want:
desired = want[key]
for vlan_id, extant in have.items():
if vlan_id in want:
desired = want[vlan_id]
else:
desired = dict(vlan_id=key)
desired = dict()
add_config = dict_diff(extant, desired)
del_config = dict_diff(desired, extant)
commands.extend(generate_commands(key, add_config, del_config))
commands.extend(generate_commands(vlan_id, add_config, del_config))
# Handle vlans not already in config
new_vlans = [vlan_id for vlan_id in want if vlan_id not in have]
for vlan_id in new_vlans:
desired = want[vlan_id]
extant = dict(vlan_id=vlan_id)
add_config = dict_diff(extant, desired)
commands.extend(generate_commands(vlan_id, add_config, {}))
return commands
@ -159,15 +168,15 @@ class Vlans(ConfigBase):
the current configuration
"""
commands = []
for key, desired in want.items():
if key in have:
extant = have[key]
for vlan_id, desired in want.items():
if vlan_id in have:
extant = have[vlan_id]
else:
extant = dict(vlan_id=key)
extant = dict()
add_config = dict_diff(extant, desired)
commands.extend(generate_commands(key, add_config, {}))
commands.extend(generate_commands(vlan_id, add_config, {}))
return commands
@ -180,29 +189,32 @@ class Vlans(ConfigBase):
of the provided objects
"""
commands = []
for key in want.keys():
desired = dict(vlan_id=key)
if key in have:
extant = have[key]
for vlan_id in want:
desired = dict()
if vlan_id in have:
extant = have[vlan_id]
else:
extant = dict(vlan_id=key)
continue
del_config = dict_diff(desired, extant)
commands.extend(generate_commands(key, {}, del_config))
commands.extend(generate_commands(vlan_id, {}, del_config))
return commands
def generate_commands(vlan_id, to_set, to_remove):
commands = []
if "vlan_id" in to_remove:
return ["no vlan {0}".format(vlan_id)]
for key, value in to_set.items():
if value is None:
if key == "vlan_id" or value is None:
continue
commands.append("{0} {1}".format(key, value))
for key in to_remove.keys():
for key in to_remove:
commands.append("no {0}".format(key))
if commands:

@ -32,7 +32,6 @@
expected_config:
- vlan_id: 10
name: ten
- vlan_id: 20
- assert:
that:

@ -5,8 +5,8 @@
config:
- vlan_id: 20
state: suspend
other_config:
- vlan_id: 10
- vlan_id: 50
name: fifty
- eos_facts:
gather_network_resources: vlans
@ -32,7 +32,7 @@
- "ansible_facts.network_resources.vlans|symmetric_difference(result.after) == []"
- set_fact:
expected_config: "{{ config }} + {{ other_config }}"
expected_config: "{{ config }}"
- assert:
that:

Loading…
Cancel
Save