Skip to content

Commit dfbf9ce

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add support for Cisco Nexus devices (NX-OS)"
2 parents 0c7f61b + 61dd3e8 commit dfbf9ce

File tree

6 files changed

+183
-0
lines changed

6 files changed

+183
-0
lines changed

doc/source/configuration.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ for the Cisco IOS device::
5656
secret = secret
5757
ip = <switch mgmt ip address>
5858

59+
for the Cisco NX-OS device::
60+
61+
[genericswitch:sw-hostname]
62+
device_type = netmiko_cisco_nxos
63+
ngs_mac_address = <switch mac address>
64+
ip = <switch mgmt ip address>
65+
username = admin
66+
password = password
67+
secret = secret
68+
5969
for the Huawei VRPV3 or VRPV5 device::
6070

6171
[genericswitch:sw-hostname]
@@ -282,6 +292,7 @@ This is currently supported by the following devices:
282292

283293
* Juniper Junos OS
284294
* ArubaOS-CX
295+
* Cisco NX-OS
285296

286297
Network Name Format
287298
===================

doc/source/supported-devices.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The following devices are supported by this plugin:
99
* Brocade ICX (FastIron)
1010
* Cisco 300-series switches
1111
* Cisco IOS switches
12+
* Cisco NX-OS switches (Nexus)
1213
* Cumulus Linux (via NCLU)
1314
* Dell Force10
1415
* Dell OS10

