From ea89f123382617f0c86843b63ae1ed6c162a48d0 Mon Sep 17 00:00:00 2001 From: Edgar Magana Date: Fri, 19 Aug 2011 10:13:53 -0700 Subject: [PATCH] Adding the Nexus support to the Persistence Framwork Modification of the Nexus Unit Case to be running with Persistence Framework pep8 passed pylint 8.81/10 --- quantum/plugins/cisco/README | 7 ++++--- quantum/plugins/cisco/conf/nexus.ini | 5 +++-- .../cisco/nexus/cisco_nexus_configuration.py | 3 ++- .../cisco/nexus/cisco_nexus_network_driver.py | 14 +++++++++----- .../plugins/cisco/nexus/cisco_nexus_plugin.py | 17 +++++++++++++---- .../cisco/tests/unit/test_nexus_plugin.py | 3 ++- 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/quantum/plugins/cisco/README b/quantum/plugins/cisco/README index 2ef3a0c08..f7674401a 100755 --- a/quantum/plugins/cisco/README +++ b/quantum/plugins/cisco/README @@ -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 # information via SSHv2. nexus_ip_address=10.0.0.1 -# Port number on the Nexus switch to which the UCSM 6120 is connected -# Use shortened interface syntax, e.g. "3/23" not "Ethernet3/23". -nexus_port=3/23 +# 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 number where the SSH will be running at Nexus Switch, e.g.: 22 (Default) nexus_ssh_port=22 diff --git a/quantum/plugins/cisco/conf/nexus.ini b/quantum/plugins/cisco/conf/nexus.ini index a4efcb206..50d8e54be 100644 --- a/quantum/plugins/cisco/conf/nexus.ini +++ b/quantum/plugins/cisco/conf/nexus.ini @@ -1,8 +1,9 @@ [SWITCH] # Change the following to reflect the Nexus switch details nexus_ip_address= -#Port number of the Interface connected from the Nexus 7K Switch to UCSM 6120, e.g.: 3/23 -nexus_port= +#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= #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/nexus/cisco_nexus_configuration.py b/quantum/plugins/cisco/nexus/cisco_nexus_configuration.py index f0394dcb2..13457e7da 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_configuration.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_configuration.py @@ -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'] diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py b/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py index 3f9235349..f533c9f76 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py @@ -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) diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_plugin.py b/quantum/plugins/cisco/nexus/cisco_nexus_plugin.py index 84085ff3f..62f3806f3 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_plugin.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_plugin.py @@ -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 diff --git a/quantum/plugins/cisco/tests/unit/test_nexus_plugin.py b/quantum/plugins/cisco/tests/unit/test_nexus_plugin.py index d77985b17..e9f95f1fc 100644 --- a/quantum/plugins/cisco/tests/unit/test_nexus_plugin.py +++ b/quantum/plugins/cisco/tests/unit/test_nexus_plugin.py @@ -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) -- 2.45.2