mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
sub-interface support for nxos module (#37392)
* nxos sub-interface support Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * update l3_interface test Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * Add integration test Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
parent
9940b5db9c
commit
6db3f522c8
5 changed files with 94 additions and 4 deletions
|
@ -302,7 +302,7 @@ def normalize_interface(name):
|
||||||
def _get_number(name):
|
def _get_number(name):
|
||||||
digits = ''
|
digits = ''
|
||||||
for char in name:
|
for char in name:
|
||||||
if char.isdigit() or char == '/':
|
if char.isdigit() or char in '/.':
|
||||||
digits += char
|
digits += char
|
||||||
return digits
|
return digits
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,6 @@ def map_obj_to_commands(updates, module):
|
||||||
if command:
|
if command:
|
||||||
command.append('exit')
|
command.append('exit')
|
||||||
command.insert(0, 'interface {0}'.format(name))
|
command.insert(0, 'interface {0}'.format(name))
|
||||||
command.insert(1, 'no switchport')
|
|
||||||
commands.extend(command)
|
commands.extend(command)
|
||||||
|
|
||||||
elif state == 'present' and obj_in_have:
|
elif state == 'present' and obj_in_have:
|
||||||
|
@ -135,10 +134,8 @@ def map_obj_to_commands(updates, module):
|
||||||
if command:
|
if command:
|
||||||
command.append('exit')
|
command.append('exit')
|
||||||
command.insert(0, 'interface {0}'.format(name))
|
command.insert(0, 'interface {0}'.format(name))
|
||||||
command.insert(1, 'no switchport')
|
|
||||||
elif not ipv4 and not ipv6:
|
elif not ipv4 and not ipv6:
|
||||||
command.append('interface {0}'.format(name))
|
command.append('interface {0}'.format(name))
|
||||||
command.append('no switchport')
|
|
||||||
commands.extend(command)
|
commands.extend(command)
|
||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
---
|
||||||
|
- debug: msg="START connection={{ ansible_connection }} nxos_interface sub-interface test"
|
||||||
|
- debug: msg="Using provider={{ connection.transport }}"
|
||||||
|
when: ansible_connection == "local"
|
||||||
|
|
||||||
|
- set_fact: testint="{{ nxos_int1 }}"
|
||||||
|
|
||||||
|
- name: Setup - delete sub-interface
|
||||||
|
nxos_interface: &rm
|
||||||
|
name: "{{ testint }}.20"
|
||||||
|
state: absent
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: Setup - Ensure the interface is layer3
|
||||||
|
nxos_interface:
|
||||||
|
name: "{{ testint }}"
|
||||||
|
mode: layer3
|
||||||
|
|
||||||
|
- name: Create sub-interface
|
||||||
|
nxos_interface: &sub_int
|
||||||
|
name: "{{ testint }}.20"
|
||||||
|
description: "sub-interface Configured by Ansible"
|
||||||
|
admin_state: up
|
||||||
|
mtu: 800
|
||||||
|
provider: "{{ connection }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result.changed == true"
|
||||||
|
|
||||||
|
- name: Create sub-interface (Idempotence)
|
||||||
|
nxos_interface: *sub_int
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result.changed == false"
|
||||||
|
|
||||||
|
- name: Make admin_state down
|
||||||
|
nxos_interface: &state_down
|
||||||
|
name: "{{ testint }}.20"
|
||||||
|
description: "sub-interface Configured by Ansible"
|
||||||
|
admin_state: down
|
||||||
|
mtu: 800
|
||||||
|
provider: "{{ connection }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result.changed == true"
|
||||||
|
|
||||||
|
- name: Create sub-interface (Idempotence)
|
||||||
|
nxos_interface: *state_down
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result.changed == false"
|
||||||
|
|
||||||
|
- name: Remove sub-interface
|
||||||
|
nxos_interface: *rm
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result.changed == true"
|
||||||
|
|
||||||
|
- name: Remove sub-interface (Idempotence)
|
||||||
|
nxos_interface: *rm
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result.changed == false"
|
||||||
|
|
||||||
|
- debug: msg="END connection={{ ansible_connection }} nxos_interface sub-interface test"
|
|
@ -30,6 +30,14 @@
|
||||||
provider: "{{ cli }}"
|
provider: "{{ cli }}"
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: Setup - Ensure interfaces are layer3
|
||||||
|
nxos_interface:
|
||||||
|
aggregate:
|
||||||
|
- name: "{{ testint2 }}"
|
||||||
|
- name: "{{ testint3 }}"
|
||||||
|
mode: layer3
|
||||||
|
provider: "{{ cli }}"
|
||||||
|
|
||||||
- name: Configure ipv4 address to interface
|
- name: Configure ipv4 address to interface
|
||||||
nxos_l3_interface: &conf
|
nxos_l3_interface: &conf
|
||||||
name: "{{ testint2 }}"
|
name: "{{ testint2 }}"
|
||||||
|
|
|
@ -20,6 +20,14 @@
|
||||||
state: absent
|
state: absent
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: Setup - Ensure interfaces are layer3
|
||||||
|
nxos_interface:
|
||||||
|
aggregate:
|
||||||
|
- name: "{{ testint2 }}"
|
||||||
|
- name: "{{ testint3 }}"
|
||||||
|
mode: layer3
|
||||||
|
provider: "{{ nxapi }}"
|
||||||
|
|
||||||
- name: Configure ipv4 address to interface
|
- name: Configure ipv4 address to interface
|
||||||
nxos_l3_interface: &conf
|
nxos_l3_interface: &conf
|
||||||
name: "{{ testint2 }}"
|
name: "{{ testint2 }}"
|
||||||
|
|
Loading…
Reference in a new issue