]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Adding the Nexus support to the Persistence Framwork
authorEdgar Magana <eperdomo@cisco.com>
Fri, 19 Aug 2011 17:13:53 +0000 (10:13 -0700)
committerEdgar Magana <eperdomo@cisco.com>
Fri, 19 Aug 2011 17:13:53 +0000 (10:13 -0700)
Modification of the Nexus Unit Case to be running with Persistence Framework
pep8 passed
pylint 8.81/10

quantum/plugins/cisco/README
quantum/plugins/cisco/conf/nexus.ini
quantum/plugins/cisco/nexus/cisco_nexus_configuration.py
quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py
quantum/plugins/cisco/nexus/cisco_nexus_plugin.py
quantum/plugins/cisco/tests/unit/test_nexus_plugin.py

index 2ef3a0c082306201a561ddb704db4e3fbede1306..f7674401a056c10d2db494bc712dbb699beb42f8 100755 (executable)
@@ -118,9 +118,10 @@ nexus_plugin=quantum.plugins.cisco.nexus.cisco_nexus_plugin.NexusPlugin
 # This will be the address at which Quantum sends and receives configuration\r
 # information via SSHv2.\r
 nexus_ip_address=10.0.0.1\r
-# Port number on the Nexus switch to which the UCSM 6120 is connected\r
-# Use shortened interface syntax, e.g. "3/23" not "Ethernet3/23".\r
-nexus_port=3/23\r
+# Port numbers on the Nexus switch to each one of the UCSM 6120s is connected\r
+# Use shortened interface syntax, e.g. "1/10" not "Ethernet1/10".\r
+nexus_first_port=1/10\r
+nexus_second_port=1/11\r
 #Port number where the SSH will be running at Nexus Switch, e.g.: 22 (Default) \r
 nexus_ssh_port=22\r
 \r
index a4efcb2060b12cda7930c0cecf548963d04f06e2..50d8e54beb6441f907a407458540ec96ce5551b5 100644 (file)
@@ -1,8 +1,9 @@
 [SWITCH]
 # Change the following to reflect the Nexus switch details
 nexus_ip_address=<put_nexus_switch_ip_address_here>
-#Port number of the Interface connected from the Nexus 7K Switch to UCSM 6120, e.g.: 3/23
-nexus_port=<put_interface_name_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>
 #Port number where the SSH will be running at the Nexus Switch, e.g.: 22 (Default) 
 nexus_ssh_port=22
 
