Docstrings formatted according to pep257

Bug #1020184

quantum/plugins/bigswitch/*
quantum/plugins/brocade/*

Change-Id: I9bf4381738319551a5993d4b279a5cec3425b7ef
This commit is contained in:
Sergey Skripnick 2013-04-29 16:46:51 +03:00
parent d9c4623870
commit 1e166f3efd
10 changed files with 66 additions and 60 deletions

View File

@ -18,7 +18,7 @@
# @author: Sumit Naiksatam, sumitnaiksatam@gmail.com, Big Switch Networks, Inc. # @author: Sumit Naiksatam, sumitnaiksatam@gmail.com, Big Switch Networks, Inc.
""" """
Quantum REST Proxy Plug-in for Big Switch and FloodLight Controllers Quantum REST Proxy Plug-in for Big Switch and FloodLight Controllers.
QuantumRestProxy provides a generic quantum plugin that translates all plugin QuantumRestProxy provides a generic quantum plugin that translates all plugin
function calls to equivalent authenticated REST calls to a set of redundant function calls to equivalent authenticated REST calls to a set of redundant
@ -119,6 +119,7 @@ METADATA_SERVER_IP = '169.254.169.254'
class RemoteRestError(exceptions.QuantumException): class RemoteRestError(exceptions.QuantumException):
def __init__(self, message): def __init__(self, message):
if message is None: if message is None:
message = "None" message = "None"
@ -208,6 +209,7 @@ class ServerProxy(object):
class ServerPool(object): class ServerPool(object):
def __init__(self, servers, ssl, auth, quantum_id, timeout=10, def __init__(self, servers, ssl, auth, quantum_id, timeout=10,
base_uri='/quantum/v1.0', name='QuantumRestProxy'): base_uri='/quantum/v1.0', name='QuantumRestProxy'):
self.base_uri = base_uri self.base_uri = base_uri
@ -226,6 +228,7 @@ class ServerPool(object):
def server_failure(self, resp): def server_failure(self, resp):
"""Define failure codes as required. """Define failure codes as required.
Note: We assume 301-303 is a failure, and try the next server in Note: We assume 301-303 is a failure, and try the next server in
the server pool. the server pool.
""" """
@ -233,6 +236,7 @@ class ServerPool(object):
def action_success(self, resp): def action_success(self, resp):
"""Defining success codes as required. """Defining success codes as required.
Note: We assume any valid 2xx as being successful response. Note: We assume any valid 2xx as being successful response.
""" """
return resp[0] in SUCCESS_CODES return resp[0] in SUCCESS_CODES
@ -335,8 +339,11 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2,
LOG.debug(_("QuantumRestProxyV2: initialization done")) LOG.debug(_("QuantumRestProxyV2: initialization done"))
def create_network(self, context, network): def create_network(self, context, network):
"""Create a network, which represents an L2 network segment which """Create a network.
can have a set of subnets and ports associated with it.
Network represents an L2 network segment which can have a set of
subnets and ports associated with it.
:param context: quantum api request context :param context: quantum api request context
:param network: dictionary describing the network :param network: dictionary describing the network
@ -355,7 +362,6 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2,
:raises: RemoteRestError :raises: RemoteRestError
""" """
LOG.debug(_("QuantumRestProxyV2: create_network() called")) LOG.debug(_("QuantumRestProxyV2: create_network() called"))
self._warn_on_state_status(network['network']) self._warn_on_state_status(network['network'])
@ -393,6 +399,7 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2,
def update_network(self, context, net_id, network): def update_network(self, context, net_id, network):
"""Updates the properties of a particular Virtual Network. """Updates the properties of a particular Virtual Network.
:param context: quantum api request context :param context: quantum api request context
:param net_id: uuid of the network to update :param net_id: uuid of the network to update
:param network: dictionary describing the updates :param network: dictionary describing the updates
@ -413,7 +420,6 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2,
:raises: exceptions.NetworkNotFound :raises: exceptions.NetworkNotFound
:raises: RemoteRestError :raises: RemoteRestError
""" """
LOG.debug(_("QuantumRestProxyV2.update_network() called")) LOG.debug(_("QuantumRestProxyV2.update_network() called"))
self._warn_on_state_status(network['network']) self._warn_on_state_status(network['network'])
@ -571,6 +577,7 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2,
def update_port(self, context, port_id, port): def update_port(self, context, port_id, port):
"""Update values of a port. """Update values of a port.
:param context: quantum api request context :param context: quantum api request context
:param id: UUID representing the port to update. :param id: UUID representing the port to update.
:param port: dictionary with keys indicating fields to update. :param port: dictionary with keys indicating fields to update.
@ -640,6 +647,7 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2,
def delete_port(self, context, port_id, l3_port_check=True): def delete_port(self, context, port_id, l3_port_check=True):
"""Delete a port. """Delete a port.
:param context: quantum api request context :param context: quantum api request context
:param id: UUID representing the port to delete. :param id: UUID representing the port to delete.
@ -648,7 +656,6 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2,
:raises: exceptions.NetworkNotFound :raises: exceptions.NetworkNotFound
:raises: RemoteRestError :raises: RemoteRestError
""" """
LOG.debug(_("QuantumRestProxyV2: delete_port() called")) LOG.debug(_("QuantumRestProxyV2: delete_port() called"))
# if needed, check to see if this is a port owned by # if needed, check to see if this is a port owned by
@ -684,8 +691,10 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2,
def _plug_interface(self, context, tenant_id, net_id, port_id, def _plug_interface(self, context, tenant_id, net_id, port_id,
remote_interface_id): remote_interface_id):
"""Attaches a remote interface to the specified port on the """Plug remote interface to the network.
specified Virtual Network.
Attaches a remote interface to the specified port on the specified
Virtual Network.
:returns: None :returns: None
@ -716,8 +725,10 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2,
raise raise
def _unplug_interface(self, context, tenant_id, net_id, port_id): def _unplug_interface(self, context, tenant_id, net_id, port_id):
"""Detaches a remote interface from the specified port on the """Detach interface from the network controller.
network controller
Detaches a remote interface from the specified port on the network
controller.
:returns: None :returns: None
@ -1042,8 +1053,9 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2,
raise raise
def _send_all_data(self): def _send_all_data(self):
"""Pushes all data to network ctrl (networks/ports, ports/attachments) """Pushes all data to network ctrl (networks/ports, ports/attachments).
to give the controller an option to re-sync it's persistent store
This gives the controller an option to re-sync it's persistent store
with quantum's current view of that data. with quantum's current view of that data.
""" """
admin_context = qcontext.get_admin_context() admin_context = qcontext.get_admin_context()

View File

@ -18,8 +18,9 @@
# #
# @author: Mandeep Dhami, Big Switch Networks, Inc. # @author: Mandeep Dhami, Big Switch Networks, Inc.
""" """Test server mocking a REST based network ctrl.
Test server mocking a REST based network ctrl. Used for QuantumRestProxy tests
Used for QuantumRestProxy tests
""" """
import json import json
@ -29,6 +30,7 @@ from wsgiref.simple_server import make_server
class TestNetworkCtrl(object): class TestNetworkCtrl(object):
def __init__(self, host='', port=8000, def __init__(self, host='', port=8000,
default_status='404 Not Found', default_status='404 Not Found',
default_response='404 Not Found', default_response='404 Not Found',
@ -44,9 +46,10 @@ class TestNetworkCtrl(object):
def match(self, prior, method_regexp, uri_regexp, handler, data=None, def match(self, prior, method_regexp, uri_regexp, handler, data=None,
multi=True): multi=True):
"""Adds to the list of exptected inputs. The incomming request is """Add to the list of exptected inputs.
matched in the order of priority. For same priority, match the
oldest match request first. The incoming request is matched in the order of priority. For same
priority, match the oldest match request first.
:param prior: intgere priority of this match (e.g. 100) :param prior: intgere priority of this match (e.g. 100)
:param method_regexp: regexp to match method (e.g. 'PUT|POST') :param method_regexp: regexp to match method (e.g. 'PUT|POST')

View File

@ -23,9 +23,7 @@
# TODO(shiv) need support for security groups # TODO(shiv) need support for security groups
""" """Implentation of Brocade Quantum Plugin."""
Implentation of Brocade Quantum Plugin.
"""
from oslo.config import cfg from oslo.config import cfg
@ -86,11 +84,11 @@ class BridgeRpcCallbacks(dhcp_rpc_base.DhcpRpcCallbackMixin,
TAP_PREFIX_LEN = 3 TAP_PREFIX_LEN = 3
def create_rpc_dispatcher(self): def create_rpc_dispatcher(self):
'''Get the rpc dispatcher for this manager. """Get the rpc dispatcher for this manager.
If a manager would like to set an rpc API version, or support more than If a manager would like to set an rpc API version, or support more than
one class as the target of rpc messages, override this method. one class as the target of rpc messages, override this method.
''' """
return q_rpc.PluginRpcDispatcher([self, return q_rpc.PluginRpcDispatcher([self,
agents_db.AgentExtRpcCallback()]) agents_db.AgentExtRpcCallback()])
@ -161,12 +159,12 @@ class BridgeRpcCallbacks(dhcp_rpc_base.DhcpRpcCallbackMixin,
class AgentNotifierApi(proxy.RpcProxy, class AgentNotifierApi(proxy.RpcProxy,
sg_rpc.SecurityGroupAgentRpcApiMixin): sg_rpc.SecurityGroupAgentRpcApiMixin):
'''Agent side of the linux bridge rpc API. """Agent side of the linux bridge rpc API.
API version history: API version history:
1.0 - Initial version. 1.0 - Initial version.
''' """
BASE_RPC_API_VERSION = '1.0' BASE_RPC_API_VERSION = '1.0'
@ -207,8 +205,9 @@ class BrocadePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
""" """
def __init__(self): def __init__(self):
"""Initialize Brocade Plugin, specify switch address """Initialize Brocade Plugin.
and db configuration.
Specify switch address and db configuration.
""" """
self.supported_extension_aliases = ["binding", "security-group", self.supported_extension_aliases = ["binding", "security-group",
@ -255,8 +254,10 @@ class BrocadePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
self.l3_agent_notifier = l3_rpc_agent_api.L3AgentNotify self.l3_agent_notifier = l3_rpc_agent_api.L3AgentNotify
def create_network(self, context, network): def create_network(self, context, network):
"""This call to create network translates to creation of """Create network.
port-profile on the physical switch.
This call to create network translates to creation of port-profile on
the physical switch.
""" """
with context.session.begin(subtransactions=True): with context.session.begin(subtransactions=True):
@ -284,8 +285,10 @@ class BrocadePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
return net return net
def delete_network(self, context, net_id): def delete_network(self, context, net_id):
"""This call to delete the network translates to removing """Delete network.
the port-profile on the physical switch.
This call to delete the network translates to removing the
port-profile on the physical switch.
""" """
with context.session.begin(subtransactions=True): with context.session.begin(subtransactions=True):
@ -460,7 +463,6 @@ class BrocadePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
:type interface_mac: string :type interface_mac: string
:returns: MAC address in the format xxxx.xxxx.xxxx :returns: MAC address in the format xxxx.xxxx.xxxx
:rtype: string :rtype: string
""" """
mac = interface_mac.replace(":", "") mac = interface_mac.replace(":", "")

View File

@ -20,9 +20,7 @@
# Varma Bhupatiraju (vbhupati@#brocade.com) # Varma Bhupatiraju (vbhupati@#brocade.com)
""" """Brocade specific database schema/model."""
Brocade specific database schema/model.
"""
import sqlalchemy as sa import sqlalchemy as sa
@ -32,6 +30,7 @@ from quantum.db import models_v2
class BrocadeNetwork(model_base.BASEV2, models_v2.HasId): class BrocadeNetwork(model_base.BASEV2, models_v2.HasId):
"""Schema for brocade network.""" """Schema for brocade network."""
vlan = sa.Column(sa.String(10)) vlan = sa.Column(sa.String(10))

View File

@ -20,10 +20,10 @@
# Shiv Haris (sharis@brocade.com) # Shiv Haris (sharis@brocade.com)
""" """FAKE DRIVER, for unit tests purposes.
FAKE DRIVER, for unit tests purposes
Brocade NOS Driver implements NETCONF over SSHv2 for Brocade NOS Driver implements NETCONF over SSHv2 for
Quantum network life-cycle management Quantum network life-cycle management.
""" """
@ -33,7 +33,6 @@ class NOSdriver():
Fake: Handles life-cycle management of Quantum network, Fake: Handles life-cycle management of Quantum network,
leverages AMPP on NOS leverages AMPP on NOS
(for use by unit tests, avoids touching any hardware) (for use by unit tests, avoids touching any hardware)
""" """
def __init__(self): def __init__(self):

View File

@ -20,10 +20,11 @@
# Shiv Haris (sharis@brocade.com) # Shiv Haris (sharis@brocade.com)
""" """NOS NETCONF XML Configuration Command Templates.
NOS NETCONF XML Configuration Command Templates
Interface Configuration Commands Interface Configuration Commands
""" """
# Create VLAN (vlan_id) # Create VLAN (vlan_id)
CREATE_VLAN_INTERFACE = """ CREATE_VLAN_INTERFACE = """
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"> <config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">

View File

@ -20,10 +20,10 @@
# Shiv Haris (sharis@brocade.com) # Shiv Haris (sharis@brocade.com)
"""Brocade NOS Driver implements NETCONF over SSHv2 for
Quantum network life-cycle management.
""" """
Brocade NOS Driver implements NETCONF over SSHv2 for
Quantum network life-cycle management
"""
from ncclient import manager from ncclient import manager
from quantum.openstack.common import log as logging from quantum.openstack.common import log as logging
@ -40,9 +40,7 @@ def nos_unknown_host_cb(host, fingerprint):
Returns `True` if it finds the key acceptable, Returns `True` if it finds the key acceptable,
and `False` if not. This default callback for NOS always returns 'True' and `False` if not. This default callback for NOS always returns 'True'
(i.e. trusts all hosts for now). (i.e. trusts all hosts for now).
""" """
return True return True
@ -50,7 +48,6 @@ class NOSdriver():
"""NOS NETCONF interface driver for Quantum network. """NOS NETCONF interface driver for Quantum network.
Handles life-cycle management of Quantum network (leverages AMPP on NOS) Handles life-cycle management of Quantum network (leverages AMPP on NOS)
""" """
def __init__(self): def __init__(self):

View File

@ -20,9 +20,8 @@
# Shiv Haris (sharis@brocade.com) # Shiv Haris (sharis@brocade.com)
""" """Brocade NOS Driver CLI."""
Brocade NOS Driver CLI
"""
import argparse import argparse
from quantum.openstack.common import log as logging from quantum.openstack.common import log as logging

View File

@ -18,9 +18,7 @@
# Shiv Haris (sharis@brocade.com) # Shiv Haris (sharis@brocade.com)
""" """Brocade NOS Driver Test."""
Brocade NOS Driver Test
"""
import sys import sys
from quantum.plugins.brocade.nos import nosdriver as nos from quantum.plugins.brocade.nos import nosdriver as nos

View File

@ -20,9 +20,7 @@
# Varma Bhupatiraju (vbhupati@#brocade.com) # Varma Bhupatiraju (vbhupati@#brocade.com)
""" """A Vlan Bitmap class to handle allocation/de-allocation of vlan ids."""
A Vlan Bitmap class to handle allocation/de-allocation of vlan ids.
"""
from quantum.plugins.brocade.db import models as brocade_db from quantum.plugins.brocade.db import models as brocade_db
@ -37,16 +35,14 @@ class VlanBitmap(object):
# uses a bitmap to do this # uses a bitmap to do this
def __init__(self, ctxt): def __init__(self, ctxt):
"""initialize the vlan as a set.""" """Initialize the vlan as a set."""
self.vlans = set(int(net['vlan']) self.vlans = set(int(net['vlan'])
for net in brocade_db.get_networks(ctxt) for net in brocade_db.get_networks(ctxt)
if net['vlan'] if net['vlan']
) )
def get_next_vlan(self, vlan_id=None): def get_next_vlan(self, vlan_id=None):
"""try to get a specific vlan if requested """Try to get a specific vlan if requested or get the next vlan."""
or get the next vlan.
"""
min_vlan_search = vlan_id or MIN_VLAN min_vlan_search = vlan_id or MIN_VLAN
max_vlan_search = (vlan_id and vlan_id + 1) or MAX_VLAN max_vlan_search = (vlan_id and vlan_id + 1) or MAX_VLAN
@ -56,6 +52,6 @@ class VlanBitmap(object):
return vlan return vlan
def release_vlan(self, vlan_id): def release_vlan(self, vlan_id):
"""return the vlan to the pool.""" """Return the vlan to the pool."""
if vlan_id in self.vlans: if vlan_id in self.vlans:
self.vlans.remove(vlan_id) self.vlans.remove(vlan_id)