This commit is contained in:
Salvatore Orlando 2011-06-27 14:09:52 +01:00
parent 9c6ab1bc28
commit 1cb59504db
9 changed files with 158 additions and 12 deletions

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>quantum-api</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>

10
.pydevproject Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?>
<pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/quantum-api</path>
</pydev_pathproperty>
</pydev_project>

10
.pydevproject.moved Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?>
<pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/quantum-api</path>
</pydev_pathproperty>
</pydev_project>

61
bin/quantum.py Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 Nicira Neworks, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# If ../quantum/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
import gettext
import optparse
import os
import sys
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(possible_topdir, 'quantum', '__init__.py')):
sys.path.insert(0, possible_topdir)
gettext.install('quantum', unicode=1)
from quantum import service
from quantum.common import config
def create_options(parser):
"""
Sets up the CLI and config-file options that may be
parsed and program commands.
:param parser: The option parser
"""
config.add_common_options(parser)
config.add_log_options(parser)
if __name__ == '__main__':
oparser = optparse.OptionParser(version='%%prog VERSION')
create_options(oparser)
(options, args) = config.parse_options(oparser)
try:
service = service.serve_wsgi(service.QuantumApiService,
options=options,
args=args)
service.wait()
except RuntimeError, e:
sys.exit("ERROR: %s" % e)

49
pep8.errors Normal file
View File

@ -0,0 +1,49 @@
quantum/cli.py:39:43: W291 trailing whitespace
quantum/cli.py:92:68: W291 trailing whitespace
quantum/cli.py:95:62: W291 trailing whitespace
quantum/cli.py:98:53: W291 trailing whitespace
quantum/cli.py:110:1: W391 blank line at end of file
quantum/manager.py:21:80: E501 line too long (94 characters)
quantum/manager.py:37:22: E231 missing whitespace after ','
quantum/service.py:91:39: E251 no spaces around keyword / parameter equals
quantum/service.py:102:1: W293 blank line contains whitespace
quantum/api/__init__.py:54:41: W291 trailing whitespace
quantum/api/__init__.py:57:60: E251 no spaces around keyword / parameter equals
quantum/api/faults.py:55:57: W291 trailing whitespace
quantum/api/networks.py:81:48: E231 missing whitespace after ','
quantum/common/exceptions.py:98:1: E302 expected 2 blank lines, found 1
quantum/common/exceptions.py:103:1: E302 expected 2 blank lines, found 1
quantum/plugins/SamplePlugin.py:137:30: W291 trailing whitespace
quantum/plugins/SamplePlugin.py:139:47: E203 whitespace before ','
quantum/plugins/SamplePlugin.py:184:1: W293 blank line contains whitespace
quantum/plugins/SamplePlugin.py:255:38: W291 trailing whitespace
quantum/plugins/SamplePlugin.py:258:38: W291 trailing whitespace
quantum/plugins/SamplePlugin.py:255:21: E203 whitespace before ':'
quantum/plugins/SamplePlugin.py:259:37: E231 missing whitespace after ':'
quantum/plugins/SamplePlugin.py:263:38: W291 trailing whitespace
quantum/plugins/SamplePlugin.py:266:38: W291 trailing whitespace
quantum/plugins/SamplePlugin.py:269:21: W291 trailing whitespace
quantum/plugins/SamplePlugin.py:263:21: E203 whitespace before ':'
quantum/plugins/SamplePlugin.py:267:37: E231 missing whitespace after ':'
quantum/plugins/SamplePlugin.py:280:46: W291 trailing whitespace
quantum/plugins/SamplePlugin.py:272:29: E231 missing whitespace after ':'
quantum/plugins/SamplePlugin.py:270:14: E225 missing whitespace around operator
quantum/plugins/SamplePlugin.py:284:32: E225 missing whitespace around operator
quantum/plugins/SamplePlugin.py:300:43: E231 missing whitespace after ','
quantum/plugins/SamplePlugin.py:309:49: E251 no spaces around keyword / parameter equals
quantum/plugins/SamplePlugin.py:318:30: W291 trailing whitespace
quantum/plugins/SamplePlugin.py:338:19: E225 missing whitespace around operator
quantum/plugins/SamplePlugin.py:341:31: E231 missing whitespace after ':'
quantum/plugins/SamplePlugin.py:341:21: E225 missing whitespace around operator
quantum/plugins/SamplePlugin.py:344:41: E225 missing whitespace around operator
quantum/plugins/SamplePlugin.py:373:33: W291 trailing whitespace
quantum/plugins/SamplePlugin.py:373:24: E225 missing whitespace around operator
quantum/plugins/SamplePlugin.py:401:63: W291 trailing whitespace
quantum/plugins/SamplePlugin.py:404:40: E225 missing whitespace around operator
quantum/plugins/SamplePlugin.py:405:35: E231 missing whitespace after ':'
quantum/plugins/SamplePlugin.py:409:29: W291 trailing whitespace
quantum/plugins/SamplePlugin.py:419:20: W291 trailing whitespace
quantum/plugins/SamplePlugin.py:432:46: E231 missing whitespace after ','
quantum/plugins/SamplePlugin.py:436:25: W291 trailing whitespace
quantum/plugins/SamplePlugin.py:459:46: E231 missing whitespace after ','
quantum/plugins/SamplePlugin.py:482:80: E501 line too long (99 characters)

