Fixing pep8 errors

removing excess debug lines
This commit is contained in:
Salvatore Orlando 2011-06-07 18:25:16 +01:00
parent dafac9726b
commit 15a625ba16
17 changed files with 153 additions and 193 deletions

View File

@ -51,11 +51,11 @@ class APIRouterV01(wsgi.Router):
mapper.resource('network', 'networks',
controller=networks.Controller(),
path_prefix=uri_prefix)
mapper.resource('port', 'ports',
mapper.resource('port', 'ports',
controller=ports.Controller(),
parent_resource=dict(member_name='network',
collection_name=\
uri_prefix + 'networks'))
collection_name=uri_prefix +\
'networks'))
mapper.connect("get_resource",
uri_prefix + 'networks/{network_id}/' \

View File

@ -52,7 +52,7 @@ class Fault(webob.exc.HTTPException):
fault_data = {
fault_name: {
'code': code,
'message': self.wrapped_exc.explanation,
'message': self.wrapped_exc.explanation,
'detail': self.wrapped_exc.detail}}
# 'code' is an attribute on the fault tag itself
metadata = {'application/xml': {'attributes': {fault_name: 'code'}}}

View File

@ -78,7 +78,7 @@ class Controller(common.QuantumController):
except exc.HTTPError as e:
return faults.Fault(e)
network = self.network_manager.\
create_network(tenant_id,req_params['network-name'])
create_network(tenant_id, req_params['network-name'])
builder = networks_view.get_view_builder(req)
result = builder.build(network)
return dict(networks=result)

View File

@ -24,24 +24,25 @@ from quantum.common import exceptions as exception
LOG = logging.getLogger('quantum.api.ports')
class Controller(common.QuantumController):
""" Port API controller for Quantum API """
_port_ops_param_list = [{
'param-name': 'port-state',
'default-value': 'DOWN',
'required': False},]
'default-value': 'DOWN',
'required': False},
]
_attachment_ops_param_list = [{
'param-name': 'attachment-id',
'required': True},]
'required': True},
]
_serialization_metadata = {
"application/xml": {
"attributes": {
"port": ["id","state"],
"port": ["id", "state"],
},
},
}
@ -49,14 +50,14 @@ class Controller(common.QuantumController):
def __init__(self, plugin_conf_file=None):
self._resource_name = 'port'
super(Controller, self).__init__()
def index(self, req, tenant_id, network_id):
""" Returns a list of port ids for a given network """
return self._items(req, tenant_id, network_id, is_detail=False)
def _items(self, req, tenant_id, network_id, is_detail):
""" Returns a list of networks. """
try :
try:
ports = self.network_manager.get_all_ports(tenant_id, network_id)
builder = ports_view.get_view_builder(req)
result = [builder.build(port, is_detail)['port']
@ -64,7 +65,7 @@ class Controller(common.QuantumController):
return dict(ports=result)
except exception.NetworkNotFound as e:
return faults.Fault(faults.NetworkNotFound(e))
def show(self, req, tenant_id, network_id, id):
""" Returns port details for given port and network """
try:
@ -77,7 +78,7 @@ class Controller(common.QuantumController):
except exception.NetworkNotFound as e:
return faults.Fault(faults.NetworkNotFound(e))
except exception.PortNotFound as e:
return faults.Fault(faults.PortNotFound(e))
return faults.Fault(faults.PortNotFound(e))
def create(self, req, tenant_id, network_id):
""" Creates a new port for a given network """
@ -87,17 +88,17 @@ class Controller(common.QuantumController):
self._parse_request_params(req, self._port_ops_param_list)
except exc.HTTPError as e:
return faults.Fault(e)
try:
try:
port = self.network_manager.create_port(tenant_id,
network_id,
network_id,
req_params['port-state'])
builder = ports_view.get_view_builder(req)
result = builder.build(port)
return dict(ports=result)
except exception.NetworkNotFound as e:
return faults.Fault(faults.NetworkNotFound(e))
except exception.StateInvalid as e:
return faults.Fault(faults.RequestedStateInvalid(e))
except exception.StateInvalid as e:
return faults.Fault(faults.RequestedStateInvalid(e))
def update(self, req, tenant_id, network_id, id):
""" Updates the state of a port for a given network """
@ -106,9 +107,9 @@ class Controller(common.QuantumController):
req_params = \
self._parse_request_params(req, self._port_ops_param_list)
except exc.HTTPError as e:
return faults.Fault(e)
try:
port = self.network_manager.update_port(tenant_id,network_id, id,
return faults.Fault(e)
try:
port = self.network_manager.update_port(tenant_id, network_id, id,
req_params['port-state'])
builder = ports_view.get_view_builder(req)
result = builder.build(port, True)
@ -117,26 +118,24 @@ class Controller(common.QuantumController):
return faults.Fault(faults.NetworkNotFound(e))
except exception.PortNotFound as e:
return faults.Fault(faults.PortNotFound(e))
except exception.StateInvalid as e:
except exception.StateInvalid as e:
return faults.Fault(faults.RequestedStateInvalid(e))
def delete(self, req, tenant_id, network_id, id):
""" Destroys the port with the given id """
#look for port state in request
try:
self.network_manager.delete_port(tenant_id, network_id, id)
return exc.HTTPAccepted()
#TODO(salvatore-orlando): Handle portInUse error
# TODO(salvatore-orlando): Handle portInUse error
except exception.NetworkNotFound as e:
return faults.Fault(faults.NetworkNotFound(e))
except exception.PortNotFound as e:
return faults.Fault(faults.PortNotFound(e))
return faults.Fault(faults.PortNotFound(e))
except exception.PortInUse as e:
return faults.Fault(faults.PortInUse(e))
def get_resource(self,req,tenant_id, network_id, id):
def get_resource(self, req, tenant_id, network_id, id):
try:
result = self.network_manager.get_interface_details(
tenant_id, network_id, id)
@ -144,12 +143,9 @@ class Controller(common.QuantumController):
except exception.NetworkNotFound as e:
return faults.Fault(faults.NetworkNotFound(e))
except exception.PortNotFound as e:
return faults.Fault(faults.PortNotFound(e))
return faults.Fault(faults.PortNotFound(e))
#TODO - Complete implementation of these APIs
def attach_resource(self,req,tenant_id, network_id, id):
content_type = req.best_match_content_type()
print "Content type:%s" %content_type
def attach_resource(self, req, tenant_id, network_id, id):
try:
req_params = \
self._parse_request_params(req,
@ -158,26 +154,24 @@ class Controller(common.QuantumController):
return faults.Fault(e)
try:
self.network_manager.plug_interface(tenant_id,
network_id,id,
network_id, id,
req_params['attachment-id'])
return exc.HTTPAccepted()
except exception.NetworkNotFound as e:
return faults.Fault(faults.NetworkNotFound(e))
except exception.PortNotFound as e:
return faults.Fault(faults.PortNotFound(e))
return faults.Fault(faults.PortNotFound(e))
except exception.PortInUse as e:
return faults.Fault(faults.PortInUse(e))
except exception.AlreadyAttached as e:
return faults.Fault(faults.AlreadyAttached(e))
#TODO - Complete implementation of these APIs
def detach_resource(self,req,tenant_id, network_id, id):
def detach_resource(self, req, tenant_id, network_id, id):
try:
self.network_manager.unplug_interface(tenant_id,
network_id,id)
network_id, id)
return exc.HTTPAccepted()
except exception.NetworkNotFound as e:
return faults.Fault(faults.NetworkNotFound(e))
except exception.PortNotFound as e:
return faults.Fault(faults.PortNotFound(e))
return faults.Fault(faults.PortNotFound(e))

View File

@ -13,4 +13,3 @@
# 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: Somik Behera, Nicira Networks, Inc.

View File

@ -33,17 +33,16 @@ class ViewBuilder(object):
def build(self, network_data, is_detail=False):
"""Generic method used to generate a network entity."""
print "NETWORK-DATA:%s" %network_data
if is_detail:
network = self._build_detail(network_data)
else:
network = self._build_simple(network_data)
return network
def _build_simple(self, network_data):
"""Return a simple model of a server."""
return dict(network=dict(id=network_data['net-id']))
def _build_detail(self, network_data):
"""Return a simple model of a server."""
return dict(network=dict(id=network_data['net-id'],

View File

@ -31,17 +31,16 @@ class ViewBuilder(object):
def build(self, port_data, is_detail=False):
"""Generic method used to generate a port entity."""
print "PORT-DATA:%s" %port_data
if is_detail:
port = self._build_detail(port_data)
else:
port = self._build_simple(port_data)
return port
def _build_simple(self, port_data):
"""Return a simple model of a server."""
return dict(port=dict(id=port_data['port-id']))
def _build_detail(self, port_data):
"""Return a simple model of a server."""
return dict(port=dict(id=port_data['port-id'],

View File

@ -36,7 +36,7 @@ def usage():
print "detail_iface <tenant-id> <net-id> <port-id>"
print "list_iface <tenant-id> <net-id>\n"
if len(sys.argv) < 2 or len(sys.argv) > 6:
if len(sys.argv) < 2 or len(sys.argv) > 6:
usage()
exit(1)
@ -89,13 +89,13 @@ elif sys.argv[1] == "plug_iface" and len(sys.argv) == 6:
elif sys.argv[1] == "unplug_iface" and len(sys.argv) == 5:
manager.unplug_interface(sys.argv[2], sys.argv[3], sys.argv[4])
print "UnPlugged remote interface " \
"from Virtual Port:%s Virtual Network:%s" % (sys.argv[4],
"from Virtual Port:%s Virtual Network:%s" % (sys.argv[4],
sys.argv[3])
elif sys.argv[1] == "detail_iface" and len(sys.argv) == 5:
remote_iface = manager.get_interface_details(sys.argv[2],
remote_iface = manager.get_interface_details(sys.argv[2],
sys.argv[3], sys.argv[4])
print "Remote interface on Virtual Port:%s " \
"Virtual Network:%s is %s" % (sys.argv[4],
"Virtual Network:%s is %s" % (sys.argv[4],
sys.argv[3], remote_iface)
elif sys.argv[1] == "list_iface" and len(sys.argv) == 4:
iface_list = manager.get_all_attached_interfaces(sys.argv[2], sys.argv[3])
@ -107,4 +107,3 @@ elif sys.argv[1] == "all" and len(sys.argv) == 2:
else:
print "invalid arguments: %s" % str(sys.argv)
usage()

View File

@ -209,7 +209,7 @@ def find_config_file(options, args):
fix_path(os.path.join('~', '.quantum')),
fix_path('~'),
os.path.join(FLAGS.state_path, 'etc'),
os.path.join(FLAGS.state_path, 'etc','quantum'),
os.path.join(FLAGS.state_path, 'etc', 'quantum'),
'/etc/quantum/',
'/etc']
for cfg_dir in config_file_dirs:
@ -244,12 +244,10 @@ def load_paste_config(app_name, options, args):
problem loading the configuration file.
"""
conf_file = find_config_file(options, args)
print "Conf_file:%s" %conf_file
if not conf_file:
raise RuntimeError("Unable to locate any configuration file. "
"Cannot load application %s" % app_name)
try:
print "App_name:%s" %app_name
conf = deploy.appconfig("config:%s" % conf_file, name=app_name)
return conf_file, conf
except Exception, e:

View File

@ -25,7 +25,7 @@ import logging
class QuantumException(Exception):
"""Base Quantum Exception
Taken from nova.exception.NovaException
To correctly use this class, inherit from it and define
a 'message' property. That message will get printf'd
@ -45,6 +45,7 @@ class QuantumException(Exception):
def __str__(self):
return self._error_string
class ProcessExecutionError(IOError):
def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None,
description=None):
@ -84,11 +85,11 @@ class NetworkNotFound(NotFound):
class PortNotFound(NotFound):
message = _("Port %(port_id)s could not be found " \
"on network %(net_id)s")
class StateInvalid(QuantumException):
message = _("Unsupported port state: %(port_state)s")
class NetworkInUse(QuantumException):
message = _("Unable to complete operation on network %(net_id)s. " \
@ -100,11 +101,13 @@ class PortInUse(QuantumException):
"for network %(net_id)s. The attachment '%(att_id)s" \
"is plugged into the logical port.")
class AlreadyAttached(QuantumException):
message = _("Unable to plug the attachment %(att_id)s into port " \
"%(port_id)s for network %(net_id)s. The attachment is " \
"already plugged into port %(att_port_id)s")
class Duplicate(Error):
pass

View File

@ -23,7 +23,7 @@ Global flags should be defined here, the rest are defined where they're used.
"""
import getopt
import os
import os
import string
import sys
@ -249,4 +249,3 @@ def DECLARE(name, module_string, flag_values=FLAGS):
DEFINE_string('state_path', os.path.join(os.path.dirname(__file__), '../../'),
"Top-level directory for maintaining quantum's state")

View File

@ -37,6 +37,7 @@ from exceptions import ProcessExecutionError
TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
FLAGS = flags.FLAGS
def int_from_bool_as_string(subject):
"""
Interpret a string as a boolean and return either 1 or 0.
@ -188,6 +189,7 @@ def isotime(at=None):
def parse_isotime(timestr):
return datetime.datetime.strptime(timestr, TIME_FORMAT)
def getPluginFromConfig(file="config.ini"):
Config = ConfigParser.ConfigParser()
Config.read(os.path.join(FLAGS.state_path, file))

View File

@ -40,6 +40,7 @@ from quantum.common import exceptions as exception
LOG = logging.getLogger('quantum.common.wsgi')
class WritableLogger(object):
"""A thin wrapper that responds to `write` and logs."""
@ -126,7 +127,7 @@ class Request(webob.Request):
"""
parts = self.path.rsplit('.', 1)
LOG.debug("Request parts:%s",parts)
LOG.debug("Request parts:%s", parts)
if len(parts) > 1:
format = parts[1]
if format in ['json', 'xml']:
@ -134,7 +135,6 @@ class Request(webob.Request):
ctypes = ['application/json', 'application/xml']
bm = self.accept.best_match(ctypes)
LOG.debug("BM:%s",bm)
return bm or 'application/json'
def get_content_type(self):
@ -336,10 +336,6 @@ class Controller(object):
arg_dict = req.environ['wsgiorg.routing_args'][1]
action = arg_dict['action']
method = getattr(self, action)
LOG.debug("ARG_DICT:%s",arg_dict)
LOG.debug("Action:%s",action)
LOG.debug("Method:%s",method)
LOG.debug("%s %s" % (req.method, req.url))
del arg_dict['controller']
del arg_dict['action']
if 'format' in arg_dict:
@ -349,8 +345,6 @@ class Controller(object):
if type(result) is dict:
content_type = req.best_match_content_type()
LOG.debug("Content type:%s",content_type)
LOG.debug("Result:%s",result)
default_xmlns = self.get_default_xmlns(req)
body = self._serialize(result, content_type, default_xmlns)
@ -497,9 +491,7 @@ class Serializer(object):
xmlns = metadata.get('xmlns', None)
if xmlns:
result.setAttribute('xmlns', xmlns)
LOG.debug("DATA:%s",data)
if type(data) is list:
LOG.debug("TYPE IS LIST")
collections = metadata.get('list_collections', {})
if nodename in collections:
metadata = collections[nodename]
@ -518,7 +510,6 @@ class Serializer(object):
node = self._to_xml_node(doc, metadata, singular, item)
result.appendChild(node)
elif type(data) is dict:
LOG.debug("TYPE IS DICT")
collections = metadata.get('dict_collections', {})
if nodename in collections:
metadata = collections[nodename]
@ -538,8 +529,6 @@ class Serializer(object):
result.appendChild(node)
else:
# Type is atom
LOG.debug("TYPE IS ATOM:%s",data)
node = doc.createTextNode(str(data))
result.appendChild(node)
return result

View File

@ -18,8 +18,9 @@
"""
Quantum's Manager class is responsible for parsing a config file and instantiating the correct
plugin that concretely implement quantum_plugin_base class
Quantum's Manager class is responsible for parsing a config file
and instantiating the correct plugin that concretely implement
quantum_plugin_base class
The caller should make sure that QuantumManager is a singleton.
"""
@ -34,7 +35,7 @@ CONFIG_FILE = "quantum/plugins.ini"
class QuantumManager(object):
def __init__(self,config=CONFIG_FILE):
def __init__(self, config=CONFIG_FILE):
self.configuration_file = CONFIG_FILE
plugin_location = utils.getPluginFromConfig(CONFIG_FILE)
print "PLUGIN LOCATION:%s" % plugin_location

View File

@ -17,33 +17,32 @@
from quantum.common import exceptions as exc
class QuantumEchoPlugin(object):
"""
QuantumEchoPlugin is a demo plugin that doesn't
do anything but demonstrated the concept of a
concrete Quantum Plugin. Any call to this plugin
will result in just a "print" to std. out with
will result in just a "print" to std. out with
the name of the method that was called.
"""
def get_all_networks(self, tenant_id):
"""
Returns a dictionary containing all
<network_uuid, network_name> for
the specified tenant.
the specified tenant.
"""
print("get_all_networks() called\n")
def create_network(self, tenant_id, net_name):
"""
Creates a new Virtual Network, and assigns it
a symbolic name.
"""
print("create_network() called\n")
def delete_network(self, tenant_id, net_id):
"""
Deletes the network with the specified network identifier
@ -51,38 +50,33 @@ class QuantumEchoPlugin(object):
"""
print("delete_network() called\n")
def get_network_details(self, tenant_id, net_id):
"""
Deletes the Virtual Network belonging to a the
spec
"""
print("get_network_details() called\n")
def rename_network(self, tenant_id, net_id, new_name):
"""
Updates the symbolic name belonging to a particular
Virtual Network.
"""
print("rename_network() called\n")
def get_all_ports(self, tenant_id, net_id):
"""
Retrieves all port identifiers belonging to the
specified Virtual Network.
"""
print("get_all_ports() called\n")
def create_port(self, tenant_id, net_id):
"""
Creates a port on the specified Virtual Network.
"""
print("create_port() called\n")
def delete_port(self, tenant_id, net_id, port_id):
"""
Deletes a port on a specified Virtual Network,
@ -91,40 +85,35 @@ class QuantumEchoPlugin(object):
is deleted.
"""
print("delete_port() called\n")
def get_port_details(self, tenant_id, net_id, port_id):
"""
This method allows the user to retrieve a remote interface
that is attached to this particular port.
"""
print("get_port_details() called\n")
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id):
"""
Attaches a remote interface to the specified port on the
specified Virtual Network.
"""
print("plug_interface() called\n")
def unplug_interface(self, tenant_id, net_id, port_id):
"""
Detaches a remote interface from the specified port on the
specified Virtual Network.
"""
print("unplug_interface() called\n")
def get_interface_details(self, tenant_id, net_id, port_id):
"""
Retrieves the remote interface that is attached at this
particular port.
"""
print("get_interface_details() called\n")
def get_all_attached_interfaces(self, tenant_id, net_id):
"""
Retrieves all remote interfaces that are attached to
@ -132,6 +121,7 @@ class QuantumEchoPlugin(object):
"""
print("get_all_attached_interfaces() called\n")
class DummyDataPlugin(object):
"""
@ -139,18 +129,17 @@ class DummyDataPlugin(object):
hard-coded data structures to aid in quantum
client/cli development
"""
def get_all_networks(self, tenant_id):
"""
Returns a dictionary containing all
<network_uuid, network_name> for
the specified tenant.
the specified tenant.
"""
nets = {"001": "lNet1", "002": "lNet2" , "003": "lNet3"}
nets = {"001": "lNet1", "002": "lNet2", "003": "lNet3"}
print("get_all_networks() called\n")
return nets
def create_network(self, tenant_id, net_name):
"""
Creates a new Virtual Network, and assigns it
@ -159,8 +148,7 @@ class DummyDataPlugin(object):
print("create_network() called\n")
# return network_id of the created network
return 101
def delete_network(self, tenant_id, net_id):
"""
Deletes the network with the specified network identifier
@ -168,25 +156,23 @@ class DummyDataPlugin(object):
"""
print("delete_network() called\n")
def get_network_details(self, tenant_id, net_id):
"""
retrieved a list of all the remote vifs that
are attached to the network
"""
print("get_network_details() called\n")
vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0", "/tenant1/networks/10/121/vif1.1"]
vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0",
"/tenant1/networks/10/121/vif1.1"]
return vifs_on_net
def rename_network(self, tenant_id, net_id, new_name):
"""
Updates the symbolic name belonging to a particular
Virtual Network.
"""
print("rename_network() called\n")
def get_all_ports(self, tenant_id, net_id):
"""
Retrieves all port identifiers belonging to the
@ -195,8 +181,7 @@ class DummyDataPlugin(object):
print("get_all_ports() called\n")
port_ids_on_net = ["2", "3", "4"]
return port_ids_on_net
def create_port(self, tenant_id, net_id):
"""
Creates a port on the specified Virtual Network.
@ -204,8 +189,7 @@ class DummyDataPlugin(object):
print("create_port() called\n")
#return the port id
return 201
def delete_port(self, tenant_id, net_id, port_id):
"""
Deletes a port on a specified Virtual Network,
@ -214,8 +198,7 @@ class DummyDataPlugin(object):
is deleted.
"""
print("delete_port() called\n")
def get_port_details(self, tenant_id, net_id, port_id):
"""
This method allows the user to retrieve a remote interface
@ -224,24 +207,21 @@ class DummyDataPlugin(object):
print("get_port_details() called\n")
#returns the remote interface UUID
return "/tenant1/networks/net_id/portid/vif2.1"
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id):
"""
Attaches a remote interface to the specified port on the
specified Virtual Network.
"""
print("plug_interface() called\n")
def unplug_interface(self, tenant_id, net_id, port_id):
"""
Detaches a remote interface from the specified port on the
specified Virtual Network.
"""
print("unplug_interface() called\n")
def get_interface_details(self, tenant_id, net_id, port_id):
"""
Retrieves the remote interface that is attached at this
@ -250,8 +230,7 @@ class DummyDataPlugin(object):
print("get_interface_details() called\n")
#returns the remote interface UUID
return "/tenant1/networks/net_id/portid/vif2.0"
def get_all_attached_interfaces(self, tenant_id, net_id):
"""
Retrieves all remote interfaces that are attached to
@ -259,10 +238,11 @@ class DummyDataPlugin(object):
"""
print("get_all_attached_interfaces() called\n")
# returns a list of all attached remote interfaces
vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0", "/tenant1/networks/10/121/vif1.1"]
vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0",
"/tenant1/networks/10/121/vif1.1"]
return vifs_on_net
class FakePlugin(object):
"""
FakePlugin is a demo plugin that provides
@ -272,72 +252,70 @@ class FakePlugin(object):
#static data for networks and ports
_port_dict_1 = {
1 : {'port-id': 1,
'port-state': 'DOWN',
'attachment': None},
2 : {'port-id': 2,
'port-state':'UP',
'attachment': None}
1: {'port-id': 1,
'port-state': 'DOWN',
'attachment': None},
2: {'port-id': 2,
'port-state': 'UP',
'attachment': None}
}
_port_dict_2 = {
1 : {'port-id': 1,
'port-state': 'UP',
'attachment': 'SomeFormOfVIFID'},
2 : {'port-id': 2,
'port-state':'DOWN',
'attachment': None}
}
_networks={'001':
1: {'port-id': 1,
'port-state': 'UP',
'attachment': 'SomeFormOfVIFID'},
2: {'port-id': 2,
'port-state': 'DOWN',
'attachment': None}
}
_networks = {'001':
{
'net-id':'001',
'net-name':'pippotest',
'net-id': '001',
'net-name': 'pippotest',
'net-ports': _port_dict_1
},
'002':
{
'net-id':'002',
'net-name':'cicciotest',
'net-ports': _port_dict_2
'net-id': '002',
'net-name': 'cicciotest',
'net-ports': _port_dict_2
}}
def __init__(self):
FakePlugin._net_counter=len(FakePlugin._networks)
FakePlugin._net_counter = len(FakePlugin._networks)
def _get_network(self, tenant_id, network_id):
network = FakePlugin._networks.get(network_id)
if not network:
raise exc.NetworkNotFound(net_id=network_id)
return network
def _get_port(self, tenant_id, network_id, port_id):
net = self._get_network(tenant_id, network_id)
port = net['net-ports'].get(int(port_id))
if not port:
raise exc.PortNotFound(net_id=network_id, port_id=port_id)
return port
def _validate_port_state(self, port_state):
if port_state.upper() not in ('UP','DOWN'):
if port_state.upper() not in ('UP', 'DOWN'):
raise exc.StateInvalid(port_state=port_state)
return True
def _validate_attachment(self, tenant_id, network_id, port_id,
remote_interface_id):
network = self._get_network(tenant_id, network_id)
for port in network['net-ports'].values():
if port['attachment'] == remote_interface_id:
raise exc.AlreadyAttached(net_id = network_id,
port_id = port_id,
att_id = port['attachment'],
att_port_id = port['port-id'])
raise exc.AlreadyAttached(net_id=network_id,
port_id=port_id,
att_id=port['attachment'],
att_port_id=port['port-id'])
def get_all_networks(self, tenant_id):
"""
Returns a dictionary containing all
<network_uuid, network_name> for
the specified tenant.
the specified tenant.
"""
print("get_all_networks() called\n")
return FakePlugin._networks.values()
@ -357,16 +335,16 @@ class FakePlugin(object):
"""
print("create_network() called\n")
FakePlugin._net_counter += 1
new_net_id=("0" * (3 - len(str(FakePlugin._net_counter)))) + \
new_net_id = ("0" * (3 - len(str(FakePlugin._net_counter)))) + \
str(FakePlugin._net_counter)
print new_net_id
new_net_dict={'net-id':new_net_id,
'net-name':net_name,
'net-ports': {}}
FakePlugin._networks[new_net_id]=new_net_dict
new_net_dict = {'net-id': new_net_id,
'net-name': net_name,
'net-ports': {}}
FakePlugin._networks[new_net_id] = new_net_dict
# return network_id of the created network
return new_net_dict
def delete_network(self, tenant_id, net_id):
"""
Deletes the network with the specified network identifier
@ -384,7 +362,7 @@ class FakePlugin(object):
return net
# Network not found
raise exc.NetworkNotFound(net_id=net_id)
def rename_network(self, tenant_id, net_id, new_name):
"""
Updates the symbolic name belonging to a particular
@ -392,7 +370,7 @@ class FakePlugin(object):
"""
print("rename_network() called\n")
net = self._get_network(tenant_id, net_id)
net['net-name']=new_name
net['net-name'] = new_name
return net
def get_all_ports(self, tenant_id, net_id):
@ -412,7 +390,7 @@ class FakePlugin(object):
"""
print("get_port_details() called\n")
return self._get_port(tenant_id, net_id, port_id)
def create_port(self, tenant_id, net_id, port_state=None):
"""
Creates a port on the specified Virtual Network.
@ -420,15 +398,15 @@ class FakePlugin(object):
print("create_port() called\n")
net = self._get_network(tenant_id, net_id)
# check port state
# TODO(salvatore-orlando): Validate port state in API?
# TODO(salvatore-orlando): Validate port state in API?
self._validate_port_state(port_state)
ports = net['net-ports']
new_port_id = max(ports.keys())+1
new_port_dict = {'port-id':new_port_id,
new_port_id = max(ports.keys()) + 1
new_port_dict = {'port-id': new_port_id,
'port-state': port_state,
'attachment': None}
ports[new_port_id] = new_port_dict
return new_port_dict
return new_port_dict
def update_port(self, tenant_id, net_id, port_id, port_state):
"""
@ -438,8 +416,8 @@ class FakePlugin(object):
port = self._get_port(tenant_id, net_id, port_id)
self._validate_port_state(port_state)
port['port-state'] = port_state
return port
return port
def delete_port(self, tenant_id, net_id, port_id):
"""
Deletes a port on a specified Virtual Network,
@ -451,11 +429,11 @@ class FakePlugin(object):
net = self._get_network(tenant_id, net_id)
port = self._get_port(tenant_id, net_id, port_id)
if port['attachment']:
raise exc.PortInUse(net_id=net_id,port_id=port_id,
raise exc.PortInUse(net_id=net_id, port_id=port_id,
att_id=port['attachment'])
try:
net['net-ports'].pop(int(port_id))
except KeyError:
except KeyError:
raise exc.PortNotFound(net_id=net_id, port_id=port_id)
def get_interface_details(self, tenant_id, net_id, port_id):
@ -466,7 +444,7 @@ class FakePlugin(object):
print("get_interface_details() called\n")
port = self._get_port(tenant_id, net_id, port_id)
return port['attachment']
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id):
"""
Attaches a remote interface to the specified port on the
@ -478,10 +456,10 @@ class FakePlugin(object):
remote_interface_id)
port = self._get_port(tenant_id, net_id, port_id)
if port['attachment']:
raise exc.PortInUse(net_id=net_id,port_id=port_id,
raise exc.PortInUse(net_id=net_id, port_id=port_id,
att_id=port['attachment'])
port['attachment'] = remote_interface_id
def unplug_interface(self, tenant_id, net_id, port_id):
"""
Detaches a remote interface from the specified port on the
@ -492,8 +470,8 @@ class FakePlugin(object):
# TODO(salvatore-orlando):
# Should unplug on port without attachment raise an Error?
port['attachment'] = None
#TODO - neeed to update methods from this point onwards
# TODO - neeed to update methods from this point onwards
def get_all_attached_interfaces(self, tenant_id, net_id):
"""
Retrieves all remote interfaces that are attached to
@ -501,6 +479,6 @@ class FakePlugin(object):
"""
print("get_all_attached_interfaces() called\n")
# returns a list of all attached remote interfaces
vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0", "/tenant1/networks/10/121/vif1.1"]
vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0",
"/tenant1/networks/10/121/vif1.1"]
return vifs_on_net

View File

@ -13,4 +13,4 @@
# 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: Somik Behera, Nicira Networks, Inc.
# @author: Somik Behera, Nicira Networks, Inc.

View File

@ -88,7 +88,7 @@ class QuantumApiService(WsgiService):
return service
def serve_wsgi(cls, conf=None, options = None, args=None):
def serve_wsgi(cls, conf=None, options=None, args=None):
try:
service = cls.create(conf, options, args)
except Exception:
@ -99,7 +99,7 @@ def serve_wsgi(cls, conf=None, options = None, args=None):
return service
def _run_wsgi(app_name, paste_conf, paste_config_file):
LOG.info(_('Using paste.deploy config at: %s'), paste_config_file)
app = config.load_paste_app(paste_config_file, app_name)