networking_generic_switch/devices/netmiko_devices/cisco.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2016 Mirantis, Inc.
2+
# Copyright 2022 Baptiste Jonglez, Inria
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License"); you may
45
# not use this file except in compliance with the License. You may obtain
@@ -37,3 +38,55 @@ class CiscoIos(netmiko_devices.NetmikoSwitch):
3738
'no switchport mode trunk',
3839
'switchport trunk allowed vlan none'
3940
)
41+
42+
43+
class CiscoNxOS(netmiko_devices.NetmikoSwitch):
44+
"""Netmiko device driver for Cisco Nexus switches running NX-OS."""
45+
46+
ADD_NETWORK = (
47+
'vlan {segmentation_id}',
48+
'name {network_name}',
49+
'exit',
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+
'exit',
61+
)
62+
63+
DELETE_PORT = (
64+
'interface {port}',
65+
'no switchport access vlan',
66+
'exit',
67+
)
68+
69+
ADD_NETWORK_TO_TRUNK = (
70+
'interface {port}',
71+
'switchport mode trunk',
72+
'switchport trunk allowed vlan add {segmentation_id}',
73+
'exit',
74+
)
75+
76+
REMOVE_NETWORK_FROM_TRUNK = (
77+
'interface {port}',
78+
'switchport trunk allowed vlan remove {segmentation_id}',
79+
'exit',
80+
)
81+
82+
ENABLE_PORT = (
83+
'interface {port}',
84+
'no shutdown',
85+
'exit',
86+
)
87+
88+
DISABLE_PORT = (
89+
'interface {port}',
90+
'shutdown',
91+
'exit',
92+
)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Copyright 2022 Baptiste Jonglez, Inria
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 cisco
18+
from networking_generic_switch.tests.unit.netmiko import test_netmiko_base
19+
20+
21+
class TestNetmikoCiscoNxOS(test_netmiko_base.NetmikoSwitchTestBase):
22+
23+
def _make_switch_device(self):
24+
device_cfg = {'device_type': 'netmiko_cisco_nxos'}
25+
return cisco.CiscoNxOS(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')
32+
def test_add_network(self, m_exec):
33+
self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
34+
m_exec.assert_called_with(
35+
['vlan 33', 'name 0ae071f55be943e480eae41fefe85b21', 'exit'])
36+
37+
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
38+
'NetmikoSwitch.send_commands_to_device')
39+
def test_del_network(self, mock_exec):
40+
self.switch.del_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
41+
mock_exec.assert_called_with(['no vlan 33'])
42+
43+
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
44+
'NetmikoSwitch.send_commands_to_device')
45+
def test_plug_port_to_network(self, mock_exec):
46+
self.switch.plug_port_to_network(3333, 33)
47+
mock_exec.assert_called_with(
48+
['interface 3333', 'switchport mode access',
49+
'switchport access vlan 33', 'exit'])
50+
51+
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
52+
'NetmikoSwitch.send_commands_to_device')
53+
def test_delete_port(self, mock_exec):
54+
self.switch.delete_port(3333, 33)
55+
mock_exec.assert_called_with(
56+
['interface 3333', 'no switchport access vlan', 'exit'])
57+
58+
def test__format_commands(self):
59+
cmd_set = self.switch._format_commands(
60+
cisco.CiscoNxOS.ADD_NETWORK,
61+
segmentation_id=22,
62+
network_id=22,
63+
network_name='vlan-22')
64+
self.assertEqual(cmd_set, ['vlan 22', 'name vlan-22', 'exit'])
65+
66+
cmd_set = self.switch._format_commands(
67+
cisco.CiscoNxOS.DELETE_NETWORK,
68+
segmentation_id=22)
69+
self.assertEqual(cmd_set, ['no vlan 22'])
70+
71+
cmd_set = self.switch._format_commands(
72+
cisco.CiscoNxOS.PLUG_PORT_TO_NETWORK,
73+
port=3333,
74+
segmentation_id=33)
75+
plug_exp = ['interface 3333', 'switchport mode access',
76+
'switchport access vlan 33', 'exit']
77+
self.assertEqual(plug_exp, cmd_set)
78+
79+
cmd_set = self.switch._format_commands(
80+
cisco.CiscoNxOS.DELETE_PORT,
81+
port=3333,
82+
segmentation_id=33)
83+
del_exp = ['interface 3333', 'no switchport access vlan', 'exit']
84+
self.assertEqual(del_exp, cmd_set)
85+
86+
cmd_set = self.switch._format_commands(
87+
cisco.CiscoNxOS.ADD_NETWORK_TO_TRUNK,
88+
port=3333,
89+
segmentation_id=33)
90+
add_trunk_exp = ['interface 3333', 'switchport mode trunk',
91+
'switchport trunk allowed vlan add 33', 'exit']
92+
self.assertEqual(add_trunk_exp, cmd_set)
93+
94+
cmd_set = self.switch._format_commands(
95+
cisco.CiscoNxOS.REMOVE_NETWORK_FROM_TRUNK,
96+
port=3333,
97+
segmentation_id=33)
98+
del_trunk_exp = ['interface 3333',
99+
'switchport trunk allowed vlan remove 33',
100+
'exit']
101+
self.assertEqual(del_trunk_exp, cmd_set)
102+
103+
cmd_set = self.switch._format_commands(
104+
cisco.CiscoNxOS.ENABLE_PORT,
105+
port=3333)
106+
enable_exp = ['interface 3333', 'no shutdown', 'exit']
107+
self.assertEqual(enable_exp, cmd_set)
108+
109+
cmd_set = self.switch._format_commands(
110+
cisco.CiscoNxOS.DISABLE_PORT,
111+
port=3333)
112+
disable_exp = ['interface 3333', 'shutdown', 'exit']
113+
self.assertEqual(disable_exp, cmd_set)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
features:
3+
- |
4+
Add support for Cisco Nexus devices (NX-OS).

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ neutron.ml2.mechanism_drivers =
3232
generic_switch.devices =
3333
netmiko_ovs_linux = networking_generic_switch.devices.netmiko_devices.ovs:OvsLinux
3434
netmiko_cisco_ios = networking_generic_switch.devices.netmiko_devices.cisco:CiscoIos
35+
netmiko_cisco_nxos = networking_generic_switch.devices.netmiko_devices.cisco:CiscoNxOS
3536
netmiko_cisco_s300= networking_generic_switch.devices.netmiko_devices.cisco300:Cisco300
3637
netmiko_huawei = networking_generic_switch.devices.netmiko_devices.huawei:Huawei
3738
netmiko_huawei_vrpv8 = networking_generic_switch.devices.netmiko_devices.huawei_vrpv8:Huawei

0 commit comments

Comments
 (0)