Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nxos_vlan purge #38202

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/ansible/modules/network/nxos/nxos_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
purge:
description:
- Purge VLANs not defined in the I(aggregate) parameter.
This parameter can be used without aggregate as well.
type: bool
default: 'no'
delay:
Expand Down Expand Up @@ -131,6 +132,14 @@
aggregate:
- { vlan_id: 4000, mode: ce }
- { 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 = '''
Expand Down Expand Up @@ -184,6 +193,7 @@ def is_default_name(obj, vlan_id):

def map_obj_to_commands(updates, module, os_platform):
commands = list()
purge = module.params['purge']
want, have = updates

for w in want:
Expand Down Expand Up @@ -307,6 +317,12 @@ def map_obj_to_commands(updates, module, os_platform):
commands.append('switchport mode access')
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


Expand Down
21 changes: 21 additions & 0 deletions test/integration/targets/nxos_vlan/tests/common/agg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@
that:
- '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
nxos_config: *rm
ignore_errors: yes
Expand Down