Skip to content

Commit 518742a

Browse files
committed
Add Supermicro switches to allow for supported write config
Yes the syntax is the same as Cisco but they don't save the config the same way this makes sure that when using a supermicro switch config is saved using the correct netmiko driver. Change-Id: Icfc4d02884ca4b92c131307edac1b55ba8c1adb1
1 parent 0aed9fd commit 518742a

6 files changed

Lines changed: 175 additions & 0 deletions

File tree

doc/source/configuration.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ for an ArubaOS-CX switch::
224224
password = password
225225
ip = <switch mgmt ip address>
226226

227+
for the Supermicro device::
228+
229+
[genericswitch:sw-hostname]
230+
device_type = netmiko_supermicro_smis
231+
ngs_mac_address = <switch mac address>
232+
ip = <switch mgmt ip address>
233+
username = admin
234+
password = password
235+
secret = secret
236+
227237
General configuration
228238
=====================
229239

doc/source/supported-devices.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The following devices are supported by this plugin:
2121
* OpenVSwitch
2222
* Ruijie switches
2323
* SONiC switches
24+
* Supermicro switches
2425

2526
This Mechanism Driver architecture allows easily to add more devices
2627
of any type.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright 2024 Nscale.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
from networking_generic_switch.devices import netmiko_devices
16+
17+
18+
class SupermicroSmis(netmiko_devices.NetmikoSwitch):
19+
"""A class to represent a Supermicro SMIS switch"""
20+
"""
21+
Inherits from:
22+
--------------
23+
netmiko_devices.NetmikoSwitch
24+
25+
Class Attributes:
26+
-----------------
27+
ADD_NETWORK : tuple
28+
A tuple of command strings used to add a VLAN
29+
with a specific segmentation ID
30+
and name the VLAN.
31+
32+
DELETE_NETWORK : tuple
33+
A tuple of command strings used to delete a VLAN
34+
by its segmentation ID.
35+
36+
PLUG_PORT_TO_NETWORK : tuple
37+
A tuple of command strings used to configure a port
38+
to connect to a specific VLAN.
39+
This sets the port to access mode and assigns it
40+
to the specified VLAN.
41+
42+
DELETE_PORT : tuple
43+
A tuple of command strings used to remove a port
44+
from the VLAN. This removes
45+
any trunking configuration and clears VLAN assignments.
46+
"""
47+
ADD_NETWORK = (
48+
'vlan {segmentation_id}',
49+
'name {network_name}',
50+
)
51+
52+
DELETE_NETWORK = (
53+
'no vlan {segmentation_id}',
54+
)
55+
56+
PLUG_PORT_TO_NETWORK = (
57+
'interface {port}',
58+
'switchport mode access',
59+
'switchport access vlan {segmentation_id}',
60+
)
61+
62+
DELETE_PORT = (
63+
'interface {port}',
64+
'no switchport access vlan {segmentation_id}',
65+
'no switchport mode trunk',
66+
'switchport trunk allowed vlan none'
67+
)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright 2024 Nscale.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
from unittest import mock
16+
17+
from networking_generic_switch.devices.netmiko_devices import smc
18+
from networking_generic_switch.tests.unit.netmiko import test_netmiko_base
19+
20+
21+
class TestNetmikoSupermicroSmis(test_netmiko_base.NetmikoSwitchTestBase):
22+
23+
def _make_switch_device(self):
24+
device_cfg = {'device_type': 'netmiko_supermicro_smis'}
25+
return smc.SupermicroSmis(device_cfg)
26+
27+
def test_constants(self):
28+
self.assertIsNone(self.switch.SAVE_CONFIGURATION)
29+
30+
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
31+
'NetmikoSwitch.send_commands_to_device', autospec=True)
32+
def test_add_network(self, m_exec):
33+
self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
34+
m_exec.assert_any_call(
35+
self.switch,
36+
['vlan 33', 'name 0ae071f55be943e480eae41fefe85b21'])
37+
38+
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
39+
'NetmikoSwitch.send_commands_to_device', autospec=True)
40+
def test_del_network(self, mock_exec):
41+
self.switch.del_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
42+
mock_exec.assert_called_with(self.switch, ['no vlan 33'])
43+
44+
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
45+
'NetmikoSwitch.send_commands_to_device', autospec=True)
46+
def test_plug_port_to_network(self, mock_exec):
47+
self.switch.plug_port_to_network(3333, 33)
48+
mock_exec.assert_called_with(
49+
self.switch,
50+
['interface 3333', 'switchport mode access',
51+
'switchport access vlan 33'])
52+
53+
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
54+
'NetmikoSwitch.send_commands_to_device', autospec=True)
55+
def test_delete_port(self, mock_exec):
56+
self.switch.delete_port(3333, 33)
57+
mock_exec.assert_called_with(
58+
self.switch,
59+
['interface 3333', 'no switchport access vlan 33',
60+
'no switchport mode trunk', 'switchport trunk allowed vlan none'])
61+
62+
def test__format_commands(self):
63+
cmd_set = self.switch._format_commands(
64+
smc.SupermicroSmis.ADD_NETWORK,
65+
segmentation_id=22,
66+
network_id=22,
67+
network_name='vlan-22')
68+
self.assertEqual(cmd_set, ['vlan 22', 'name vlan-22'])
69+
70+
cmd_set = self.switch._format_commands(
71+
smc.SupermicroSmis.DELETE_NETWORK,
72+
segmentation_id=22)
73+
self.assertEqual(cmd_set, ['no vlan 22'])
74+
75+
cmd_set = self.switch._format_commands(
76+
smc.SupermicroSmis.PLUG_PORT_TO_NETWORK,
77+
port=3333,
78+
segmentation_id=33)
79+
plug_exp = ['interface 3333', 'switchport mode access',
80+
'switchport access vlan 33']
81+
self.assertEqual(plug_exp, cmd_set)
82+
83+
cmd_set = self.switch._format_commands(
84+
smc.SupermicroSmis.DELETE_PORT,
85+
port=3333,
86+
segmentation_id=33)
87+
del_exp = ['interface 3333',
88+
'no switchport access vlan 33',
89+
'no switchport mode trunk',
90+
'switchport trunk allowed vlan none']
91+
self.assertEqual(del_exp, cmd_set)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Adds a new device driver, ``netmiko_supermicro_smis``, for managing Supermicro
5+
based switch devices.

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ generic_switch.devices =
5151
netmiko_cumulus = networking_generic_switch.devices.netmiko_devices.cumulus:Cumulus
5252
netmiko_cumulus_nvue = networking_generic_switch.devices.netmiko_devices.cumulus:CumulusNVUE
5353
netmiko_sonic = networking_generic_switch.devices.netmiko_devices.sonic:Sonic
54+
netmiko_supermicro_smis = networking_generic_switch.devices.netmiko_devices.smc:SupermicroSmis
5455
netmiko_nokia_srl = networking_generic_switch.devices.netmiko_devices.nokia:NokiaSRL
5556
netmiko_pluribus = networking_generic_switch.devices.netmiko_devices.pluribus:Pluribus
5657
netmiko_aruba_os = networking_generic_switch.devices.netmiko_devices.aruba:ArubaOSCX

0 commit comments

Comments
 (0)