diff --git a/quantum/api/__init__.py b/quantum/api/__init__.py index b64f14f347..aa5a8791b1 100644 --- a/quantum/api/__init__.py +++ b/quantum/api/__init__.py @@ -40,6 +40,7 @@ class APIRouter(wsgi.Router): """ Base class for Quantum API routes. """ + _version = None def __init__(self, options=None): mapper = self._mapper() diff --git a/quantum/api/api_common.py b/quantum/api/api_common.py index 244f50f4ec..5007ba9ebc 100644 --- a/quantum/api/api_common.py +++ b/quantum/api/api_common.py @@ -165,6 +165,8 @@ class HeaderSerializer11(HeaderSerializer10): class QuantumController(object): """ Base controller class for Quantum API """ + # _resource_name will be redefined in sub concrete controller + _resource_name = None def __init__(self, plugin): self._plugin = plugin diff --git a/quantum/api/attachments.py b/quantum/api/attachments.py index 59ce248966..69588be05a 100644 --- a/quantum/api/attachments.py +++ b/quantum/api/attachments.py @@ -37,7 +37,9 @@ def create_resource(plugin, version): class Controller(common.QuantumController): """ Port API controller for Quantum API """ - + _resource_name = 'attachment' + # version will be redefined by in child class + version = None _attachment_ops_param_list = [ { 'param-name': 'id', @@ -53,10 +55,6 @@ class Controller(common.QuantumController): }, } - def __init__(self, plugin): - self._resource_name = 'attachment' - super(Controller, self).__init__(plugin) - @common.APIFaultWrapper([exception.NetworkNotFound, exception.PortNotFound]) def get_resource(self, request, tenant_id, network_id, id): @@ -83,15 +81,9 @@ class Controller(common.QuantumController): class ControllerV10(Controller): """Attachment resources controller for Quantum v1.0 API""" - - def __init__(self, plugin): - self.version = "1.0" - super(ControllerV10, self).__init__(plugin) + version = "1.0" class ControllerV11(Controller): """Attachment resources controller for Quantum v1.1 API""" - - def __init__(self, plugin): - self.version = "1.1" - super(ControllerV11, self).__init__(plugin) + version = "1.1" diff --git a/quantum/api/networks.py b/quantum/api/networks.py index 148dceca31..ad0606ef31 100644 --- a/quantum/api/networks.py +++ b/quantum/api/networks.py @@ -15,10 +15,8 @@ import logging -from webob import exc from quantum.api import api_common as common -from quantum.api import faults from quantum.api.views import filters from quantum.api.views import networks as networks_view from quantum.common import exceptions as exception @@ -41,15 +39,13 @@ def create_resource(plugin, version): class Controller(common.QuantumController): """ Network API controller for Quantum API """ - + _resource_name = 'network' + # version will be redefined in child class + version = None _network_ops_param_list = [ {'param-name': 'name', 'required': True}, ] - def __init__(self, plugin): - self._resource_name = 'network' - super(Controller, self).__init__(plugin) - def _item(self, request, tenant_id, network_id, net_details=True, port_details=False): # We expect get_network_details to return information @@ -165,9 +161,7 @@ class ControllerV10(Controller): }, } - def __init__(self, plugin): - self.version = "1.0" - super(ControllerV10, self).__init__(plugin) + version = "1.0" class ControllerV11(Controller): @@ -191,6 +185,4 @@ class ControllerV11(Controller): }, } - def __init__(self, plugin): - self.version = "1.1" - super(ControllerV11, self).__init__(plugin) + version = "1.1" diff --git a/quantum/api/ports.py b/quantum/api/ports.py index 317780f695..27075f046d 100644 --- a/quantum/api/ports.py +++ b/quantum/api/ports.py @@ -38,15 +38,13 @@ def create_resource(plugin, version): class Controller(common.QuantumController): """ Port API controller for Quantum API """ - + _resource_name = 'port' + # version will be redefined in child class + version = None _port_ops_param_list = [ {'param-name': 'state', 'default-value': 'DOWN', 'required': False}, ] - def __init__(self, plugin): - self._resource_name = 'port' - super(Controller, self).__init__(plugin) - def _items(self, request, tenant_id, network_id, port_details=False): """ Returns a list of ports. @@ -168,9 +166,7 @@ class ControllerV10(Controller): }, } - def __init__(self, plugin): - self.version = "1.0" - super(ControllerV10, self).__init__(plugin) + version = "1.0" class ControllerV11(Controller): @@ -186,6 +182,4 @@ class ControllerV11(Controller): }, } - def __init__(self, plugin): - self.version = "1.1" - super(ControllerV11, self).__init__(plugin) + version = "1.1" diff --git a/quantum/api/versions.py b/quantum/api/versions.py index 0e9c339277..8486ef3795 100644 --- a/quantum/api/versions.py +++ b/quantum/api/versions.py @@ -25,7 +25,11 @@ from quantum.api.views import versions as versions_view LOG = logging.getLogger(__name__) -class Versions(wsgi.Application): +class Versions(object): + + @classmethod + def factory(cls, global_config, **local_config): + return cls() @webob.dec.wsgify(RequestClass=wsgi.Request) def __call__(self, req): @@ -37,7 +41,7 @@ class Versions(wsgi.Application): }, { "id": "v1.1", - "status": "PROPOSED", + "status": "CURRENT", }, ] diff --git a/quantum/common/utils.py b/quantum/common/utils.py index 9fd1739d10..92b3719374 100644 --- a/quantum/common/utils.py +++ b/quantum/common/utils.py @@ -21,23 +21,15 @@ """Utilities and helper functions.""" -import base64 import ConfigParser import datetime -import functools import inspect import json import logging import os import random -import re -import socket -import string -import struct import subprocess import sys -import time -import types from quantum.common import exceptions as exception from quantum.common.exceptions import ProcessExecutionError diff --git a/quantum/extensions/extensions.py b/quantum/extensions/extensions.py index 6457ef95b4..83090d4192 100644 --- a/quantum/extensions/extensions.py +++ b/quantum/extensions/extensions.py @@ -364,7 +364,7 @@ class ExtensionManager(object): resources = [] resources.append(ResourceExtension('extensions', ExtensionController(self))) - for alias, ext in self.extensions.iteritems(): + for ext in self.extensions.itervalues(): try: resources.extend(ext.get_resources()) except AttributeError: @@ -376,7 +376,7 @@ class ExtensionManager(object): def get_actions(self): """Returns a list of ActionExtension objects.""" actions = [] - for alias, ext in self.extensions.iteritems(): + for ext in self.extensions.itervalues(): try: actions.extend(ext.get_actions()) except AttributeError: @@ -388,7 +388,7 @@ class ExtensionManager(object): def get_request_extensions(self): """Returns a list of RequestExtension objects.""" request_exts = [] - for alias, ext in self.extensions.iteritems(): + for ext in self.extensions.itervalues(): try: request_exts.extend(ext.get_request_extensions()) except AttributeError: diff --git a/quantum/plugins/cisco/db/api.py b/quantum/plugins/cisco/db/api.py index 373ca6838a..b4fc23f006 100644 --- a/quantum/plugins/cisco/db/api.py +++ b/quantum/plugins/cisco/db/api.py @@ -97,7 +97,7 @@ def network_list(tenant_id): def network_id(net_name): session = get_session() try: - return session.query(models.Network).\ + return session.query(models.Network).\ options(joinedload(models.Network.ports)). \ filter_by(name=net_name).\ all() @@ -108,7 +108,7 @@ def network_id(net_name): def network_get(net_id): session = get_session() try: - return session.query(models.Network).\ + return session.query(models.Network).\ options(joinedload(models.Network.ports)). \ filter_by(uuid=net_id).\ one() @@ -142,7 +142,7 @@ def network_destroy(net_id): def validate_network_ownership(tenant_id, net_id): session = get_session() try: - return session.query(models.Network).\ + return session.query(models.Network).\ filter_by(uuid=net_id).\ filter_by(tenant_id=tenant_id).\ one() @@ -176,7 +176,7 @@ def port_get(net_id, port_id): network_get(net_id) session = get_session() try: - return session.query(models.Port).\ + return session.query(models.Port).\ filter_by(uuid=port_id).\ filter_by(network_id=net_id).\ one() @@ -266,7 +266,7 @@ def port_destroy(net_id, port_id): def port_get_by_id(port_id): session = get_session() try: - return session.query(models.Port).\ + return session.query(models.Port).\ filter_by(uuid=port_id).one() except exc.NoResultFound: raise q_exc.PortNotFound(port_id=port_id) diff --git a/quantum/service.py b/quantum/service.py index 455b7f077f..ea2855c6c7 100644 --- a/quantum/service.py +++ b/quantum/service.py @@ -80,7 +80,9 @@ class QuantumApiService(WsgiService): items = dict([(k, v) for k, v in conf.items() if k not in ('__file__', 'here')]) for key, value in sorted(items.items()): - LOG.debug("%(key)-30s %(value)s" % locals()) + LOG.debug("%(key)-30s %(value)s" % {'key': key, + 'value': value, + }) LOG.debug("*" * 80) service = cls(app_name, conf_file, conf) return service diff --git a/quantum/tests/unit/extensions/foxinsocks.py b/quantum/tests/unit/extensions/foxinsocks.py index c43764edf8..a2dcc8435e 100644 --- a/quantum/tests/unit/extensions/foxinsocks.py +++ b/quantum/tests/unit/extensions/foxinsocks.py @@ -15,7 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. -from abc import abstractmethod +from abc import abstractmethod import json from quantum.extensions import extensions @@ -66,10 +66,10 @@ class Foxinsocks(object): return resources def get_actions(self): - return [extensions.ActionExtension('dummy_resources', + return [extensions.ActionExtension('dummy_resources', 'FOXNSOX:add_tweedle', self._add_tweedle_handler), - extensions.ActionExtension('dummy_resources', + extensions.ActionExtension('dummy_resources', 'FOXNSOX:delete_tweedle', self._delete_tweedle_handler)] diff --git a/quantum/tests/unit/test_extensions.py b/quantum/tests/unit/test_extensions.py index b660d617df..cb8de5b0e8 100644 --- a/quantum/tests/unit/test_extensions.py +++ b/quantum/tests/unit/test_extensions.py @@ -15,8 +15,6 @@ # under the License. import json -import os -import sys import unittest import routes @@ -39,7 +37,6 @@ from quantum.tests.unit.extension_stubs import ( StubBaseAppController, StubExtension, StubPlugin, - StubPluginInterface, ) import quantum.tests.unit.extensions from quantum import wsgi diff --git a/quantum/wsgi.py b/quantum/wsgi.py index 6dd5086140..b1f631b35e 100644 --- a/quantum/wsgi.py +++ b/quantum/wsgi.py @@ -310,7 +310,7 @@ class ResponseSerializer(object): self.body_serializers.update(body_serializers or {}) self.headers_serializer = (headers_serializer or - ResponseHeadersSerializer()) + ResponseHeaderSerializer()) def serialize(self, response_data, content_type, action='default'): """Serialize a dict into a string and wrap in a wsgi.Request object.