pep8 fixes (1st batch)

This commit is contained in:
Salvatore Orlando
2011-05-31 18:15:00 +01:00
parent 9f1c248826
commit 75b67e63e2
10 changed files with 118 additions and 105 deletions

View File

@@ -48,31 +48,30 @@ class APIRouterV01(wsgi.Router):
def _setup_routes(self, mapper): def _setup_routes(self, mapper):
uri_prefix = '/tenants/{tenant_id}/' uri_prefix = '/tenants/{tenant_id}/'
mapper.resource('network', mapper.resource('network', 'networks',
'networks',
controller=networks.Controller(), controller=networks.Controller(),
path_prefix=uri_prefix) path_prefix=uri_prefix)
mapper.resource("port", "ports", controller=ports.Controller(), mapper.resource('port', 'ports',
controller=ports.Controller(),
parent_resource=dict(member_name='network', parent_resource=dict(member_name='network',
collection_name= uri_prefix + 'networks')) collection_name=\
uri_prefix + 'networks'))
mapper.connect("get_resource", mapper.connect("get_resource",
uri_prefix + 'networks/{network_id}/ports/{id}/attachment{.format}', uri_prefix + 'networks/{network_id}/' \
'ports/{id}/attachment{.format}',
controller=ports.Controller(), controller=ports.Controller(),
action="get_resource", action="get_resource",
conditions=dict(method=['GET'])) conditions=dict(method=['GET']))
mapper.connect("attach_resource", mapper.connect("attach_resource",
uri_prefix + 'networks/{network_id}/ports/{id}/attachment{.format}', uri_prefix + 'networks/{network_id}/' \
'ports/{id}/attachment{.format}',
controller=ports.Controller(), controller=ports.Controller(),
action="attach_resource", action="attach_resource",
conditions=dict(method=['PUT'])) conditions=dict(method=['PUT']))
mapper.connect("detach_resource", mapper.connect("detach_resource",
uri_prefix + 'networks/{network_id}/ports/{id}/attachment{.format}', uri_prefix + 'networks/{network_id}/' \
'ports/{id}/attachment{.format}',
controller=ports.Controller(), controller=ports.Controller(),
action="detach_resource", action="detach_resource",
conditions=dict(method=['DELETE'])) conditions=dict(method=['DELETE']))
print "AFTER MAPPING"
print mapper
for route in mapper.matchlist:
print "Found route:%s %s" %(route.defaults,route.conditions)

View File

@@ -15,17 +15,18 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import logging import logging
from webob import exc from webob import exc
from quantum import manager from quantum import manager
from quantum.common import wsgi from quantum.common import wsgi
XML_NS_V01 = 'http://netstack.org/quantum/api/v0.1' XML_NS_V01 = 'http://netstack.org/quantum/api/v0.1'
XML_NS_V10 = 'http://netstack.org/quantum/api/v1.0' XML_NS_V10 = 'http://netstack.org/quantum/api/v1.0'
LOG = logging.getLogger('quantum.api.api_common') LOG = logging.getLogger('quantum.api.api_common')
class QuantumController(wsgi.Controller): class QuantumController(wsgi.Controller):
""" Base controller class for Quantum API """ """ Base controller class for Quantum API """
@@ -40,7 +41,8 @@ class QuantumController(wsgi.Controller):
param_value = None param_value = None
# 1- parse request body # 1- parse request body
if req.body: if req.body:
des_body = self._deserialize(req.body, req.best_match_content_type()) des_body = self._deserialize(req.body,
req.best_match_content_type())
data = des_body and des_body.get(self._resource_name, None) data = des_body and des_body.get(self._resource_name, None)
param_value = data and data.get(param_name, None) param_value = data and data.get(param_name, None)
if not param_value: if not param_value:
@@ -52,17 +54,17 @@ class QuantumController(wsgi.Controller):
try: try:
param_value = req.str_GET[param_name] param_value = req.str_GET[param_name]
except KeyError: except KeyError:
#param not found #param not found
pass pass
if not param_value and param['required']: if not param_value and param['required']:
msg = ("Failed to parse request. " + msg = ("Failed to parse request. " +
"Parameter: %(param_name)s not specified" % locals()) "Parameter: %(param_name)s " +
"not specified" % locals())
for line in msg.split('\n'): for line in msg.split('\n'):
LOG.error(line) LOG.error(line)
raise exc.HTTPBadRequest(msg) raise exc.HTTPBadRequest(msg)
results[param_name]=param_value or param.get('default-value') results[param_name] = param_value or param.get('default-value')
return results return results
def _setup_network_manager(self):
self.network_manager=manager.QuantumManager().get_manager()
def _setup_network_manager(self):
self.network_manager = manager.QuantumManager().get_manager()

View File

@@ -22,6 +22,7 @@ import webob.exc
from quantum.api import api_common as common from quantum.api import api_common as common
from quantum.common import wsgi from quantum.common import wsgi
class Fault(webob.exc.HTTPException): class Fault(webob.exc.HTTPException):
"""Error codes for API faults""" """Error codes for API faults"""
@@ -29,7 +30,7 @@ class Fault(webob.exc.HTTPException):
400: "malformedRequest", 400: "malformedRequest",
401: "unauthorized", 401: "unauthorized",
420: "networkNotFound", 420: "networkNotFound",
421: "networkInUse", 421: "networkInUse",
430: "portNotFound", 430: "portNotFound",
431: "requestedStateInvalid", 431: "requestedStateInvalid",
432: "portInUse", 432: "portInUse",
@@ -61,20 +62,21 @@ class Fault(webob.exc.HTTPException):
self.wrapped_exc.body = serializer.serialize(fault_data, content_type) self.wrapped_exc.body = serializer.serialize(fault_data, content_type)
self.wrapped_exc.content_type = content_type self.wrapped_exc.content_type = content_type
return self.wrapped_exc return self.wrapped_exc
class NetworkNotFound(webob.exc.HTTPClientError): class NetworkNotFound(webob.exc.HTTPClientError):
""" """
subclass of :class:`~HTTPClientError` subclass of :class:`~HTTPClientError`
This indicates that the server did not find the network specified This indicates that the server did not find the network specified
in the HTTP request in the HTTP request
code: 420, title: Network not Found code: 420, title: Network not Found
""" """
code = 420 code = 420
title = 'Network not Found' title = 'Network not Found'
explanation = ('Unable to find a network with the specified identifier.') explanation = ('Unable to find a network with the specified identifier.')
class NetworkInUse(webob.exc.HTTPClientError): class NetworkInUse(webob.exc.HTTPClientError):
""" """
@@ -82,7 +84,7 @@ class NetworkInUse(webob.exc.HTTPClientError):
This indicates that the server could not delete the network as there is This indicates that the server could not delete the network as there is
at least an attachment plugged into its ports at least an attachment plugged into its ports
code: 421, title: Network In Use code: 421, title: Network In Use
""" """
code = 421 code = 421
@@ -96,27 +98,27 @@ class PortNotFound(webob.exc.HTTPClientError):
This indicates that the server did not find the port specified This indicates that the server did not find the port specified
in the HTTP request for a given network in the HTTP request for a given network
code: 430, title: Port not Found code: 430, title: Port not Found
""" """
code = 430 code = 430
title = 'Port not Found' title = 'Port not Found'
explanation = ('Unable to find a port with the specified identifier.') explanation = ('Unable to find a port with the specified identifier.')
class RequestedStateInvalid(webob.exc.HTTPClientError): class RequestedStateInvalid(webob.exc.HTTPClientError):
""" """
subclass of :class:`~HTTPClientError` subclass of :class:`~HTTPClientError`
This indicates that the server could not update the port state to This indicates that the server could not update the port state to
to the request value to the request value
code: 431, title: Requested State Invalid code: 431, title: Requested State Invalid
""" """
code = 431 code = 431
title = 'Requested State Invalid' title = 'Requested State Invalid'
explanation = ('Unable to update port state with specified value.') explanation = ('Unable to update port state with specified value.')
class PortInUse(webob.exc.HTTPClientError): class PortInUse(webob.exc.HTTPClientError):
""" """
@@ -124,20 +126,21 @@ class PortInUse(webob.exc.HTTPClientError):
This indicates that the server could not remove o port or attach This indicates that the server could not remove o port or attach
a resource to it because there is an attachment plugged into the port a resource to it because there is an attachment plugged into the port
code: 432, title: PortInUse code: 432, title: PortInUse
""" """
code = 432 code = 432
title = 'Port in Use' title = 'Port in Use'
explanation = ('A resource is currently attached to the logical port') explanation = ('A resource is currently attached to the logical port')
class AlreadyAttached(webob.exc.HTTPClientError): class AlreadyAttached(webob.exc.HTTPClientError):
""" """
subclass of :class:`~HTTPClientError` subclass of :class:`~HTTPClientError`
This indicates that the server refused an attempt to re-attach a resource This indicates that the server refused an attempt to re-attach a resource
already attached to the network already attached to the network
code: 440, title: AlreadyAttached code: 440, title: AlreadyAttached
""" """
code = 440 code = 440

View File

@@ -29,13 +29,13 @@ class Controller(common.QuantumController):
""" Network API controller for Quantum API """ """ Network API controller for Quantum API """
_network_ops_param_list = [{ _network_ops_param_list = [{
'param-name': 'network-name', 'param-name': 'network-name',
'required': True},] 'required': True}, ]
_serialization_metadata = { _serialization_metadata = {
"application/xml": { "application/xml": {
"attributes": { "attributes": {
"network": ["id","name"], "network": ["id", "name"],
}, },
}, },
} }
@@ -56,12 +56,12 @@ class Controller(common.QuantumController):
result = [builder.build(network, is_detail)['network'] result = [builder.build(network, is_detail)['network']
for network in networks] for network in networks]
return dict(networks=result) return dict(networks=result)
def show(self, req, tenant_id, id): def show(self, req, tenant_id, id):
""" Returns network details for the given network id """ """ Returns network details for the given network id """
try: try:
network = self.network_manager.get_network_details( network = self.network_manager.get_network_details(
tenant_id,id) tenant_id, id)
builder = networks_view.get_view_builder(req) builder = networks_view.get_view_builder(req)
#build response with details #build response with details
result = builder.build(network, True) result = builder.build(network, True)
@@ -77,7 +77,8 @@ class Controller(common.QuantumController):
self._parse_request_params(req, self._network_ops_param_list) self._parse_request_params(req, self._network_ops_param_list)
except exc.HTTPError as e: except exc.HTTPError as e:
return faults.Fault(e) return faults.Fault(e)
network = self.network_manager.create_network(tenant_id, req_params['network-name']) network = self.network_manager.\
create_network(tenant_id,req_params['network-name'])
builder = networks_view.get_view_builder(req) builder = networks_view.get_view_builder(req)
result = builder.build(network) result = builder.build(network)
return dict(networks=result) return dict(networks=result)
@@ -89,15 +90,15 @@ class Controller(common.QuantumController):
self._parse_request_params(req, self._network_ops_param_list) self._parse_request_params(req, self._network_ops_param_list)
except exc.HTTPError as e: except exc.HTTPError as e:
return faults.Fault(e) return faults.Fault(e)
try: try:
network = self.network_manager.rename_network(tenant_id, network = self.network_manager.rename_network(tenant_id,
id,req_params['network-name']) id, req_params['network-name'])
builder = networks_view.get_view_builder(req) builder = networks_view.get_view_builder(req)
result = builder.build(network, True) result = builder.build(network, True)
return dict(networks=result) return dict(networks=result)
except exception.NetworkNotFound as e: except exception.NetworkNotFound as e:
return faults.Fault(faults.NetworkNotFound(e)) return faults.Fault(faults.NetworkNotFound(e))
def delete(self, req, tenant_id, id): def delete(self, req, tenant_id, id):
""" Destroys the network with the given id """ """ Destroys the network with the given id """
@@ -105,6 +106,6 @@ class Controller(common.QuantumController):
self.network_manager.delete_network(tenant_id, id) self.network_manager.delete_network(tenant_id, id)
return exc.HTTPAccepted() return exc.HTTPAccepted()
except exception.NetworkNotFound as e: except exception.NetworkNotFound as e:
return faults.Fault(faults.NetworkNotFound(e)) return faults.Fault(faults.NetworkNotFound(e))
except exception.NetworkInUse as e: except exception.NetworkInUse as e:
return faults.Fault(faults.NetworkInUse(e)) return faults.Fault(faults.NetworkInUse(e))

View File

@@ -23,6 +23,7 @@ from quantum.api.views import versions as versions_view
LOG = logging.getLogger('quantum.api.versions') LOG = logging.getLogger('quantum.api.versions')
class Versions(wsgi.Application): class Versions(wsgi.Application):
@webob.dec.wsgify(RequestClass=wsgi.Request) @webob.dec.wsgify(RequestClass=wsgi.Request)
@@ -42,7 +43,6 @@ class Versions(wsgi.Application):
builder = versions_view.get_view_builder(req) builder = versions_view.get_view_builder(req)
versions = [builder.build(version) for version in version_objs] versions = [builder.build(version) for version in version_objs]
response = dict(versions=versions) response = dict(versions=versions)
LOG.debug("response:%s",response)
metadata = { metadata = {
"application/xml": { "application/xml": {
"attributes": { "attributes": {
@@ -51,12 +51,13 @@ class Versions(wsgi.Application):
} }
} }
} }
content_type = req.best_match_content_type() content_type = req.best_match_content_type()
body = wsgi.Serializer(metadata=metadata).serialize(response, content_type) body = wsgi.Serializer(metadata=metadata). \
serialize(response, content_type)
response = webob.Response() response = webob.Response()
response.content_type = content_type response.content_type = content_type
response.body = body response.body = body
return response return response

View File

@@ -20,37 +20,37 @@ import sys
from manager import QuantumManager from manager import QuantumManager
def usage(): def usage():
print "\nUsage:" print "\nUsage:"
print "list_nets <tenant-id>" print "list_nets <tenant-id>"
print "create_net <tenant-id> <net-name>" print "create_net <tenant-id> <net-name>"
print "delete_net <tenant-id> <net-id>" print "delete_net <tenant-id> <net-id>"
print "detail_net <tenant-id> <net-id>" print "detail_net <tenant-id> <net-id>"
print "rename_net <tenant-id> <net-id> <new name>" print "rename_net <tenant-id> <net-id> <new name>"
print "list_ports <tenant-id> <net-id>" print "list_ports <tenant-id> <net-id>"
print "create_port <tenant-id> <net-id>" print "create_port <tenant-id> <net-id>"
print "delete_port <tenant-id> <net-id> <port-id>" print "delete_port <tenant-id> <net-id> <port-id>"
print "detail_port <tenant-id> <net-id> <port-id>" print "detail_port <tenant-id> <net-id> <port-id>"
print "plug_iface <tenant-id> <net-id> <port-id> <iface-id>" print "plug_iface <tenant-id> <net-id> <port-id> <iface-id>"
print "unplug_iface <tenant-id> <net-id> <port-id>" print "unplug_iface <tenant-id> <net-id> <port-id>"
print "detail_iface <tenant-id> <net-id> <port-id>" print "detail_iface <tenant-id> <net-id> <port-id>"
print "list_iface <tenant-id> <net-id>\n" 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() usage()
exit(1) exit(1)
quantum = QuantumManager() quantum = QuantumManager()
manager = quantum.get_manager() manager = quantum.get_manager()
if sys.argv[1] == "list_nets" and len(sys.argv) == 3: if sys.argv[1] == "list_nets" and len(sys.argv) == 3:
network_on_tenant = manager.get_all_networks(sys.argv[2]) network_on_tenant = manager.get_all_networks(sys.argv[2])
print "Virtual Networks on Tenant:%s\n" % sys.argv[2] print "Virtual Networks on Tenant:%s\n" % sys.argv[2]
for k, v in network_on_tenant.iteritems(): for k, v in network_on_tenant.iteritems():
print"\tNetwork ID:%s \n\tNetwork Name:%s \n" % (k, v) print"\tNetwork ID:%s \n\tNetwork Name:%s \n" % (k, v)
elif sys.argv[1] == "create_net" and len(sys.argv) == 4: elif sys.argv[1] == "create_net" and len(sys.argv) == 4:
new_net_id = manager.create_network(sys.argv[2], sys.argv[3]) new_net_id = manager.create_network(sys.argv[2], sys.argv[3])
print "Created a new Virtual Network with ID:%s\n" % new_net_id print "Created a new Virtual Network with ID:%s\n" % new_net_id
elif sys.argv[1] == "delete_net" and len(sys.argv) == 4: elif sys.argv[1] == "delete_net" and len(sys.argv) == 4:
manager.delete_network(sys.argv[2], sys.argv[3]) manager.delete_network(sys.argv[2], sys.argv[3])
print "Deleted Virtual Network with ID:%s" % sys.argv[3] print "Deleted Virtual Network with ID:%s" % sys.argv[3]
@@ -58,7 +58,7 @@ elif sys.argv[1] == "detail_net" and len(sys.argv) == 4:
vif_list = manager.get_network_details(sys.argv[2], sys.argv[3]) vif_list = manager.get_network_details(sys.argv[2], sys.argv[3])
print "Remote Interfaces on Virtual Network:%s\n" % sys.argv[3] print "Remote Interfaces on Virtual Network:%s\n" % sys.argv[3]
for iface in vif_list: for iface in vif_list:
print "\tRemote interface :%s" % iface print "\tRemote interface :%s" % iface
elif sys.argv[1] == "rename_net" and len(sys.argv) == 5: elif sys.argv[1] == "rename_net" and len(sys.argv) == 5:
manager.rename_network(sys.argv[2], sys.argv[3], sys.argv[4]) manager.rename_network(sys.argv[2], sys.argv[3], sys.argv[4])
print "Renamed Virtual Network with ID:%s" % sys.argv[3] print "Renamed Virtual Network with ID:%s" % sys.argv[3]
@@ -66,33 +66,45 @@ elif sys.argv[1] == "list_ports" and len(sys.argv) == 4:
ports = manager.get_all_ports(sys.argv[2], sys.argv[3]) ports = manager.get_all_ports(sys.argv[2], sys.argv[3])
print " Virtual Ports on Virtual Network:%s\n" % sys.argv[3] print " Virtual Ports on Virtual Network:%s\n" % sys.argv[3]
for port in ports: for port in ports:
print "\tVirtual Port:%s" % port print "\tVirtual Port:%s" % port
elif sys.argv[1] == "create_port" and len(sys.argv) == 4: elif sys.argv[1] == "create_port" and len(sys.argv) == 4:
new_port = manager.create_port(sys.argv[2], sys.argv[3]) new_port = manager.create_port(sys.argv[2], sys.argv[3])
print "Created Virtual Port:%s on Virtual Network:%s" % (new_port, sys.argv[3]) print "Created Virtual Port:%s " \
"on Virtual Network:%s" % (new_port, sys.argv[3])
elif sys.argv[1] == "delete_port" and len(sys.argv) == 5: elif sys.argv[1] == "delete_port" and len(sys.argv) == 5:
manager.delete_port(sys.argv[2], sys.argv[3], sys.argv[4]) manager.delete_port(sys.argv[2], sys.argv[3], sys.argv[4])
print "Deleted Virtual Port:%s on Virtual Network:%s" % (sys.argv[3], sys.argv[4]) print "Deleted Virtual Port:%s " \
"on Virtual Network:%s" % (sys.argv[3], sys.argv[4])
elif sys.argv[1] == "detail_port" and len(sys.argv) == 5: elif sys.argv[1] == "detail_port" and len(sys.argv) == 5:
port_detail = manager.get_port_details(sys.argv[2], sys.argv[3], sys.argv[4]) port_detail = manager.get_port_details(sys.argv[2],
print "Virtual Port:%s on Virtual Network:%s contains remote interface:%s" % (sys.argv[3], sys.argv[4], port_detail) sys.argv[3], sys.argv[4])
print "Virtual Port:%s on Virtual Network:%s " \
"contains remote interface:%s" % (sys.argv[3],
sys.argv[4],
port_detail)
elif sys.argv[1] == "plug_iface" and len(sys.argv) == 6: elif sys.argv[1] == "plug_iface" and len(sys.argv) == 6:
manager.plug_interface(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]) manager.plug_interface(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])
print "Plugged remote interface:%s into Virtual Network:%s" % (sys.argv[5], sys.argv[3]) print "Plugged remote interface:%s " \
"into Virtual Network:%s" % (sys.argv[5], sys.argv[3])
elif sys.argv[1] == "unplug_iface" and len(sys.argv) == 5: elif sys.argv[1] == "unplug_iface" and len(sys.argv) == 5:
manager.unplug_interface(sys.argv[2], sys.argv[3], sys.argv[4]) 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], sys.argv[3]) print "UnPlugged remote interface " \
"from Virtual Port:%s Virtual Network:%s" % (sys.argv[4],
sys.argv[3])
elif sys.argv[1] == "detail_iface" and len(sys.argv) == 5: elif sys.argv[1] == "detail_iface" and len(sys.argv) == 5:
remote_iface = manager.get_interface_details(sys.argv[2], sys.argv[3], sys.argv[4]) remote_iface = manager.get_interface_details(sys.argv[2],
print "Remote interface on Virtual Port:%s Virtual Network:%s is %s" % (sys.argv[4], sys.argv[3], remote_iface) sys.argv[3], sys.argv[4])
print "Remote interface on Virtual Port:%s " \
"Virtual Network:%s is %s" % (sys.argv[4],
sys.argv[3], remote_iface)
elif sys.argv[1] == "list_iface" and len(sys.argv) == 4: elif sys.argv[1] == "list_iface" and len(sys.argv) == 4:
iface_list = manager.get_all_attached_interfaces(sys.argv[2], sys.argv[3]) iface_list = manager.get_all_attached_interfaces(sys.argv[2], sys.argv[3])
print "Remote Interfaces on Virtual Network:%s\n" % sys.argv[3] print "Remote Interfaces on Virtual Network:%s\n" % sys.argv[3]
for iface in iface_list: for iface in iface_list:
print "\tRemote interface :%s" % iface print "\tRemote interface :%s" % iface
elif sys.argv[1] == "all" and len(sys.argv) == 2: elif sys.argv[1] == "all" and len(sys.argv) == 2:
print "Not Implemented" print "Not Implemented"
else: else:
print "invalid arguments: %s" % str(sys.argv) print "invalid arguments: %s" % str(sys.argv)
usage() usage()

View File

@@ -25,29 +25,30 @@ The caller should make sure that QuantumManager is a singleton.
""" """
import gettext import gettext
gettext.install('quantum', unicode=1) gettext.install('quantum', unicode=1)
from common import utils from common import utils
from quantum_plugin_base import QuantumPluginBase from quantum_plugin_base import QuantumPluginBase
CONFIG_FILE = "quantum/plugins.ini" CONFIG_FILE = "quantum/plugins.ini"
class QuantumManager(object): class QuantumManager(object):
def __init__(self,config=CONFIG_FILE): def __init__(self,config=CONFIG_FILE):
self.configuration_file = CONFIG_FILE self.configuration_file = CONFIG_FILE
plugin_location = utils.getPluginFromConfig(CONFIG_FILE) plugin_location = utils.getPluginFromConfig(CONFIG_FILE)
print "PLUGIN LOCATION:%s" %plugin_location print "PLUGIN LOCATION:%s" % plugin_location
plugin_klass = utils.import_class(plugin_location) plugin_klass = utils.import_class(plugin_location)
if not issubclass(plugin_klass, QuantumPluginBase): if not issubclass(plugin_klass, QuantumPluginBase):
raise Exception("Configured Quantum plug-in didn't pass compatibility test") raise Exception("Configured Quantum plug-in " \
"didn't pass compatibility test")
else: else:
print("Successfully imported Quantum plug-in. All compatibility tests passed\n") print("Successfully imported Quantum plug-in." \
"All compatibility tests passed\n")
self.plugin = plugin_klass() self.plugin = plugin_klass()
def get_manager(self):
return self.plugin
def get_manager(self):
return self.plugin
# TODO(somik): rmove the main class # TODO(somik): rmove the main class
@@ -61,4 +62,3 @@ def main():
# Standard boilerplate to call the main() function. # Standard boilerplate to call the main() function.
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@@ -88,11 +88,11 @@ class QuantumPluginBase(object):
@abstractmethod @abstractmethod
def update_port(self, tenant_id, net_id, port_id, port_state): def update_port(self, tenant_id, net_id, port_id, port_state):
""" """
Updates the state of a specific port on the Updates the state of a specific port on the
specified Virtual Network specified Virtual Network
""" """
pass pass
@abstractmethod @abstractmethod
def delete_port(self, tenant_id, net_id, port_id): def delete_port(self, tenant_id, net_id, port_id):
""" """
@@ -142,13 +142,13 @@ class QuantumPluginBase(object):
a particular Virtual Network. a particular Virtual Network.
""" """
pass pass
@classmethod @classmethod
def __subclasshook__(cls, klass): def __subclasshook__(cls, klass):
""" """
The __subclasshook__ method is a class method The __subclasshook__ method is a class method
that will be called everytime a class is tested that will be called everytime a class is tested
using issubclass(klass, Plugin). using issubclass(klass, Plugin).
In that case, it will check that every method In that case, it will check that every method
marked with the abstractmethod decorator is marked with the abstractmethod decorator is
provided by the plugin class. provided by the plugin class.
@@ -160,5 +160,3 @@ class QuantumPluginBase(object):
return NotImplemented return NotImplemented
return True return True
return NotImplemented return NotImplemented

View File

@@ -16,15 +16,14 @@
# under the License. # under the License.
import logging import logging
import json
import routes
from quantum.common import config from quantum.common import config
from quantum.common import wsgi from quantum.common import wsgi
from quantum.common import exceptions as exception from quantum.common import exceptions as exception
from webob import Response
LOG = logging.getLogger('quantum.service') LOG = logging.getLogger('quantum.service')
class WsgiService(object): class WsgiService(object):
"""Base class for WSGI based services. """Base class for WSGI based services.
@@ -60,21 +59,19 @@ class QuantumApiService(WsgiService):
message = (_('No paste configuration found for: %s'), message = (_('No paste configuration found for: %s'),
app_name) app_name)
raise exception.Error(message) raise exception.Error(message)
print "OPTIONS:%s" %options
print "CONF:%s" %conf
# Setup logging early, supplying both the CLI options and the # Setup logging early, supplying both the CLI options and the
# configuration mapping from the config file # configuration mapping from the config file
# We only update the conf dict for the verbose and debug # We only update the conf dict for the verbose and debug
# flags. Everything else must be set up in the conf file... # flags. Everything else must be set up in the conf file...
# Log the options used when starting if we're in debug mode... # Log the options used when starting if we're in debug mode...
config.setup_logging(options, conf) config.setup_logging(options, conf)
debug = options.get('debug') or \ debug = options.get('debug') or \
config.get_option(conf, 'debug', config.get_option(conf, 'debug',
type='bool', default=False) type='bool', default=False)
verbose = options.get('verbose') or \ verbose = options.get('verbose') or \
config.get_option(conf, 'verbose', config.get_option(conf, 'verbose',
type='bool', default=False) type='bool', default=False)
conf['debug'] = debug conf['debug'] = debug
conf['verbose'] = verbose conf['verbose'] = verbose
@@ -91,7 +88,7 @@ class QuantumApiService(WsgiService):
return service return service
def serve_wsgi(cls, conf=None, options = None, args = None): def serve_wsgi(cls, conf=None, options = None, args=None):
try: try:
service = cls.create(conf, options, args) service = cls.create(conf, options, args)
except Exception: except Exception:
@@ -104,7 +101,6 @@ def serve_wsgi(cls, conf=None, options = None, args = None):
def _run_wsgi(app_name, paste_conf, paste_config_file): def _run_wsgi(app_name, paste_conf, paste_config_file):
print "CICCIO"
LOG.info(_('Using paste.deploy config at: %s'), paste_config_file) LOG.info(_('Using paste.deploy config at: %s'), paste_config_file)
app = config.load_paste_app(paste_config_file, app_name) app = config.load_paste_app(paste_config_file, app_name)
if not app: if not app:
@@ -112,7 +108,6 @@ def _run_wsgi(app_name, paste_conf, paste_config_file):
paste_config_file) paste_config_file)
return return
server = wsgi.Server() server = wsgi.Server()
server.start(app, server.start(app,
int(paste_conf['bind_port']),paste_conf['bind_host']) int(paste_conf['bind_port']), paste_conf['bind_host'])
return server return server

View File

@@ -58,6 +58,7 @@ def import_object(import_str):
cls = import_class(import_str) cls = import_class(import_str)
return cls() return cls()
def to_primitive(value): def to_primitive(value):
if type(value) is type([]) or type(value) is type((None,)): if type(value) is type([]) or type(value) is type((None,)):
o = [] o = []
@@ -77,7 +78,8 @@ def to_primitive(value):
return to_primitive(list(value)) return to_primitive(list(value))
else: else:
return value return value
def dumps(value): def dumps(value):
try: try:
return json.dumps(value) return json.dumps(value)