mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
nxos_vlan purge (#38202)
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
parent
24cc6b80bd
commit
119352b538
2 changed files with 37 additions and 0 deletions
|
@ -83,6 +83,7 @@ options:
|
||||||
purge:
|
purge:
|
||||||
description:
|
description:
|
||||||
- Purge VLANs not defined in the I(aggregate) parameter.
|
- Purge VLANs not defined in the I(aggregate) parameter.
|
||||||
|
This parameter can be used without aggregate as well.
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
delay:
|
delay:
|
||||||
|
@ -131,6 +132,14 @@ EXAMPLES = '''
|
||||||
aggregate:
|
aggregate:
|
||||||
- { vlan_id: 4000, mode: ce }
|
- { vlan_id: 4000, mode: ce }
|
||||||
- { vlan_id: 4001, name: vlan-4001 }
|
- { vlan_id: 4001, name: vlan-4001 }
|
||||||
|
|
||||||
|
- name: purge vlans - removes all other vlans except the ones mentioned in aggregate)
|
||||||
|
nxos_vlan:
|
||||||
|
aggregate:
|
||||||
|
- vlan_id: 1
|
||||||
|
- vlan_id: 4001
|
||||||
|
purge: yes
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -184,6 +193,7 @@ def is_default_name(obj, vlan_id):
|
||||||
|
|
||||||
def map_obj_to_commands(updates, module, os_platform):
|
def map_obj_to_commands(updates, module, os_platform):
|
||||||
commands = list()
|
commands = list()
|
||||||
|
purge = module.params['purge']
|
||||||
want, have = updates
|
want, have = updates
|
||||||
|
|
||||||
for w in want:
|
for w in want:
|
||||||
|
@ -307,6 +317,12 @@ def map_obj_to_commands(updates, module, os_platform):
|
||||||
commands.append('switchport mode access')
|
commands.append('switchport mode access')
|
||||||
commands.append('no switchport access vlan {0}'.format(vlan_id))
|
commands.append('no switchport access vlan {0}'.format(vlan_id))
|
||||||
|
|
||||||
|
if purge:
|
||||||
|
for h in have:
|
||||||
|
obj_in_want = search_obj_in_list(h['vlan_id'], want)
|
||||||
|
if not obj_in_want:
|
||||||
|
commands.append('no vlan {0}'.format(h['vlan_id']))
|
||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,27 @@
|
||||||
that:
|
that:
|
||||||
- 'result.changed == false'
|
- 'result.changed == false'
|
||||||
|
|
||||||
|
- name: purge
|
||||||
|
nxos_vlan: &purge
|
||||||
|
vlan_id: 1
|
||||||
|
purge: yes
|
||||||
|
provider: "{{ connection }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed == true'
|
||||||
|
- '"no vlan 102" in result.commands'
|
||||||
|
- '"no vlan 103" in result.commands'
|
||||||
|
|
||||||
|
- name: purge - Idempotence
|
||||||
|
nxos_vlan: *purge
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed == false'
|
||||||
|
|
||||||
- name: teardown
|
- name: teardown
|
||||||
nxos_config: *rm
|
nxos_config: *rm
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue