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):
|
||||
|
||||
uri_prefix = '/tenants/{tenant_id}/'
|
||||
mapper.resource('network',
|
||||
'networks',
|
||||
mapper.resource('network', 'networks',
|
||||
controller=networks.Controller(),
|
||||
path_prefix=uri_prefix)
|
||||
mapper.resource("port", "ports", controller=ports.Controller(),
|
||||
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}/ports/{id}/attachment{.format}',
|
||||
uri_prefix + 'networks/{network_id}/' \
|
||||
'ports/{id}/attachment{.format}',
|
||||
controller=ports.Controller(),
|
||||
action="get_resource",
|
||||
conditions=dict(method=['GET']))
|
||||
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(),
|
||||
action="attach_resource",
|
||||
conditions=dict(method=['PUT']))
|
||||
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(),
|
||||
action="detach_resource",
|
||||
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'
|
||||
LOG = logging.getLogger('quantum.api.api_common')
|
||||
|
||||
|
||||
class QuantumController(wsgi.Controller):
|
||||
""" Base controller class for Quantum API """
|
||||
|
||||
@ -40,7 +41,8 @@ class QuantumController(wsgi.Controller):
|
||||
param_value = None
|
||||
# 1- parse request 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)
|
||||
param_value = data and data.get(param_name, None)
|
||||
if not param_value:
|
||||
@ -56,13 +58,13 @@ class QuantumController(wsgi.Controller):
|
||||
pass
|
||||
if not param_value and param['required']:
|
||||
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'):
|
||||
LOG.error(line)
|
||||
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
|
||||
|
||||
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.common import wsgi
|
||||
|
||||
|
||||
class Fault(webob.exc.HTTPException):
|
||||
"""Error codes for API faults"""
|
||||
|
||||
@ -62,6 +63,7 @@ class Fault(webob.exc.HTTPException):
|
||||
self.wrapped_exc.content_type = content_type
|
||||
return self.wrapped_exc
|
||||
|
||||
|
||||
class NetworkNotFound(webob.exc.HTTPClientError):
|
||||
"""
|
||||
subclass of :class:`~HTTPClientError`
|
||||
@ -131,6 +133,7 @@ class PortInUse(webob.exc.HTTPClientError):
|
||||
title = 'Port in Use'
|
||||
explanation = ('A resource is currently attached to the logical port')
|
||||
|
||||
|
||||
class AlreadyAttached(webob.exc.HTTPClientError):
|
||||
"""
|
||||
subclass of :class:`~HTTPClientError`
|
||||
|
@ -30,12 +30,12 @@ class Controller(common.QuantumController):
|
||||
|
||||
_network_ops_param_list = [{
|
||||
'param-name': 'network-name',
|
||||
'required': True},]
|
||||
'required': True}, ]
|
||||
|
||||
_serialization_metadata = {
|
||||
"application/xml": {
|
||||
"attributes": {
|
||||
"network": ["id","name"],
|
||||
"network": ["id", "name"],
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -61,7 +61,7 @@ class Controller(common.QuantumController):
|
||||
""" Returns network details for the given network id """
|
||||
try:
|
||||
network = self.network_manager.get_network_details(
|
||||
tenant_id,id)
|
||||
tenant_id, id)
|
||||
builder = networks_view.get_view_builder(req)
|
||||
#build response with details
|
||||
result = builder.build(network, True)
|
||||
@ -77,7 +77,8 @@ class Controller(common.QuantumController):
|
||||
self._parse_request_params(req, self._network_ops_param_list)
|
||||
except exc.HTTPError as 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)
|
||||
result = builder.build(network)
|
||||
return dict(networks=result)
|
||||
@ -91,7 +92,7 @@ class Controller(common.QuantumController):
|
||||
return faults.Fault(e)
|
||||
try:
|
||||
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)
|
||||
result = builder.build(network, True)
|
||||
|
@ -23,6 +23,7 @@ from quantum.api.views import versions as versions_view
|
||||
|
||||
LOG = logging.getLogger('quantum.api.versions')
|
||||
|
||||
|
||||
class Versions(wsgi.Application):
|
||||
|
||||
@webob.dec.wsgify(RequestClass=wsgi.Request)
|
||||
@ -42,7 +43,6 @@ class Versions(wsgi.Application):
|
||||
builder = versions_view.get_view_builder(req)
|
||||
versions = [builder.build(version) for version in version_objs]
|
||||
response = dict(versions=versions)
|
||||
LOG.debug("response:%s",response)
|
||||
metadata = {
|
||||
"application/xml": {
|
||||
"attributes": {
|
||||
@ -53,7 +53,8 @@ class Versions(wsgi.Application):
|
||||
}
|
||||
|
||||
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.content_type = content_type
|
||||
|
@ -69,22 +69,34 @@ elif sys.argv[1] == "list_ports" and len(sys.argv) == 4:
|
||||
print "\tVirtual Port:%s" % port
|
||||
elif sys.argv[1] == "create_port" and len(sys.argv) == 4:
|
||||
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:
|
||||
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:
|
||||
port_detail = manager.get_port_details(sys.argv[2], 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)
|
||||
port_detail = manager.get_port_details(sys.argv[2],
|
||||
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:
|
||||
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:
|
||||
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:
|
||||
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], sys.argv[3], remote_iface)
|
||||
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],
|
||||
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])
|
||||
print "Remote Interfaces on Virtual Network:%s\n" % sys.argv[3]
|
||||
|
@ -31,25 +31,26 @@ from quantum_plugin_base import QuantumPluginBase
|
||||
|
||||
CONFIG_FILE = "quantum/plugins.ini"
|
||||
|
||||
|
||||
class QuantumManager(object):
|
||||
|
||||
def __init__(self,config=CONFIG_FILE):
|
||||
self.configuration_file = 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)
|
||||
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:
|
||||
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()
|
||||
|
||||
def get_manager(self):
|
||||
return self.plugin
|
||||
|
||||
|
||||
|
||||
|
||||
# TODO(somik): rmove the main class
|
||||
# Added for temporary testing purposes
|
||||
def main():
|
||||
@ -61,4 +62,3 @@ def main():
|
||||
# Standard boilerplate to call the main() function.
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
@ -160,5 +160,3 @@ class QuantumPluginBase(object):
|
||||
return NotImplemented
|
||||
return True
|
||||
return NotImplemented
|
||||
|
||||
|
||||
|
@ -16,15 +16,14 @@
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
import json
|
||||
import routes
|
||||
from quantum.common import config
|
||||
from quantum.common import wsgi
|
||||
from quantum.common import exceptions as exception
|
||||
from webob import Response
|
||||
|
||||
|
||||
LOG = logging.getLogger('quantum.service')
|
||||
|
||||
|
||||
class WsgiService(object):
|
||||
"""Base class for WSGI based services.
|
||||
|
||||
@ -60,8 +59,6 @@ class QuantumApiService(WsgiService):
|
||||
message = (_('No paste configuration found for: %s'),
|
||||
app_name)
|
||||
raise exception.Error(message)
|
||||
print "OPTIONS:%s" %options
|
||||
print "CONF:%s" %conf
|
||||
|
||||
# Setup logging early, supplying both the CLI options and the
|
||||
# configuration mapping from the config file
|
||||
@ -91,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:
|
||||
@ -104,7 +101,6 @@ def serve_wsgi(cls, conf=None, options = None, args = None):
|
||||
|
||||
|
||||
def _run_wsgi(app_name, paste_conf, paste_config_file):
|
||||
print "CICCIO"
|
||||
LOG.info(_('Using paste.deploy config at: %s'), paste_config_file)
|
||||
app = config.load_paste_app(paste_config_file, app_name)
|
||||
if not app:
|
||||
@ -113,6 +109,5 @@ def _run_wsgi(app_name, paste_conf, paste_config_file):
|
||||
return
|
||||
server = wsgi.Server()
|
||||
server.start(app,
|
||||
int(paste_conf['bind_port']),paste_conf['bind_host'])
|
||||
int(paste_conf['bind_port']), paste_conf['bind_host'])
|
||||
return server
|
||||
|
||||
|
@ -58,6 +58,7 @@ def import_object(import_str):
|
||||
cls = import_class(import_str)
|
||||
return cls()
|
||||
|
||||
|
||||
def to_primitive(value):
|
||||
if type(value) is type([]) or type(value) is type((None,)):
|
||||
o = []
|
||||
@ -78,6 +79,7 @@ def to_primitive(value):
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
def dumps(value):
|
||||
try:
|
||||
return json.dumps(value)
|
||||
|
Loading…
Reference in New Issue
Block a user