IOS: Add voice vlan to ios_l2_interfaces (#67211)
* Add voice vlan to ios_l2_interfaces * Fixed pep8 issues, added voice vlan to tests, updated module docs
This commit is contained in:
parent
e632d93371
commit
cceb517aff
5 changed files with 77 additions and 30 deletions
|
@ -39,6 +39,9 @@ class L2_InterfacesArgs(object):
|
||||||
'access': {'type': 'dict',
|
'access': {'type': 'dict',
|
||||||
'options': {'vlan': {'type': 'int'}}
|
'options': {'vlan': {'type': 'int'}}
|
||||||
},
|
},
|
||||||
|
'voice': {'type': 'dict',
|
||||||
|
'options': {'vlan': {'type': 'int'}}
|
||||||
|
},
|
||||||
'trunk': {'type': 'dict',
|
'trunk': {'type': 'dict',
|
||||||
'options': {'allowed_vlans': {'type': 'list'},
|
'options': {'allowed_vlans': {'type': 'list'},
|
||||||
'encapsulation': {'type': 'str',
|
'encapsulation': {'type': 'str',
|
||||||
|
|
|
@ -36,6 +36,7 @@ class L2_Interfaces(ConfigBase):
|
||||||
]
|
]
|
||||||
|
|
||||||
access_cmds = {'access_vlan': 'switchport access vlan'}
|
access_cmds = {'access_vlan': 'switchport access vlan'}
|
||||||
|
voice_cmds = {'voice_vlan': 'switchport voice vlan'}
|
||||||
trunk_cmds = {'encapsulation': 'switchport trunk encapsulation', 'pruning_vlans': 'switchport trunk pruning vlan',
|
trunk_cmds = {'encapsulation': 'switchport trunk encapsulation', 'pruning_vlans': 'switchport trunk pruning vlan',
|
||||||
'native_vlan': 'switchport trunk native vlan', 'allowed_vlans': 'switchport trunk allowed vlan'}
|
'native_vlan': 'switchport trunk native vlan', 'allowed_vlans': 'switchport trunk allowed vlan'}
|
||||||
|
|
||||||
|
@ -250,6 +251,10 @@ class L2_Interfaces(ConfigBase):
|
||||||
cmd = 'switchport access vlan {0}'.format(diff.get('access')[0][1])
|
cmd = 'switchport access vlan {0}'.format(diff.get('access')[0][1])
|
||||||
add_command_to_config_list(interface, cmd, commands)
|
add_command_to_config_list(interface, cmd, commands)
|
||||||
|
|
||||||
|
if diff.get('voice'):
|
||||||
|
cmd = 'switchport voice vlan {0}'.format(diff.get('voice')[0][1])
|
||||||
|
add_command_to_config_list(interface, cmd, commands)
|
||||||
|
|
||||||
if want_trunk:
|
if want_trunk:
|
||||||
if diff.get('trunk'):
|
if diff.get('trunk'):
|
||||||
diff = dict(diff.get('trunk'))
|
diff = dict(diff.get('trunk'))
|
||||||
|
@ -287,6 +292,12 @@ class L2_Interfaces(ConfigBase):
|
||||||
if have.get('access').get('vlan') != want.get('access').get('vlan'):
|
if have.get('access').get('vlan') != want.get('access').get('vlan'):
|
||||||
remove_command_from_config_list(interface, L2_Interfaces.access_cmds['access_vlan'], commands)
|
remove_command_from_config_list(interface, L2_Interfaces.access_cmds['access_vlan'], commands)
|
||||||
|
|
||||||
|
if have.get('voice') and want.get('voice') is None:
|
||||||
|
remove_command_from_config_list(interface, L2_Interfaces.voice_cmds['voice_vlan'], commands)
|
||||||
|
elif have.get('voice') and want.get('voice'):
|
||||||
|
if have.get('voice').get('vlan') != want.get('voice').get('vlan'):
|
||||||
|
remove_command_from_config_list(interface, L2_Interfaces.voice_cmds['voice_vlan'], commands)
|
||||||
|
|
||||||
if have.get('trunk') and want.get('trunk') is None:
|
if have.get('trunk') and want.get('trunk') is None:
|
||||||
# Check when no config is passed
|
# Check when no config is passed
|
||||||
if have.get('trunk').get('encapsulation'):
|
if have.get('trunk').get('encapsulation'):
|
||||||
|
|
|
@ -91,6 +91,10 @@ class L2_InterfacesFacts(object):
|
||||||
if has_access:
|
if has_access:
|
||||||
config["access"] = {"vlan": int(has_access)}
|
config["access"] = {"vlan": int(has_access)}
|
||||||
|
|
||||||
|
has_voice = utils.parse_conf_arg(conf, 'switchport voice vlan')
|
||||||
|
if has_voice:
|
||||||
|
config["voice"] = {"vlan": int(has_voice)}
|
||||||
|
|
||||||
trunk = dict()
|
trunk = dict()
|
||||||
trunk["encapsulation"] = utils.parse_conf_arg(conf, 'encapsulation')
|
trunk["encapsulation"] = utils.parse_conf_arg(conf, 'encapsulation')
|
||||||
native_vlan = utils.parse_conf_arg(conf, 'native vlan')
|
native_vlan = utils.parse_conf_arg(conf, 'native vlan')
|
||||||
|
|
|
@ -66,6 +66,15 @@ options:
|
||||||
description:
|
description:
|
||||||
- Configure given VLAN in access port. It's used as the access VLAN ID.
|
- Configure given VLAN in access port. It's used as the access VLAN ID.
|
||||||
type: int
|
type: int
|
||||||
|
voice:
|
||||||
|
description:
|
||||||
|
- Switchport mode voice command to configure the interface with a voice vlan.
|
||||||
|
type: dict
|
||||||
|
suboptions:
|
||||||
|
vlan:
|
||||||
|
description:
|
||||||
|
- Configure given voice VLAN on access port. It's used as the voice VLAN ID.
|
||||||
|
type: int
|
||||||
trunk:
|
trunk:
|
||||||
description:
|
description:
|
||||||
- Switchport mode trunk command to configure the interface as a Layer 2 trunk.
|
- Switchport mode trunk command to configure the interface as a Layer 2 trunk.
|
||||||
|
@ -126,6 +135,8 @@ EXAMPLES = """
|
||||||
- name: GigabitEthernet0/1
|
- name: GigabitEthernet0/1
|
||||||
access:
|
access:
|
||||||
vlan: 10
|
vlan: 10
|
||||||
|
voice:
|
||||||
|
vlan: 40
|
||||||
- name: GigabitEthernet0/2
|
- name: GigabitEthernet0/2
|
||||||
trunk:
|
trunk:
|
||||||
allowed_vlans: 10-20,40
|
allowed_vlans: 10-20,40
|
||||||
|
@ -141,6 +152,7 @@ EXAMPLES = """
|
||||||
# interface GigabitEthernet0/1
|
# interface GigabitEthernet0/1
|
||||||
# description Configured by Ansible
|
# description Configured by Ansible
|
||||||
# switchport access vlan 10
|
# switchport access vlan 10
|
||||||
|
# switchport access vlan 40
|
||||||
# negotiation auto
|
# negotiation auto
|
||||||
# interface GigabitEthernet0/2
|
# interface GigabitEthernet0/2
|
||||||
# description This is test
|
# description This is test
|
||||||
|
@ -220,6 +232,8 @@ EXAMPLES = """
|
||||||
- name: GigabitEthernet0/2
|
- name: GigabitEthernet0/2
|
||||||
access:
|
access:
|
||||||
vlan: 20
|
vlan: 20
|
||||||
|
voice:
|
||||||
|
vlan: 40
|
||||||
state: overridden
|
state: overridden
|
||||||
|
|
||||||
# After state:
|
# After state:
|
||||||
|
@ -232,6 +246,7 @@ EXAMPLES = """
|
||||||
# interface GigabitEthernet0/2
|
# interface GigabitEthernet0/2
|
||||||
# description This is test
|
# description This is test
|
||||||
# switchport access vlan 20
|
# switchport access vlan 20
|
||||||
|
# switchport voice vlan 40
|
||||||
# media-type rj45
|
# media-type rj45
|
||||||
# negotiation auto
|
# negotiation auto
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ merged:
|
||||||
commands:
|
commands:
|
||||||
- "interface GigabitEthernet0/1"
|
- "interface GigabitEthernet0/1"
|
||||||
- "switchport access vlan 30"
|
- "switchport access vlan 30"
|
||||||
|
- "switchport voice vlan 40"
|
||||||
- "interface GigabitEthernet0/2"
|
- "interface GigabitEthernet0/2"
|
||||||
- "switchport trunk encapsulation dot1q"
|
- "switchport trunk encapsulation dot1q"
|
||||||
- "switchport trunk native vlan 20"
|
- "switchport trunk native vlan 20"
|
||||||
|
@ -18,38 +19,43 @@ merged:
|
||||||
- name: GigabitEthernet0/0
|
- name: GigabitEthernet0/0
|
||||||
- access:
|
- access:
|
||||||
vlan: 30
|
vlan: 30
|
||||||
|
voice:
|
||||||
|
vlan: 40
|
||||||
name: GigabitEthernet0/1
|
name: GigabitEthernet0/1
|
||||||
- name: GigabitEthernet0/2
|
- name: GigabitEthernet0/2
|
||||||
trunk:
|
trunk:
|
||||||
allowed_vlans:
|
allowed_vlans:
|
||||||
- 15-20
|
- 15-20
|
||||||
- '40'
|
- "40"
|
||||||
encapsulation: dot1q
|
encapsulation: dot1q
|
||||||
native_vlan: 20
|
native_vlan: 20
|
||||||
pruning_vlans:
|
pruning_vlans:
|
||||||
- '10'
|
- "10"
|
||||||
- '20'
|
- "20"
|
||||||
|
|
||||||
replaced:
|
replaced:
|
||||||
before:
|
before:
|
||||||
- name: GigabitEthernet0/0
|
- name: GigabitEthernet0/0
|
||||||
- access:
|
- access:
|
||||||
vlan: 10
|
vlan: 10
|
||||||
name: GigabitEthernet0/1
|
voice:
|
||||||
- name: GigabitEthernet0/2
|
vlan: 40
|
||||||
trunk:
|
name: GigabitEthernet0/1
|
||||||
allowed_vlans:
|
- name: GigabitEthernet0/2
|
||||||
- 10-20
|
trunk:
|
||||||
- '40'
|
allowed_vlans:
|
||||||
encapsulation: dot1q
|
- 10-20
|
||||||
native_vlan: 10
|
- "40"
|
||||||
pruning_vlans:
|
encapsulation: dot1q
|
||||||
- '10'
|
native_vlan: 10
|
||||||
- '20'
|
pruning_vlans:
|
||||||
|
- "10"
|
||||||
|
- "20"
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
- "interface GigabitEthernet0/1"
|
- "interface GigabitEthernet0/1"
|
||||||
- "switchport access vlan 40"
|
- "switchport access vlan 40"
|
||||||
|
- "switchport voice vlan 20"
|
||||||
- "interface GigabitEthernet0/2"
|
- "interface GigabitEthernet0/2"
|
||||||
- "no switchport trunk allowed vlan"
|
- "no switchport trunk allowed vlan"
|
||||||
- "switchport trunk native vlan 20"
|
- "switchport trunk native vlan 20"
|
||||||
|
@ -59,35 +65,40 @@ replaced:
|
||||||
- name: GigabitEthernet0/0
|
- name: GigabitEthernet0/0
|
||||||
- access:
|
- access:
|
||||||
vlan: 40
|
vlan: 40
|
||||||
|
voice:
|
||||||
|
vlan: 20
|
||||||
name: GigabitEthernet0/1
|
name: GigabitEthernet0/1
|
||||||
- name: GigabitEthernet0/2
|
- name: GigabitEthernet0/2
|
||||||
trunk:
|
trunk:
|
||||||
encapsulation: dot1q
|
encapsulation: dot1q
|
||||||
native_vlan: 20
|
native_vlan: 20
|
||||||
pruning_vlans:
|
pruning_vlans:
|
||||||
- 10-20
|
- 10-20
|
||||||
- '30'
|
- "30"
|
||||||
|
|
||||||
overridden:
|
overridden:
|
||||||
before:
|
before:
|
||||||
- name: GigabitEthernet0/0
|
- name: GigabitEthernet0/0
|
||||||
- access:
|
- access:
|
||||||
vlan: 10
|
vlan: 10
|
||||||
|
voice:
|
||||||
|
vlan: 40
|
||||||
name: GigabitEthernet0/1
|
name: GigabitEthernet0/1
|
||||||
- name: GigabitEthernet0/2
|
- name: GigabitEthernet0/2
|
||||||
trunk:
|
trunk:
|
||||||
allowed_vlans:
|
allowed_vlans:
|
||||||
- 10-20
|
- 10-20
|
||||||
- '40'
|
- "40"
|
||||||
encapsulation: dot1q
|
encapsulation: dot1q
|
||||||
native_vlan: 10
|
native_vlan: 10
|
||||||
pruning_vlans:
|
pruning_vlans:
|
||||||
- '10'
|
- "10"
|
||||||
- '20'
|
- "20"
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
- "interface GigabitEthernet0/1"
|
- "interface GigabitEthernet0/1"
|
||||||
- "no switchport access vlan"
|
- "no switchport access vlan"
|
||||||
|
- "no switchport voice vlan"
|
||||||
- "interface GigabitEthernet0/2"
|
- "interface GigabitEthernet0/2"
|
||||||
- "no switchport trunk pruning vlan"
|
- "no switchport trunk pruning vlan"
|
||||||
- "switchport trunk encapsulation isl"
|
- "switchport trunk encapsulation isl"
|
||||||
|
@ -100,8 +111,8 @@ overridden:
|
||||||
- name: GigabitEthernet0/2
|
- name: GigabitEthernet0/2
|
||||||
trunk:
|
trunk:
|
||||||
allowed_vlans:
|
allowed_vlans:
|
||||||
- 30-35
|
- 30-35
|
||||||
- '40'
|
- "40"
|
||||||
encapsulation: isl
|
encapsulation: isl
|
||||||
native_vlan: 30
|
native_vlan: 30
|
||||||
|
|
||||||
|
@ -110,21 +121,24 @@ deleted:
|
||||||
- name: GigabitEthernet0/0
|
- name: GigabitEthernet0/0
|
||||||
- access:
|
- access:
|
||||||
vlan: 10
|
vlan: 10
|
||||||
|
voice:
|
||||||
|
vlan: 40
|
||||||
name: GigabitEthernet0/1
|
name: GigabitEthernet0/1
|
||||||
- name: GigabitEthernet0/2
|
- name: GigabitEthernet0/2
|
||||||
trunk:
|
trunk:
|
||||||
allowed_vlans:
|
allowed_vlans:
|
||||||
- 10-20
|
- 10-20
|
||||||
- '40'
|
- "40"
|
||||||
encapsulation: dot1q
|
encapsulation: dot1q
|
||||||
native_vlan: 10
|
native_vlan: 10
|
||||||
pruning_vlans:
|
pruning_vlans:
|
||||||
- '10'
|
- "10"
|
||||||
- '20'
|
- "20"
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
- "interface GigabitEthernet0/1"
|
- "interface GigabitEthernet0/1"
|
||||||
- "no switchport access vlan"
|
- "no switchport access vlan"
|
||||||
|
- "no switch voice vlan"
|
||||||
- "interface GigabitEthernet0/2"
|
- "interface GigabitEthernet0/2"
|
||||||
- "no switchport trunk encapsulation"
|
- "no switchport trunk encapsulation"
|
||||||
- "no switchport trunk native vlan"
|
- "no switchport trunk native vlan"
|
||||||
|
|
Loading…
Reference in a new issue