index f0394dcb2454f3f52fcb3d664cbd3257098c9bef..13457e7da379e7b4dbc9ba3b805379aa7c71547e 100644 (file)
@@ -33,7 +33,8 @@ CP = confp.CiscoConfigParser(os.path.dirname(os.path.realpath(__file__)) \
 
 SECTION = CP['SWITCH']
 NEXUS_IP_ADDRESS = SECTION['nexus_ip_address']
-NEXUS_PORT = SECTION['nexus_port']
+NEXUS_FIRST_PORT = SECTION['nexus_first_port']
+NEXUS_SECOND_PORT = SECTION['nexus_second_port']
 NEXUS_SSH_PORT = SECTION['nexus_ssh_port']
 
 SECTION = CP['DRIVER']
index 3f92353492e4b6bef4cb4860b551c1fe3d26dfa6..f533c9f766b4a64578f22c368b0db3760095f86c 100644 (file)
@@ -103,7 +103,8 @@ class CiscoNEXUSDriver():
         mgr.edit_config(target='running', config=confstr)
 
     def create_vlan(self, vlan_name, vlan_id, nexus_host, nexus_user,
-                    nexus_password, nexus_interface, nexus_ssh_port):
+                    nexus_password, nexus_first_interface,
+                    nexus_second_interface, 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
@@ -111,10 +112,12 @@ class CiscoNEXUSDriver():
         with self.nxos_connect(nexus_host, int(nexus_ssh_port), nexus_user,
                                nexus_password) as man:
             self.enable_vlan(man, vlan_id, vlan_name)
-            self.enable_vlan_on_trunk_int(man, nexus_interface, vlan_id)
+            self.enable_vlan_on_trunk_int(man, nexus_first_interface, vlan_id)
+            self.enable_vlan_on_trunk_int(man, nexus_second_interface, vlan_id)
 
-    def delete_vlan(self, vlan_id, nexus_host, nexus_user,
-                    nexus_password, nexus_interface, nexus_ssh_port):
+    def delete_vlan(self, vlan_id, nexus_host, nexus_user, nexus_password,
+                    nexus_first_interface, nexus_second_interface,
+                    nexus_ssh_port):
         """
         Delete a VLAN and Disables trunk mode an interface on Nexus Switch
         given the VLAN ID and Interface Number
@@ -122,4 +125,5 @@ 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_switch_port(man, nexus_interface)
+            self.disable_switch_port(man, nexus_first_interface)
+            self.disable_switch_port(man, nexus_second_interface)
index 84085ff3f0807c2825fdbaa445c745bd786b4ac1..62f3806f32468db391efd03a5368d0215219f6a6 100644 (file)
@@ -28,6 +28,7 @@ from quantum.plugins.cisco.common import cisco_constants as const
 from quantum.plugins.cisco.common import cisco_credentials as cred
 from quantum.plugins.cisco.l2device_plugin_base import L2DevicePluginBase
 from quantum.plugins.cisco.nexus import cisco_nexus_configuration as conf
+from quantum.plugins.cisco.db import nexus_db as nxos_db
 
 LOG.basicConfig(level=LOG.WARN)
 LOG.getLogger(const.LOGGER_COMPONENT_NAME)
@@ -48,7 +49,8 @@ class NexusPlugin(L2DevicePluginBase):
         self._nexus_ip = conf.NEXUS_IP_ADDRESS
         self._nexus_username = cred.Store.getUsername(conf.NEXUS_IP_ADDRESS)
         self._nexus_password = cred.Store.getPassword(conf.NEXUS_IP_ADDRESS)
-        self._nexus_port = conf.NEXUS_PORT
+        self._nexus_first_port = conf.NEXUS_FIRST_PORT
+        self._nexus_second_port = conf.NEXUS_SECOND_PORT
         self._nexus_ssh_port = conf.NEXUS_SSH_PORT
 
     def get_all_networks(self, tenant_id):
@@ -68,8 +70,11 @@ class NexusPlugin(L2DevicePluginBase):
         """
         LOG.debug("NexusPlugin:create_network() called\n")
         self._client.create_vlan(vlan_name, str(vlan_id), self._nexus_ip,
-                self._nexus_username, self._nexus_password, self._nexus_port,
+                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))
 
         new_net_dict = {const.NET_ID: net_id,
                         const.NET_NAME: net_name,
@@ -85,11 +90,15 @@ class NexusPlugin(L2DevicePluginBase):
         from the relevant interfaces
         """
         LOG.debug("NexusPlugin:delete_network() called\n")
-        net = self._networks.get(net_id)
         vlan_id = self._get_vlan_id_for_network(tenant_id, net_id)
+        ports_id = nxos_db.get_nexusport_binding(vlan_id)
+        LOG.debug("NexusPlugin: Interfaces to be disassociated: %s" % ports_id)
+        nxos_db.remove_nexusport_binding(vlan_id)
+        net = self._networks.get(net_id)
         if net:
             self._client.delete_vlan(str(vlan_id), self._nexus_ip,
-                self._nexus_username, self._nexus_password, self._nexus_port,
+                self._nexus_username, self._nexus_password,
+                self._nexus_first_port, self._nexus_second_port,
                 self._nexus_ssh_port)
             self._networks.pop(net_id)
             return net
index d77985b17522eb54c94f449d54f3b6bc2e5f11f9..e9f95f1fca1051acd191228d36a9a12f66d55650 100644 (file)
@@ -19,6 +19,7 @@ import logging
 from quantum.common import exceptions as exc
 from quantum.plugins.cisco.common import cisco_constants as const
 from quantum.plugins.cisco.nexus import cisco_nexus_plugin
+from quantum.plugins.cisco.db import l2network_db as cdb
 
 LOG = logging.getLogger('quantum.tests.test_nexus')
 
@@ -34,6 +35,7 @@ class TestNexusPlugin(unittest.TestCase):
         self.vlan_id = 267
         self.port_id = "9"
         self._cisco_nexus_plugin = cisco_nexus_plugin.NexusPlugin()
+        cdb.initialize()
 
     def test_create_network(self, net_tenant_id=None, network_name=None,
                             network_id=None, net_vlan_name=None,
@@ -66,7 +68,6 @@ class TestNexusPlugin(unittest.TestCase):
 
         new_net_dict = self._cisco_nexus_plugin.create_network(
                 tenant_id, net_name, net_id, vlan_name, vlan_id)
-
         self.assertEqual(new_net_dict[const.NET_ID], self.net_id)
         self.assertEqual(new_net_dict[const.NET_NAME], self.net_name)
         self.assertEqual(new_net_dict[const.NET_VLAN_NAME], self.vlan_name)