# @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
function calls to equivalent authenticated REST calls to a set of redundant
class RemoteRestError(exceptions.QuantumException):
+
def __init__(self, message):
if message is None:
message = "None"
class ServerPool(object):
+
def __init__(self, servers, ssl, auth, quantum_id, timeout=10,
base_uri='/quantum/v1.0', name='QuantumRestProxy'):
self.base_uri = base_uri
def server_failure(self, resp):
"""Define failure codes as required.
+
Note: We assume 301-303 is a failure, and try the next server in
the server pool.
"""
def action_success(self, resp):
"""Defining success codes as required.
+
Note: We assume any valid 2xx as being successful response.
"""
return resp[0] in SUCCESS_CODES
LOG.debug(_("QuantumRestProxyV2: initialization done"))
def create_network(self, context, network):
- """Create a network, which represents an L2 network segment which
- can have a set of subnets and ports associated with it.
+ """Create a network.
+
+ 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 network: dictionary describing the network
:raises: RemoteRestError
"""
-
LOG.debug(_("QuantumRestProxyV2: create_network() called"))
self._warn_on_state_status(network['network'])
def update_network(self, context, net_id, network):
"""Updates the properties of a particular Virtual Network.
+
:param context: quantum api request context
:param net_id: uuid of the network to update
:param network: dictionary describing the updates
:raises: exceptions.NetworkNotFound
:raises: RemoteRestError
"""
-
LOG.debug(_("QuantumRestProxyV2.update_network() called"))
self._warn_on_state_status(network['network'])
def update_port(self, context, port_id, port):
"""Update values of a port.
+
:param context: quantum api request context
:param id: UUID representing the port to update.
:param port: dictionary with keys indicating fields to update.
def delete_port(self, context, port_id, l3_port_check=True):
"""Delete a port.
+
:param context: quantum api request context
:param id: UUID representing the port to delete.
:raises: exceptions.NetworkNotFound
:raises: RemoteRestError
"""
-
LOG.debug(_("QuantumRestProxyV2: delete_port() called"))
# if needed, check to see if this is a port owned by
def _plug_interface(self, context, tenant_id, net_id, port_id,
remote_interface_id):
- """Attaches a remote interface to the specified port on the
- specified Virtual Network.
+ """Plug remote interface to the network.
+
+ Attaches a remote interface to the specified port on the specified
+ Virtual Network.
:returns: None
raise
def _unplug_interface(self, context, tenant_id, net_id, port_id):
- """Detaches a remote interface from the specified port on the
- network controller
+ """Detach interface from the network controller.
+
+ Detaches a remote interface from the specified port on the network
+ controller.
:returns: None
raise
def _send_all_data(self):
- """Pushes all data to network ctrl (networks/ports, ports/attachments)
- to give the controller an option to re-sync it's persistent store
+ """Pushes all data to network ctrl (networks/ports, ports/attachments).
+
+ This gives the controller an option to re-sync it's persistent store
with quantum's current view of that data.
"""
admin_context = qcontext.get_admin_context()
#
# @author: Mandeep Dhami, Big Switch Networks, Inc.
-"""
-Test server mocking a REST based network ctrl. Used for QuantumRestProxy tests
+"""Test server mocking a REST based network ctrl.
+
+Used for QuantumRestProxy tests
"""
import json
class TestNetworkCtrl(object):
+
def __init__(self, host='', port=8000,
default_status='404 Not Found',
default_response='404 Not Found',
def match(self, prior, method_regexp, uri_regexp, handler, data=None,
multi=True):
- """Adds to the list of exptected inputs. The incomming request is
- matched in the order of priority. For same priority, match the
- oldest match request first.
+ """Add to the list of exptected inputs.
+
+ 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 method_regexp: regexp to match method (e.g. 'PUT|POST')
# TODO(shiv) need support for security groups
-"""
-Implentation of Brocade Quantum Plugin.
-"""
+"""Implentation of Brocade Quantum Plugin."""
from oslo.config import cfg
TAP_PREFIX_LEN = 3
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
one class as the target of rpc messages, override this method.
- '''
+ """
return q_rpc.PluginRpcDispatcher([self,
agents_db.AgentExtRpcCallback()])
class AgentNotifierApi(proxy.RpcProxy,
sg_rpc.SecurityGroupAgentRpcApiMixin):
- '''Agent side of the linux bridge rpc API.
+ """Agent side of the linux bridge rpc API.
API version history:
1.0 - Initial version.
- '''
+ """
BASE_RPC_API_VERSION = '1.0'
"""
def __init__(self):
- """Initialize Brocade Plugin, specify switch address
- and db configuration.
+ """Initialize Brocade Plugin.
+
+ Specify switch address and db configuration.
"""
self.supported_extension_aliases = ["binding", "security-group",
self.l3_agent_notifier = l3_rpc_agent_api.L3AgentNotify
def create_network(self, context, network):
- """This call to create network translates to creation of
- port-profile on the physical switch.
+ """Create network.
+
+ This call to create network translates to creation of port-profile on
+ the physical switch.
"""
with context.session.begin(subtransactions=True):
return net
def delete_network(self, context, net_id):
- """This call to delete the network translates to removing
- the port-profile on the physical switch.
+ """Delete network.
+
+ This call to delete the network translates to removing the
+ port-profile on the physical switch.
"""
with context.session.begin(subtransactions=True):
:type interface_mac: string
:returns: MAC address in the format xxxx.xxxx.xxxx
:rtype: string
-
"""
mac = interface_mac.replace(":", "")
# Varma Bhupatiraju (vbhupati@#brocade.com)
-"""
-Brocade specific database schema/model.
-"""
+"""Brocade specific database schema/model."""
import sqlalchemy as sa
class BrocadeNetwork(model_base.BASEV2, models_v2.HasId):
"""Schema for brocade network."""
+
vlan = sa.Column(sa.String(10))
# 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
-Quantum network life-cycle management
+Quantum network life-cycle management.
"""
Fake: Handles life-cycle management of Quantum network,
leverages AMPP on NOS
(for use by unit tests, avoids touching any hardware)
-
"""
def __init__(self):
# Shiv Haris (sharis@brocade.com)
-"""
-NOS NETCONF XML Configuration Command Templates
+"""NOS NETCONF XML Configuration Command Templates.
+
Interface Configuration Commands
"""
+
# Create VLAN (vlan_id)
CREATE_VLAN_INTERFACE = """
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
# 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 quantum.openstack.common import log as logging
Returns `True` if it finds the key acceptable,
and `False` if not. This default callback for NOS always returns 'True'
(i.e. trusts all hosts for now).
-
"""
-
return True
"""NOS NETCONF interface driver for Quantum network.
Handles life-cycle management of Quantum network (leverages AMPP on NOS)
-
"""
def __init__(self):
# Shiv Haris (sharis@brocade.com)
-"""
-Brocade NOS Driver CLI
-"""
+"""Brocade NOS Driver CLI."""
+
import argparse
from quantum.openstack.common import log as logging
# Shiv Haris (sharis@brocade.com)
-"""
-Brocade NOS Driver Test
-"""
+"""Brocade NOS Driver Test."""
import sys
from quantum.plugins.brocade.nos import nosdriver as nos
# 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
# uses a bitmap to do this
def __init__(self, ctxt):
- """initialize the vlan as a set."""
+ """Initialize the vlan as a set."""
self.vlans = set(int(net['vlan'])
for net in brocade_db.get_networks(ctxt)
if net['vlan']
)
def get_next_vlan(self, vlan_id=None):
- """try to get a specific vlan if requested
- or get the next vlan.
- """
+ """Try to get a specific vlan if requested or get the next vlan."""
min_vlan_search = vlan_id or MIN_VLAN
max_vlan_search = (vlan_id and vlan_id + 1) or MAX_VLAN
return vlan
def release_vlan(self, vlan_id):
- """return the vlan to the pool."""
+ """Return the vlan to the pool."""
if vlan_id in self.vlans:
self.vlans.remove(vlan_id)