From: eperdomo@cisco.com <> Date: Tue, 16 Aug 2011 00:17:20 +0000 (-0700) Subject: pep8 passed X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=c1aeab091984af76650589ea74f459edfada7401;p=openstack-build%2Fneutron-build.git pep8 passed pylint 8.83 --- diff --git a/quantum/plugins/cisco/nexus/__init__.py b/quantum/plugins/cisco/nexus/__init__.py index db695fb0a..963eb547f 100644 --- a/quantum/plugins/cisco/nexus/__init__.py +++ b/quantum/plugins/cisco/nexus/__init__.py @@ -15,4 +15,7 @@ # under the License. # # @author: Sumit Naiksatam, Cisco Systems, Inc. -# +# @author: Edgar Magana, Cisco Systems, Inc. +""" +Init module for Nexus Driver +""" diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_configuration.py b/quantum/plugins/cisco/nexus/cisco_nexus_configuration.py index b8987a5ce..507ccd2a6 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_configuration.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_configuration.py @@ -17,26 +17,33 @@ # @author: Sumit Naiksatam, Cisco Systems, Inc. # @author: Edgar Magana, Cisco Systems, Inc. # - +""" +Configuration consolidation for the Nexus Driver +This module will export the configuration parameters +from the nexus.ini file +""" import os from quantum.plugins.cisco.common import cisco_configparser as confp CONF_FILE = "../conf/nexus.ini" -cp = confp.CiscoConfigParser(os.path.dirname(os.path.realpath(__file__)) \ +CP = confp.CiscoConfigParser(os.path.dirname(os.path.realpath(__file__)) \ + "/" + CONF_FILE) -section = cp['SWITCH'] -NEXUS_IP_ADDRESS = section['nexus_ip_address'] -NEXUS_PORT = section['nexus_port'] -NEXUS_SSH_PORT = section['nexus_ssh_port'] +SECTION = CP['SWITCH'] +NEXUS_IP_ADDRESS = SECTION['nexus_ip_address'] +NEXUS_PORT = SECTION['nexus_port'] +NEXUS_SSH_PORT = SECTION['nexus_ssh_port'] -section = cp['DRIVER'] -NEXUS_DRIVER = section['name'] +SECTION = CP['DRIVER'] +NEXUS_DRIVER = SECTION['name'] def main(): + """ + Indicates the value of the Nexus Port + """ print NEXUS_PORT if __name__ == '__main__': diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py b/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py index f0c16274f..3f9235349 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py @@ -22,11 +22,8 @@ Implements a Nexus-OS NETCONF over SSHv2 API Client """ import logging as LOG -import string -import subprocess from quantum.plugins.cisco.common import cisco_constants as const -from quantum.plugins.cisco.common import cisco_exceptions as cexc from quantum.plugins.cisco.nexus import cisco_nexus_snippets as snipp from ncclient import manager @@ -36,60 +33,93 @@ LOG.getLogger(const.LOGGER_COMPONENT_NAME) class CiscoNEXUSDriver(): - + """ + Nexus Driver Main Class + """ def __init__(self): pass def nxos_connect(self, nexus_host, nexus_ssh_port, nexus_user, nexus_password): - m = manager.connect(host=nexus_host, port=nexus_ssh_port, + """ + Makes the SSH connection to the Nexus Switch + """ + man = manager.connect(host=nexus_host, port=nexus_ssh_port, username=nexus_user, password=nexus_password) - return m + return man def enable_vlan(self, mgr, vlanid, vlanname): - confstr = snipp.cmd_vlan_conf_snippet % (vlanid, vlanname) - confstr = snipp.exec_conf_prefix + confstr + snipp.exec_conf_postfix + """ + Creates a VLAN on Nexus Switch given the VLAN ID and Name + """ + confstr = snipp.CMD_VLAN_CONF_SNIPPET % (vlanid, vlanname) + confstr = snipp.EXEC_CONF_PREFIX + confstr + snipp.EXEC_CONF_POSTFIX mgr.edit_config(target='running', config=confstr) def disable_vlan(self, mgr, vlanid): - confstr = snipp.cmd_no_vlan_conf_snippet % vlanid - confstr = snipp.exec_conf_prefix + confstr + snipp.exec_conf_postfix + """ + Delete a VLAN on Nexus Switch given the VLAN ID + """ + confstr = snipp.CMD_NO_VLAN_CONF_SNIPPET % vlanid + confstr = snipp.EXEC_CONF_PREFIX + confstr + snipp.EXEC_CONF_POSTFIX mgr.edit_config(target='running', config=confstr) def enable_port_trunk(self, mgr, interface): - confstr = snipp.cmd_port_trunk % (interface) - confstr = snipp.exec_conf_prefix + confstr + snipp.exec_conf_postfix + """ + Enables trunk mode an interface on Nexus Switch + """ + confstr = snipp.CMD_PORT_TRUNK % (interface) + confstr = snipp.EXEC_CONF_PREFIX + confstr + snipp.EXEC_CONF_POSTFIX LOG.debug("NexusDriver: %s" % confstr) mgr.edit_config(target='running', config=confstr) def disable_switch_port(self, mgr, interface): - confstr = snipp.cmd_no_switchport % (interface) - confstr = snipp.exec_conf_prefix + confstr + snipp.exec_conf_postfix + """ + Disables trunk mode an interface on Nexus Switch + """ + confstr = snipp.CMD_NO_SWITCHPORT % (interface) + confstr = snipp.EXEC_CONF_PREFIX + confstr + snipp.EXEC_CONF_POSTFIX LOG.debug("NexusDriver: %s" % confstr) mgr.edit_config(target='running', config=confstr) def enable_vlan_on_trunk_int(self, mgr, interface, vlanid): - confstr = snipp.cmd_vlan_int_snippet % (interface, vlanid) - confstr = snipp.exec_conf_prefix + confstr + snipp.exec_conf_postfix + """ + Enables trunk mode vlan access an interface on Nexus Switch given + VLANID + """ + confstr = snipp.CMD_VLAN_INT_SNIPPET % (interface, vlanid) + confstr = snipp.EXEC_CONF_PREFIX + confstr + snipp.EXEC_CONF_POSTFIX LOG.debug("NexusDriver: %s" % confstr) mgr.edit_config(target='running', config=confstr) def disable_vlan_on_trunk_int(self, mgr, interface, vlanid): - confstr = snipp.cmd_no_vlan_int_snippet % (interface, vlanid) - confstr = snipp.exec_conf_prefix + confstr + snipp.exec_conf_postfix + """ + Enables trunk mode vlan access an interface on Nexus Switch given + VLANID + """ + confstr = snipp.CMD_NO_VLAN_INT_SNIPPET % (interface, vlanid) + confstr = snipp.EXEC_CONF_PREFIX + confstr + snipp.EXEC_CONF_POSTFIX LOG.debug("NexusDriver: %s" % confstr) 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): + """ + Creates a VLAN and Enable on trunk mode an interface on Nexus Switch + given the VLAN ID and Name and Interface Number + """ with self.nxos_connect(nexus_host, int(nexus_ssh_port), nexus_user, - nexus_password) as m: - self.enable_vlan(m, vlan_id, vlan_name) - self.enable_vlan_on_trunk_int(m, nexus_interface, vlan_id) + nexus_password) as man: + self.enable_vlan(man, vlan_id, vlan_name) + self.enable_vlan_on_trunk_int(man, nexus_interface, vlan_id) def delete_vlan(self, vlan_id, nexus_host, nexus_user, nexus_password, nexus_interface, nexus_ssh_port): + """ + Delete a VLAN and Disables trunk mode an interface on Nexus Switch + given the VLAN ID and Interface Number + """ with self.nxos_connect(nexus_host, int(nexus_ssh_port), nexus_user, - nexus_password) as m: - self.disable_vlan(m, vlan_id) - self.disable_switch_port(m, nexus_interface) + nexus_password) as man: + self.disable_vlan(man, vlan_id) + self.disable_switch_port(man, nexus_interface) diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_plugin.py b/quantum/plugins/cisco/nexus/cisco_nexus_plugin.py index e27269ed6..84085ff3f 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_plugin.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_plugin.py @@ -17,14 +17,15 @@ # @author: Sumit Naiksatam, Cisco Systems, Inc. # @author: Edgar Magana, Cisco Systems, Inc. # +""" +PlugIn for Nexus OS driver +""" import logging as LOG from quantum.common import exceptions as exc from quantum.common import utils 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_exceptions as cexc -from quantum.plugins.cisco.common import cisco_utils as cutil from quantum.plugins.cisco.l2device_plugin_base import L2DevicePluginBase from quantum.plugins.cisco.nexus import cisco_nexus_configuration as conf @@ -33,12 +34,17 @@ LOG.getLogger(const.LOGGER_COMPONENT_NAME) class NexusPlugin(L2DevicePluginBase): + """ + Nexus PLugIn Main Class + """ _networks = {} def __init__(self): + """ + Extracts the configuration parameters from the configuration file + """ self._client = utils.import_object(conf.NEXUS_DRIVER) LOG.debug("Loaded driver %s\n" % conf.NEXUS_DRIVER) - #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) @@ -103,7 +109,6 @@ class NexusPlugin(L2DevicePluginBase): Updates the symbolic name belonging to a particular Virtual Network. """ - #TODO (Edgar) We need to add an update method in the Nexus Driver LOG.debug("NexusPlugin:rename_network() called\n") network = self._get_network(tenant_id, net_id) network[const.NET_NAME] = new_name @@ -160,11 +165,17 @@ class NexusPlugin(L2DevicePluginBase): LOG.debug("NexusPlugin:unplug_interface() called\n") def _get_vlan_id_for_network(self, tenant_id, network_id): + """ + Obtain the VLAN ID given the 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): + """ + Gets the NETWORK ID + """ network = self._networks.get(network_id) if not network: raise exc.NetworkNotFound(net_id=network_id) diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_snippets.py b/quantum/plugins/cisco/nexus/cisco_nexus_snippets.py index a3bc004d2..9c7dab058 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_snippets.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_snippets.py @@ -21,8 +21,6 @@ Nexus-OS XML-based configuration snippets """ import logging as LOG -import string -import subprocess from quantum.plugins.cisco.common import cisco_constants as const @@ -31,21 +29,21 @@ LOG.getLogger(const.LOGGER_COMPONENT_NAME) # The following are standard strings, messages used to communicate with Nexus, -exec_conf_prefix = """ +EXEC_CONF_PREFIX = """ <__XML__MODE__exec_configure> """ -exec_conf_postfix = """ +EXEC_CONF_POSTFIX = """ """ -cmd_vlan_conf_snippet = """ +CMD_VLAN_CONF_SNIPPET = """ <__XML__PARAM_value>%s @@ -64,7 +62,7 @@ cmd_vlan_conf_snippet = """ """ -cmd_no_vlan_conf_snippet = """ +CMD_NO_VLAN_CONF_SNIPPET = """ @@ -74,7 +72,7 @@ cmd_no_vlan_conf_snippet = """ """ -cmd_vlan_int_snippet = """ +CMD_VLAN_INT_SNIPPET = """ %s @@ -96,7 +94,7 @@ cmd_vlan_int_snippet = """ """ -cmd_port_trunk = """ +CMD_PORT_TRUNK = """ %s @@ -113,7 +111,7 @@ cmd_port_trunk = """ """ -cmd_no_switchport = """ +CMD_NO_SWITCHPORT = """ %s @@ -128,7 +126,7 @@ cmd_no_switchport = """ """ -cmd_no_vlan_int_snippet = """ +CMD_NO_VLAN_INT_SNIPPET = """ C: 1: Missing docstring %s @@ -153,7 +151,7 @@ cmd_no_vlan_int_snippet = """ """ -filter_show_vlan_brief_snippet = """ +FILTER_SHOW_VLAN_BRIEF_SNIPPET = """