]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Enables Cisco NXOS to configure multiple ports
authorEdgar Magana <emagana@gmail.com>
Tue, 7 Aug 2012 08:20:47 +0000 (01:20 -0700)
committerEdgar Magana <emagana@gmail.com>
Tue, 14 Aug 2012 06:21:34 +0000 (23:21 -0700)
Implements blueprint cisco-nxos-enables-multiple-ports

Change-Id: I4e8bccff19eb5b13895d7083623b7291b8c8bf7e

etc/quantum/plugins/cisco/nexus.ini
quantum/plugins/cisco/README
quantum/plugins/cisco/common/cisco_exceptions.py
quantum/plugins/cisco/network_plugin.py
quantum/plugins/cisco/nexus/cisco_nexus_configuration.py
quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py
quantum/plugins/cisco/nexus/cisco_nexus_plugin_v2.py
quantum/plugins/cisco/nexus/cisco_nexus_snippets.py
quantum/plugins/cisco/tests/unit/v2/nexus/fake_nexus_driver.py

index c305db4e3f92be0b9d6f3288684ee8a11e6a87de..b5015db831abdd09b99f687198843d4bbd0edc0b 100644 (file)
@@ -1,9 +1,8 @@
 [SWITCH]
 # Change the following to reflect the Nexus switch details
 nexus_ip_address=<put_nexus_switch_ip_address_here>
-#Interfaces connected from the Nexus 7K Switch to the two UCSM 6120s, e.g.: 1/10 and 1/11
-nexus_first_port=<put_interface_name_here>
-nexus_second_port=<put_interface_name_here>
+#Interfaces connected from the Nexus Switch to the compute hosts ports, e.g.: 1/10 and 1/11
+ports=<put_interfaces_names_here_separated_by_commas>
 #Port number where the SSH will be running at the Nexus Switch, e.g.: 22 (Default) 
 nexus_ssh_port=22
 
index b81ab269f9300bd18c9e648fddda3ac863459895..0e3302c80147dd9e7c13faee9fe195866dfdc44f 100755 (executable)
@@ -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
index 2623f745cfee27e36de1071cf0dc91139209c191..b8d4792607275a901a81a047b7a36f104b6f78f2 100644 (file)
@@ -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")
index c3d2ac25c6253b52db8c02c9ea81e60bfdd7dc8a..5c7fbf8aa7906b32a8d6c5496d6599c62b4e24cd 100644 (file)
@@ -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__)
 
index 790a351ab08745d337dc403b70ab76fc5f969c80..4d648d93ddd63ce5e7b144964c6081231c1e4903 100644 (file)
@@ -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']
index 34e599d738f573a09026161d96b07e0be935b43c..e87a983b20c240dbeec37978074c7af3fe15e07c 100644 (file)
@@ -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):
         """
index 8fcc0601c9db6fad7354791853fea3dcc093e2ed..e893a996e341169c4aaa54c35153f8cceea253ca 100644 (file)
@@ -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)
index ad8217803dae5829d460d985f2f2151ebbbbbdab..0ff0bebedb76d12c896298cec7f24ad7ea74822c 100644 (file)
@@ -99,7 +99,7 @@ CMD_PORT_TRUNK = """
                     </trunk>
                   </mode>
                 </switchport>
-              </__XML__MODE_if-ethernet-switch>C:  1: Missing docstring
+              </__XML__MODE_if-ethernet-switch>
             </ethernet>
           </interface>
 """
@@ -121,7 +121,7 @@ CMD_NO_SWITCHPORT = """
 
 CMD_NO_VLAN_INT_SNIPPET = """
           <interface>
-            <ethernet>C:  1: Missing docstring
+            <ethernet>
               <interface>%s</interface>
               <__XML__MODE_if-ethernet-switch>
                 <switchport></switchport>
index 1f25cde3142d2539c97af505f13662d7ec0ea5ce..2180ab2f1d46d647f82110e99c51a0e0da7fece4 100644 (file)
@@ -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