mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix Issue:#47076 onyx_l2_interface parameter trunk_allowed_vlans tries to remove all existing vlans on a port (#49418)
Signed-off-by: Anas Badaha <anasb@mellanox.com>
This commit is contained in:
parent
b0c7efcc6b
commit
7fcd55f3ec
1 changed files with 20 additions and 9 deletions
|
@ -50,7 +50,6 @@ EXAMPLES = """
|
|||
name: Eth1/1
|
||||
mode: access
|
||||
access_vlan: 30
|
||||
|
||||
- name: remove Layer-2 interface configuration
|
||||
onyx_l2_interface:
|
||||
name: Eth1/1
|
||||
|
@ -150,16 +149,28 @@ class OnyxL2InterfaceModule(BaseOnyxModule):
|
|||
@classmethod
|
||||
def get_allowed_vlans(cls, if_data):
|
||||
allowed_vlans = cls.get_config_attr(if_data, 'Allowed vlans')
|
||||
interface_allwoed_vlans = []
|
||||
if allowed_vlans:
|
||||
vlans = allowed_vlans.split(',')
|
||||
allowed_vlans = [int(vlan.strip()) for vlan in vlans]
|
||||
return allowed_vlans
|
||||
vlans = [x.strip() for x in allowed_vlans.split(',')]
|
||||
for vlan in vlans:
|
||||
if '-' not in vlan:
|
||||
interface_allwoed_vlans.append(int(vlan))
|
||||
else:
|
||||
vlan_range = vlan.split("-")
|
||||
min_number = int(vlan_range[0].strip())
|
||||
max_number = int(vlan_range[1].strip())
|
||||
vlan_list = range(min_number, max_number + 1)
|
||||
interface_allwoed_vlans.extend(vlan_list)
|
||||
return interface_allwoed_vlans
|
||||
|
||||
@classmethod
|
||||
def get_access_vlan(cls, if_data):
|
||||
access_vlan = cls.get_config_attr(if_data, 'Access vlan')
|
||||
if access_vlan:
|
||||
try:
|
||||
return int(access_vlan)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
def _create_switchport_data(self, if_name, if_data):
|
||||
if self._os_version >= self.ONYX_API_VERSION:
|
||||
|
@ -224,14 +235,14 @@ class OnyxL2InterfaceModule(BaseOnyxModule):
|
|||
if req_trunk_vlans:
|
||||
req_trunk_vlans = set(req_trunk_vlans)
|
||||
if req_mode != 'access' and curr_trunk_vlans != req_trunk_vlans:
|
||||
removed_vlans = curr_trunk_vlans - req_trunk_vlans
|
||||
for vlan_id in removed_vlans:
|
||||
commands.append('switchport %s allowed-vlan remove %s' %
|
||||
(req_mode, vlan_id))
|
||||
added_vlans = req_trunk_vlans - curr_trunk_vlans
|
||||
for vlan_id in added_vlans:
|
||||
commands.append('switchport %s allowed-vlan add %s' %
|
||||
(req_mode, vlan_id))
|
||||
removed_vlans = curr_trunk_vlans - req_trunk_vlans
|
||||
for vlan_id in removed_vlans:
|
||||
commands.append('switchport %s allowed-vlan remove %s' %
|
||||
(req_mode, vlan_id))
|
||||
|
||||
if commands:
|
||||
self._add_interface_commands(if_name, commands)
|
||||
|
|
Loading…
Reference in a new issue