From a1212174c07370284694093063530e6b430df1d5 Mon Sep 17 00:00:00 2001 From: Edgar Magana Date: Tue, 7 Aug 2012 01:20:47 -0700 Subject: [PATCH] Enables Cisco NXOS to configure multiple ports Implements blueprint cisco-nxos-enables-multiple-ports Change-Id: I4e8bccff19eb5b13895d7083623b7291b8c8bf7e --- etc/quantum/plugins/cisco/nexus.ini | 5 ++--- quantum/plugins/cisco/README | 13 +++++------- .../plugins/cisco/common/cisco_exceptions.py | 5 +++++ quantum/plugins/cisco/network_plugin.py | 2 +- .../cisco/nexus/cisco_nexus_configuration.py | 3 +-- .../cisco/nexus/cisco_nexus_network_driver.py | 20 +++++++------------ .../cisco/nexus/cisco_nexus_plugin_v2.py | 19 +++++++++--------- .../cisco/nexus/cisco_nexus_snippets.py | 4 ++-- .../tests/unit/v2/nexus/fake_nexus_driver.py | 6 ++---- 9 files changed, 35 insertions(+), 42 deletions(-) diff --git a/etc/quantum/plugins/cisco/nexus.ini b/etc/quantum/plugins/cisco/nexus.ini index c305db4e3..b5015db83 100644 --- a/etc/quantum/plugins/cisco/nexus.ini +++ b/etc/quantum/plugins/cisco/nexus.ini @@ -1,9 +1,8 @@ [SWITCH] # Change the following to reflect the Nexus switch details nexus_ip_address= -#Interfaces connected from the Nexus 7K Switch to the two UCSM 6120s, e.g.: 1/10 and 1/11 -nexus_first_port= -nexus_second_port= +#Interfaces connected from the Nexus Switch to the compute hosts ports, e.g.: 1/10 and 1/11 +ports= #Port number where the SSH will be running at the Nexus Switch, e.g.: 22 (Default) nexus_ssh_port=22 diff --git a/quantum/plugins/cisco/README b/quantum/plugins/cisco/README index b81ab269f..0e3302c80 100755 --- a/quantum/plugins/cisco/README +++ b/quantum/plugins/cisco/README @@ -97,10 +97,9 @@ nexus_plugin=quantum.plugins.cisco.nexus.cisco_nexus_plugin_v2.NexusPlugin # This will be the address at which Quantum sends and receives configuration # information via SSHv2. nexus_ip_address=10.0.0.1 -# Port numbers on the Nexus switch to each one of the UCSM 6120s is connected -# Use shortened interface syntax, e.g. "1/10" not "Ethernet1/10". -nexus_first_port=1/10 -nexus_second_port=1/11 +# Port numbers on the Nexus switch to each one of the compute nodes are connected +# Use shortened interface syntax, e.g. "1/10" not "Ethernet1/10" and "," between ports. +ports=1/10,1/11,1/12 #Port number where SSH will be running on the Nexus switch. Typically this is 22 #unless you've configured your switch otherwise. nexus_ssh_port=22 @@ -278,16 +277,14 @@ nexus_plugin=quantum.plugins.cisco.nexus.cisco_nexus_plugin_v2.NexusPlugin When not using Nexus hardware use the following dummy configuration verbatim: [SWITCH] nexus_ip_address=1.1.1.1 -nexus_first_port=1/10 -nexus_second_port=1/11 +ports=1/10,1/11,1/12 nexus_ssh_port=22 [DRIVER] name=quantum.plugins.cisco.tests.unit.v2.nexus.fake_nexus_driver.CiscoNEXUSFakeDriver Or when using Nexus hardware (put the values relevant to your setup): [SWITCH] nexus_ip_address=1.1.1.1 -nexus_first_port=1/10 -nexus_second_port=1/11 +ports=1/10,1/11,1/12 nexus_ssh_port=22 [DRIVER] name=quantum.plugins.cisco.nexus.cisco_nexus_network_driver.CiscoNEXUSDriver diff --git a/quantum/plugins/cisco/common/cisco_exceptions.py b/quantum/plugins/cisco/common/cisco_exceptions.py index 2623f745c..b8d479260 100644 --- a/quantum/plugins/cisco/common/cisco_exceptions.py +++ b/quantum/plugins/cisco/common/cisco_exceptions.py @@ -137,6 +137,11 @@ class NexusPortBindingNotFound(exceptions.QuantumException): message = _("Nexus Port Binding %(port_id) is not present") +class NexusPortBindingAlreadyExists(exceptions.QuantumException): + """NexusPort Binding alredy exists""" + message = _("Nexus Port Binding %(port_id) already exists") + + class UcsmBindingNotFound(exceptions.QuantumException): """Ucsm Binding is not present""" message = _("Ucsm Binding with ip %(ucsm_ip) is not present") diff --git a/quantum/plugins/cisco/network_plugin.py b/quantum/plugins/cisco/network_plugin.py index c3d2ac25c..5c7fbf8aa 100644 --- a/quantum/plugins/cisco/network_plugin.py +++ b/quantum/plugins/cisco/network_plugin.py @@ -29,7 +29,7 @@ from quantum.plugins.cisco.common import cisco_exceptions as cexc from quantum.plugins.cisco.common import cisco_utils as cutil from quantum.plugins.cisco.db import network_db_v2 as cdb from quantum.plugins.cisco import l2network_plugin_configuration as conf -from quantum.quantum_plugin_base import QuantumPluginBase +from quantum.quantum_plugin_base_v2 import QuantumPluginBaseV2 LOG = logging.getLogger(__name__) diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_configuration.py b/quantum/plugins/cisco/nexus/cisco_nexus_configuration.py index 790a351ab..4d648d93d 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_configuration.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_configuration.py @@ -32,8 +32,7 @@ CP = confp.CiscoConfigParser(find_config_file({'plugin': 'cisco'}, SECTION = CP['SWITCH'] NEXUS_IP_ADDRESS = SECTION['nexus_ip_address'] -NEXUS_FIRST_PORT = SECTION['nexus_first_port'] -NEXUS_SECOND_PORT = SECTION['nexus_second_port'] +NEXUS_PORTS = SECTION['ports'] NEXUS_SSH_PORT = SECTION['nexus_ssh_port'] SECTION = CP['DRIVER'] diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py b/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py index 34e599d73..e87a983b2 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py @@ -25,7 +25,7 @@ import logging from ncclient import manager -from quantum.plugins.cisco.db import l2network_db as cdb +from quantum.plugins.cisco.db import network_db_v2 as cdb from quantum.plugins.cisco.nexus import cisco_nexus_snippets as snipp @@ -110,8 +110,7 @@ class CiscoNEXUSDriver(): mgr.edit_config(target='running', config=confstr) def create_vlan(self, vlan_name, vlan_id, nexus_host, nexus_user, - nexus_password, nexus_first_interface, - nexus_second_interface, nexus_ssh_port): + nexus_password, nexus_ports, nexus_ssh_port): """ Creates a VLAN and Enable on trunk mode an interface on Nexus Switch given the VLAN ID and Name and Interface Number @@ -121,14 +120,11 @@ class CiscoNEXUSDriver(): self.enable_vlan(man, vlan_id, vlan_name) vlan_ids = self.build_vlans_cmd() LOG.debug("NexusDriver VLAN IDs: %s" % vlan_ids) - self.enable_vlan_on_trunk_int(man, nexus_first_interface, - vlan_ids) - self.enable_vlan_on_trunk_int(man, nexus_second_interface, - vlan_ids) + for ports in nexus_ports: + self.enable_vlan_on_trunk_int(man, ports, vlan_ids) def delete_vlan(self, vlan_id, nexus_host, nexus_user, nexus_password, - nexus_first_interface, nexus_second_interface, - nexus_ssh_port): + nexus_ports, nexus_ssh_port): """ Delete a VLAN and Disables trunk mode an interface on Nexus Switch given the VLAN ID and Interface Number @@ -136,10 +132,8 @@ class CiscoNEXUSDriver(): with self.nxos_connect(nexus_host, int(nexus_ssh_port), nexus_user, nexus_password) as man: self.disable_vlan(man, vlan_id) - self.disable_vlan_on_trunk_int(man, nexus_first_interface, - vlan_id) - self.disable_vlan_on_trunk_int(man, nexus_second_interface, - vlan_id) + for ports in nexus_ports: + self.disable_vlan_on_trunk_int(man, ports, vlan_id) def build_vlans_cmd(self): """ diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py b/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py index 8fcc0601c..e893a996e 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py @@ -26,7 +26,8 @@ from quantum.common import exceptions as exc from quantum.db import api as db from quantum.openstack.common import importutils from quantum.plugins.cisco.common import cisco_constants as const -from quantum.plugins.cisco.common import cisco_credentials as cred +from quantum.plugins.cisco.common import cisco_credentials_v2 as cred +from quantum.plugins.cisco.common import cisco_exceptions as excep from quantum.plugins.cisco.db import network_db_v2 as cdb from quantum.plugins.cisco.db import nexus_db_v2 as nxos_db from quantum.plugins.cisco.l2device_plugin_base import L2DevicePluginBase @@ -51,8 +52,7 @@ class NexusPlugin(L2DevicePluginBase): self._nexus_ip = conf.NEXUS_IP_ADDRESS self._nexus_username = cred.Store.get_username(conf.NEXUS_IP_ADDRESS) self._nexus_password = cred.Store.get_password(conf.NEXUS_IP_ADDRESS) - self._nexus_first_port = conf.NEXUS_FIRST_PORT - self._nexus_second_port = conf.NEXUS_SECOND_PORT + self._nexus_ports = conf.NEXUS_PORTS self._nexus_ssh_port = conf.NEXUS_SSH_PORT def get_all_networks(self, tenant_id): @@ -74,10 +74,12 @@ class NexusPlugin(L2DevicePluginBase): self._client.create_vlan( vlan_name, str(vlan_id), self._nexus_ip, self._nexus_username, self._nexus_password, - self._nexus_first_port, self._nexus_second_port, - self._nexus_ssh_port) - nxos_db.add_nexusport_binding(self._nexus_first_port, str(vlan_id)) - nxos_db.add_nexusport_binding(self._nexus_second_port, str(vlan_id)) + self._nexus_ports, self._nexus_ssh_port) + for ports in self._nexus_ports: + try: + nxos_db.add_nexusport_binding(ports, str(vlan_id)) + except: + raise excep.NexusPortBindingAlreadyExists(port_id=ports) new_net_dict = {const.NET_ID: net_id, const.NET_NAME: net_name, @@ -105,8 +107,7 @@ class NexusPlugin(L2DevicePluginBase): self._client.delete_vlan( str(vlan_id), self._nexus_ip, self._nexus_username, self._nexus_password, - self._nexus_first_port, self._nexus_second_port, - self._nexus_ssh_port) + self._nexus_ports, self._nexus_ssh_port) return net # Network not found raise exc.NetworkNotFound(net_id=net_id) diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_snippets.py b/quantum/plugins/cisco/nexus/cisco_nexus_snippets.py index ad8217803..0ff0bebed 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_snippets.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_snippets.py @@ -99,7 +99,7 @@ CMD_PORT_TRUNK = """ - C: 1: Missing docstring + """ @@ -121,7 +121,7 @@ CMD_NO_SWITCHPORT = """ CMD_NO_VLAN_INT_SNIPPET = """ - C: 1: Missing docstring + %s <__XML__MODE_if-ethernet-switch> diff --git a/quantum/plugins/cisco/tests/unit/v2/nexus/fake_nexus_driver.py b/quantum/plugins/cisco/tests/unit/v2/nexus/fake_nexus_driver.py index 1f25cde31..2180ab2f1 100644 --- a/quantum/plugins/cisco/tests/unit/v2/nexus/fake_nexus_driver.py +++ b/quantum/plugins/cisco/tests/unit/v2/nexus/fake_nexus_driver.py @@ -77,8 +77,7 @@ class CiscoNEXUSFakeDriver(): pass def create_vlan(self, vlan_name, vlan_id, nexus_host, nexus_user, - nexus_password, nexus_first_interface, - nexus_second_interface, nexus_ssh_port): + nexus_password, nexus_ports, nexus_ssh_port): """ Creates a VLAN and Enable on trunk mode an interface on Nexus Switch given the VLAN ID and Name and Interface Number @@ -86,8 +85,7 @@ class CiscoNEXUSFakeDriver(): pass def delete_vlan(self, vlan_id, nexus_host, nexus_user, nexus_password, - nexus_first_interface, nexus_second_interface, - nexus_ssh_port): + nexus_ports, nexus_ssh_port): """ Delete a VLAN and Disables trunk mode an interface on Nexus Switch given the VLAN ID and Interface Number -- 2.45.2