View File

@ -58,8 +58,7 @@ 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 " + "Parameter: " + param_name + " not specified")
"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)

View File

@ -48,17 +48,17 @@ class Controller(common.QuantumController):
def index(self, request, tenant_id): def index(self, request, tenant_id):
""" Returns a list of network ids """ """ Returns a list of network ids """
#TODO: this should be for a given tenant!!! #TODO: this should be for a given tenant!!!
return self._items(request, tenant_id, net_detail=False) return self._items(request, tenant_id)
def _item(self, req, tenant_id, network_id, def _item(self, req, tenant_id, network_id,
net_details, port_details): net_details=True, port_details=False):
network = self.network_manager.get_network_details( network = self.network_manager.get_network_details(
tenant_id, network_id) tenant_id, network_id)
builder = networks_view.get_view_builder(req) builder = networks_view.get_view_builder(req)
result = builder.build(network, net_details, port_details) result = builder.build(network, net_details, port_details)
return dict(networks=result) return dict(networks=result)
def _items(self, req, tenant_id, net_details, port_details): def _items(self, req, tenant_id, net_details=False, port_details=False):
""" Returns a list of networks. """ """ Returns a list of networks. """
networks = self.network_manager.get_all_networks(tenant_id) networks = self.network_manager.get_all_networks(tenant_id)
builder = networks_view.get_view_builder(req) builder = networks_view.get_view_builder(req)

View File

@ -20,17 +20,13 @@
Utility methods for working with WSGI servers Utility methods for working with WSGI servers
""" """
import json
import logging import logging
import sys import sys
import datetime
from xml.dom import minidom from xml.dom import minidom
import eventlet
import eventlet.wsgi import eventlet.wsgi
eventlet.patcher.monkey_patch(all=False, socket=True) eventlet.patcher.monkey_patch(all=False, socket=True)
import routes
import routes.middleware import routes.middleware
import webob.dec import webob.dec
import webob.exc import webob.exc
@ -423,6 +419,7 @@ class Serializer(object):
The string must be in the format of a supported MIME type. The string must be in the format of a supported MIME type.
""" """
LOG.debug("Deserialize invoked:%s", datastring)
return self.get_deserialize_handler(content_type)(datastring) return self.get_deserialize_handler(content_type)(datastring)
def get_deserialize_handler(self, content_type): def get_deserialize_handler(self, content_type):
@ -455,7 +452,8 @@ class Serializer(object):
if len(node.childNodes) == 1 and node.childNodes[0].nodeType == 3: if len(node.childNodes) == 1 and node.childNodes[0].nodeType == 3:
return node.childNodes[0].nodeValue return node.childNodes[0].nodeValue
elif node.nodeName in listnames: elif node.nodeName in listnames:
return [self._from_xml_node(n, listnames) for n in node.childNodes] return [self._from_xml_node(n, listnames)
for n in node.childNodes if n.nodeType != node.TEXT_NODE]
else: else:
result = dict() result = dict()
for attr in node.attributes.keys(): for attr in node.attributes.keys():

View File

@ -49,7 +49,8 @@ def print_response(res):
class QuantumTest(unittest.TestCase): class QuantumTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.client = MiniClient(HOST, PORT, USE_SSL) self.client = MiniClient(HOST, PORT, USE_SSL)
def create_network(self, data): def create_network(self, data):
content_type = "application/" + FORMAT content_type = "application/" + FORMAT
body = Serializer().serialize(data, content_type) body = Serializer().serialize(data, content_type)
@ -128,7 +129,8 @@ class QuantumTest(unittest.TestCase):
self.assertEqual(res.status, 202) self.assertEqual(res.status, 202)
def tearDown(self): def tearDown(self):
self.delete_networks() pass
#self.delete_networks()
# Standard boilerplate to call the main() function. # Standard boilerplate to call the main() function.
if __name__ == '__main__': if __name__ == '__main__':