From: Edgar Magana Date: Mon, 1 Aug 2011 19:40:07 +0000 (-0700) Subject: Adding the Nexus OS driver based on the new PlugIn structure X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=07281aa581dccfde3a98b5c7aa338dad28397b5a;p=openstack-build%2Fneutron-build.git Adding the Nexus OS driver based on the new PlugIn structure --- diff --git a/quantum/plugins/cisco/README b/quantum/plugins/cisco/README index 3bf20a751..2672675cd 100644 --- a/quantum/plugins/cisco/README +++ b/quantum/plugins/cisco/README @@ -7,6 +7,7 @@ * UCS B200 series blades with M81KR VIC installed. * UCSM 2.0 (Capitola) Build 230 * RHEL 6.1 +* ncclcient v0.3.1 - Python library for NETCONF clients (http://schmizz.net/ncclient/) * UCS & VIC installation (support for KVM) - please consult the accompanying installation guide available at: http://wikicentral.cisco.com/display/GROUP/SAVBU+Palo+VM-FEX+for+Linux+KVM * To run Quantum on RHEL, you will need to have the correct version of python-routes (version 1.12.3 or later). The RHEL 6.1 package contains an older version. Do the following and check your python-routes version: @@ -41,6 +42,10 @@ ucs/get-vif.sh + In cisco_configuration.py, - change the UCSM IP in the following statement to your UCSM IP flags.DEFINE_string('ucsm_ip_address', "172.20.231.27", 'IP address of UCSM') + - change the NEXUS 7K IP in the following statement to your N7K Switch IP + flags.DEFINE_string('nexus_ip_address', "172.20.231.61", 'IP address of N7K') + - change the NEXUS Interface in the following statement to the interface number in your N7K which is connected to your UCSM UpLink port + flags.DEFINE_string('nexus_port', "3/23", 'Port number of the Interface connected from the Nexus 7K Switch to UCSM 6120') - change the Nova MySQL DB IP if you are running Quantum on a different host than the OpenStack Cloud Controller (in other words you do not need to change the IP if Quantum is running on the same host on which the Nova DB is running). DB IP is changed in the following statement: flags.DEFINE_string('db_server_ip', "127.0.0.1", 'IP address of nova DB server') - change the hostname of the OpenStack Cloud Controller below @@ -58,9 +63,11 @@ ucs/get-vif.sh - Change the path to reflect the location of the get-vif.sh script, if you have followed the instructions in this README, this location should be the same as that of your other plugin modules flags.DEFINE_string('get_next_vif', "/root/sumit/quantum/quantum/plugins/cisco/get-vif.sh", 'This is the location of the script to get the next available dynamic nic') + In cisco_credentials.py, - - Change the following stucture to reflect the correct UCS and Nova DB details. Your UCSM_IP_ADDRESS has to match the ucsmm_ip_addresss which you provided in the cisco_configuration file earlier. Similarly, your NOVA_DATABSE_IP has to match the db_server_ip which you provided earlier. DB_USERNAME and DB_PASSWORD are those which you provided for the Nova MySQL DB when you setup OpenStack + - Change the following structure to reflect the correct UCS, N7K and Nova DB details. Your UCSM_IP_ADDRESS has to match the ucsmm_ip_addresss which you provided in the cisco_configuration file earlier. Similarly, your NOVA_DATABSE_IP has to match the db_server_ip which you provided earlier. DB_USERNAME and DB_PASSWORD are those which you provided for the Nova MySQL DB when you setup OpenStack + N7K_IP_ADDRESS has to match with your Nexus 7k switch IP Address, N7K_USERNAME is the administrator user-name and N7K_PASSWORD is the password. _creds_dictionary = { 'UCSM_IP_ADDRESS':["UCSM_USERNAME", "UCSM_PASSWORD"], + 'N7K_IP_ADDRESS':["N7K_USERNAME", "N7K_PASSWORD"], 'NOVA_DATABASE_IP':["DB_USERNAME", "DB_PASSWORD"] } * Start the Quantum service diff --git a/quantum/plugins/cisco/common/cisco_configuration.py b/quantum/plugins/cisco/common/cisco_configuration.py index 5ab2aaf33..12ca0d428 100644 --- a/quantum/plugins/cisco/common/cisco_configuration.py +++ b/quantum/plugins/cisco/common/cisco_configuration.py @@ -15,6 +15,7 @@ # under the License. # # @author: Sumit Naiksatam, Cisco Systems, Inc. +# @author: Edgar Magana, Cisco Systems, Inc. # from quantum.common import flags @@ -26,6 +27,10 @@ FLAGS = flags.FLAGS # flags.DEFINE_string('ucsm_ip_address', "172.20.231.27", 'IP address of \ UCSM') +flags.DEFINE_string('nexus_ip_address', "172.20.231.61", 'IP address of \ + Nexus Switch') +flags.DEFINE_string('nexus_port', "3/23", 'Port number of the Interface \ + connected from the Nexus Switch to UCSM 6120') flags.DEFINE_string('db_server_ip', "127.0.0.1", 'IP address of nova DB \ server') flags.DEFINE_string('nova_host_name', "openstack-0203", 'nova cloud \ @@ -68,6 +73,8 @@ flags.DEFINE_string('get_next_vif', # Inventory items UCSM_IP_ADDRESS = FLAGS.ucsm_ip_address +NEXUS_IP_ADDRESS = FLAGS.nexus_ip_address +NEXUS_PORT = FLAGS.nexus_port DB_SERVER_IP = FLAGS.db_server_ip NOVA_HOST_NAME = FLAGS.nova_host_name diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py b/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py new file mode 100644 index 000000000..2e95409d3 --- /dev/null +++ b/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py @@ -0,0 +1,236 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# Copyright 2011 Cisco Systems, Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# @author: Debojyoti Dutta, Cisco Systems, Inc. +# @author: Edgar Magana, Cisco Systems Inc. +# +""" +Implements a Nexus-OS NETCONF over SSHv2 API Client +""" + +import logging as LOG +import string +import subprocess + +from quantum.plugins.cisco.common import cisco_configuration as conf +from quantum.plugins.cisco.common import cisco_constants as const +from quantum.plugins.cisco.common import cisco_exceptions as cexc + +from ncclient import manager + +LOG.basicConfig(level=LOG.WARN) +LOG.getLogger(const.LOGGER_COMPONENT_NAME) + + +# The following are standard strings, messages used to communicate with Nexus, +#only place holder values change for each message +exec_conf_prefix = """ + + + <__XML__MODE__exec_configure> +""" + + +exec_conf_postfix = """ + + + +""" + + +cmd_vlan_conf_snippet = """ + + + <__XML__PARAM_value>%s + <__XML__MODE_vlan> + + %s + + + active + + + + + + + +""" + +cmd_no_vlan_conf_snippet = """ + + + + <__XML__PARAM_value>%s + + + +""" + +cmd_vlan_int_snippet = """ + + + %s + <__XML__MODE_if-ethernet-switch> + + + + + + <__XML__BLK_Cmd_switchport_trunk_allowed_allow-vlans> + %s + + + + + + + + +""" + +cmd_port_trunk = """ + + + %s + <__XML__MODE_if-ethernet-switch> + + + + + + + + + + +""" + +cmd_no_switchport = """ + + + %s + <__XML__MODE_if-ethernet-switch> + + + + + + + +""" + + +cmd_no_vlan_int_snippet = """ + + + %s + <__XML__MODE_if-ethernet-switch> + + + + + + + <__XML__BLK_Cmd_switchport_trunk_allowed_allow-vlans> + %s + + + + + + + + + +""" + + +filter_show_vlan_brief_snippet = """ + + + + + """ + + +class CiscoNEXUSDriver(): + + def __init__(self): + pass + + def nxos_connect(self, nexus_host, port, nexus_user, nexus_password): + m = manager.connect(host=nexus_host, port=22, username=nexus_user, + password=nexus_password) + return m + + def enable_vlan(self, mgr, vlanid, vlanname): + confstr = cmd_vlan_conf_snippet % (vlanid, vlanname) + confstr = exec_conf_prefix + confstr + exec_conf_postfix + mgr.edit_config(target='running', config=confstr) + + def disable_vlan(self, mgr, vlanid): + confstr = cmd_no_vlan_conf_snippet % vlanid + confstr = exec_conf_prefix + confstr + exec_conf_postfix + mgr.edit_config(target='running', config=confstr) + + def enable_port_trunk(self, mgr, interface): + confstr = cmd_port_trunk % (interface) + confstr = exec_conf_prefix + confstr + exec_conf_postfix + print confstr + mgr.edit_config(target='running', config=confstr) + + def enable_vlan_on_trunk_int(self, mgr, interface, vlanid): + confstr = cmd_vlan_int_snippet % (interface, vlanid) + confstr = exec_conf_prefix + confstr + exec_conf_postfix + print confstr + mgr.edit_config(target='running', config=confstr) + + def disable_vlan_on_trunk_int(self, mgr, interface, vlanid): + confstr = cmd_no_vlan_int_snippet % (interface, vlanid) + confstr = exec_conf_prefix + confstr + exec_conf_postfix + print confstr + mgr.edit_config(target='running', config=confstr) + + def test_nxos_api(self, host, user, password): + with self.nxos_connect(host, port=22, user=user, + password=password) as m: + #enable_vlan(m, '100', 'ccn1') + #enable_vlan_on_trunk_int(m, '2/1', '100') + #disable_vlan_on_trunk_int(m, '2/1', '100') + #disable_vlan(m, '100') + result = m.get(("subtree", filter_show_vlan_brief_snippet)) + print result + + def create_vlan(self, vlan_name, vlan_id, nexus_host, nexus_user, + nexus_password, nexus_interface): + #TODO (Edgar) Move the SSH port to the configuration file + with self.nxos_connect(nexus_host, 22, nexus_user, + nexus_password) as m: + self.enable_vlan(m, vlan_id, vlan_name) + self.enable_port_trunk(m, nexus_interface) + + def delete_vlan(self, vlan_id, nexus_host, nexus_user, nexus_password): + with self.nxos_connect(nexus_host, 22, nexus_user, + nexus_password) as m: + self.disable_vlan(m, vlan_id) + + +def main(): + client = CiscoNEXUSDriver() + +if __name__ == '__main__': + main() diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_plugin.py b/quantum/plugins/cisco/nexus/cisco_nexus_plugin.py index 9d55115ab..4d8cfa654 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_plugin.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_plugin.py @@ -15,6 +15,7 @@ # under the License. # # @author: Sumit Naiksatam, Cisco Systems, Inc. +# @author: Edgar Magana, Cisco Systems, Inc. # import logging as LOG @@ -25,6 +26,8 @@ from quantum.plugins.cisco.common import cisco_credentials as cred from quantum.plugins.cisco.common import cisco_exceptions as cexc from quantum.plugins.cisco.common import cisco_utils as cutil +from quantum.plugins.cisco.nexus import cisco_nexus_network_driver + LOG.basicConfig(level=LOG.WARN) LOG.getLogger(const.LOGGER_COMPONENT_NAME) @@ -33,10 +36,12 @@ class NexusPlugin(object): _networks = {} def __init__(self): - """ - Initialize the Nexus driver here - """ - pass + self._client = cisco_nexus_network_driver.CiscoNEXUSDriver() + #TODO (Edgar) Using just one Nexus 7K Switch and Port + 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 def get_all_networks(self, tenant_id): """ @@ -53,8 +58,9 @@ class NexusPlugin(object): for this VLAN """ LOG.debug("NexusPlugin:create_network() called\n") - # TODO (Sumit): Call the nexus driver here to create the VLAN, and - # configure the appropriate interfaces + self._client.create_vlan(vlan_name, str(vlan_id), self._nexus_ip, + self._nexus_username, self._nexus_password, self._nexus_port) + new_net_dict = {const.NET_ID: net_id, const.NET_NAME: net_name, const.NET_PORTS: {}, @@ -70,9 +76,10 @@ class NexusPlugin(object): """ 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) if net: - # TODO (Sumit): Call the nexus driver here to create the VLAN, - # and configure the appropriate interfaces + self._client.delete_vlan(str(vlan_id), self._nexus_ip, + self._nexus_username, self._nexus_password) self._networks.pop(net_id) return net # Network not found @@ -145,6 +152,11 @@ class NexusPlugin(object): """ LOG.debug("NexusPlugin:unplug_interface() called\n") + def _get_vlan_id_for_network(self, tenant_id, network_id): + net = self._get_network(tenant_id, network_id) + vlan_id = net[const.NET_VLAN_ID] + return vlan_id + def _get_network(self, tenant_id, network_id): network = self._networks.get(network_id) if not network: