pep8 fixes (1st batch)
This commit is contained in:
parent
9f1c248826
commit
75b67e63e2
@ -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)
|
|
||||||
|
@ -26,6 +26,7 @@ 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:
|
||||||
@ -56,7 +58,8 @@ class QuantumController(wsgi.Controller):
|
|||||||
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)
|
||||||
@ -65,4 +68,3 @@ class QuantumController(wsgi.Controller):
|
|||||||
|
|
||||||
def _setup_network_manager(self):
|
def _setup_network_manager(self):
|
||||||
self.network_manager = manager.QuantumManager().get_manager()
|
self.network_manager = manager.QuantumManager().get_manager()
|
||||||
|
|
||||||
|
@ -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"""
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ class Fault(webob.exc.HTTPException):
|
|||||||
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`
|
||||||
@ -131,6 +133,7 @@ class PortInUse(webob.exc.HTTPClientError):
|
|||||||
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`
|
||||||
|
@ -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)
|
||||||
|
@ -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": {
|
||||||
@ -53,7 +53,8 @@ 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
|
||||||
|
@ -69,22 +69,34 @@ elif sys.argv[1] == "list_ports" and len(sys.argv) == 4:
|
|||||||
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]
|
||||||
|
@ -31,6 +31,7 @@ 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):
|
||||||
@ -39,17 +40,17 @@ class QuantumManager(object):
|
|||||||
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):
|
def get_manager(self):
|
||||||
return self.plugin
|
return self.plugin
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# TODO(somik): rmove the main class
|
# TODO(somik): rmove the main class
|
||||||
# Added for temporary testing purposes
|
# Added for temporary testing purposes
|
||||||
def main():
|
def main():
|
||||||
@ -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()
|
||||||
|
|
||||||
|
@ -160,5 +160,3 @@ class QuantumPluginBase(object):
|
|||||||
return NotImplemented
|
return NotImplemented
|
||||||
return True
|
return True
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
|
|
||||||
|
@ -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,8 +59,6 @@ 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
|
||||||
@ -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:
|
||||||
@ -115,4 +111,3 @@ def _run_wsgi(app_name, paste_conf, paste_config_file):
|
|||||||
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
|
||||||
|
|
||||||
|
@ -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 = []
|
||||||
@ -78,6 +79,7 @@ def to_primitive(value):
|
|||||||
else:
|
else:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
def dumps(value):
|
def dumps(value):
|
||||||
try:
|
try:
|
||||||
return json.dumps(value)
|
return json.dumps(value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user