From de635fc882caebd5d5c9701e755a7174e37a05c5 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Fri, 11 Nov 2011 13:26:13 -0500 Subject: [PATCH] Creating new v2 namespace in nova.api.openstack Related to blueprint separate-nova-adminapi Change-Id: Ida35372b7263c4a4efdafd35faa1325c4436459b --- etc/nova/api-paste.ini | 27 +-- nova/api/openstack/__init__.py | 187 ------------------ nova/api/openstack/faults.py | 116 ----------- nova/api/openstack/v2/__init__.py | 186 +++++++++++++++++ nova/api/openstack/{ => v2}/accounts.py | 10 +- nova/api/openstack/{ => v2}/auth.py | 30 +-- nova/api/openstack/{ => v2}/consoles.py | 6 +- .../openstack/{ => v2}/contrib/__init__.py | 2 +- .../{ => v2}/contrib/admin_actions.py | 4 +- .../{ => v2}/contrib/createserverext.py | 6 +- .../{ => v2}/contrib/deferred_delete.py | 6 +- .../openstack/{ => v2}/contrib/disk_config.py | 6 +- .../{ => v2}/contrib/extended_status.py | 7 +- .../{ => v2}/contrib/flavorextradata.py | 6 +- .../{ => v2}/contrib/flavorextraspecs.py | 3 +- .../{ => v2}/contrib/floating_ips.py | 5 +- nova/api/openstack/{ => v2}/contrib/hosts.py | 7 +- .../openstack/{ => v2}/contrib/keypairs.py | 2 +- .../openstack/{ => v2}/contrib/multinic.py | 4 +- nova/api/openstack/{ => v2}/contrib/quotas.py | 2 +- nova/api/openstack/{ => v2}/contrib/rescue.py | 5 +- .../{ => v2}/contrib/security_groups.py | 14 +- .../{ => v2}/contrib/simple_tenant_usage.py | 17 +- .../{ => v2}/contrib/virtual_interfaces.py | 8 +- .../contrib/virtual_storage_arrays.py | 22 +-- .../api/openstack/{ => v2}/contrib/volumes.py | 8 +- .../openstack/{ => v2}/contrib/volumetypes.py | 4 +- nova/api/openstack/{ => v2}/contrib/zones.py | 4 +- nova/api/openstack/{ => v2}/extensions.py | 12 +- nova/api/openstack/{ => v2}/flavors.py | 4 +- nova/api/openstack/{ => v2}/image_metadata.py | 4 +- nova/api/openstack/{ => v2}/images.py | 12 +- nova/api/openstack/{ => v2}/ips.py | 5 +- nova/api/openstack/{ => v2}/limits.py | 20 +- .../{ => v2}/ratelimiting/__init__.py | 5 +- .../openstack/{ => v2}/schemas/atom-link.rng | 0 nova/api/openstack/{ => v2}/schemas/atom.rng | 0 .../{ => v2}/schemas/v1.1/addresses.rng | 0 .../{ => v2}/schemas/v1.1/extension.rng | 0 .../{ => v2}/schemas/v1.1/extensions.rng | 0 .../{ => v2}/schemas/v1.1/flavor.rng | 0 .../{ => v2}/schemas/v1.1/flavors.rng | 0 .../{ => v2}/schemas/v1.1/flavors_index.rng | 0 .../openstack/{ => v2}/schemas/v1.1/image.rng | 0 .../{ => v2}/schemas/v1.1/images.rng | 0 .../{ => v2}/schemas/v1.1/images_index.rng | 0 .../{ => v2}/schemas/v1.1/limits.rng | 0 .../{ => v2}/schemas/v1.1/metadata.rng | 0 .../{ => v2}/schemas/v1.1/server.rng | 0 .../{ => v2}/schemas/v1.1/servers.rng | 0 .../{ => v2}/schemas/v1.1/servers_index.rng | 0 .../{ => v2}/schemas/v1.1/version.rng | 0 .../{ => v2}/schemas/v1.1/versions.rng | 0 .../api/openstack/{ => v2}/server_metadata.py | 2 +- nova/api/openstack/{ => v2}/servers.py | 13 +- nova/api/openstack/{ => v2}/urlmap.py | 2 +- nova/api/openstack/{ => v2}/users.py | 8 +- nova/api/openstack/{ => v2}/versions.py | 7 +- nova/api/openstack/{ => v2}/views/__init__.py | 0 .../api/openstack/{ => v2}/views/addresses.py | 2 +- nova/api/openstack/{ => v2}/views/flavors.py | 1 - nova/api/openstack/{ => v2}/views/images.py | 0 nova/api/openstack/{ => v2}/views/limits.py | 0 nova/api/openstack/{ => v2}/views/servers.py | 11 +- nova/api/openstack/{ => v2}/views/versions.py | 0 nova/api/openstack/{ => v2}/zones.py | 14 +- nova/api/openstack/wsgi.py | 107 +++++++++- nova/api/openstack/xmlutil.py | 4 +- nova/flags.py | 2 +- nova/tests/api/openstack/__init__.py | 16 -- nova/tests/api/openstack/fakes.py | 53 ++--- nova/tests/api/openstack/test_faults.py | 11 +- nova/tests/api/openstack/v2/__init__.py | 16 ++ .../openstack/{ => v2}/contrib/__init__.py | 0 .../{ => v2}/contrib/test_admin_actions.py | 0 .../{ => v2}/contrib/test_createserverext.py | 2 +- .../{ => v2}/contrib/test_disk_config.py | 20 +- .../{ => v2}/contrib/test_extendedstatus.py | 1 + .../contrib/test_flavors_extra_specs.py | 9 +- .../{ => v2}/contrib/test_floating_ips.py | 13 +- .../{ => v2}/contrib/test_keypairs.py | 3 +- .../{ => v2}/contrib/test_multinic_xs.py | 1 + .../openstack/{ => v2}/contrib/test_quotas.py | 3 +- .../openstack/{ => v2}/contrib/test_rescue.py | 1 + .../{ => v2}/contrib/test_security_groups.py | 9 +- .../contrib/test_simple_tenant_usage.py | 2 +- .../contrib/test_virtual_interfaces.py | 9 +- .../{ => v2}/contrib/test_volume_types.py | 6 +- .../contrib/test_volume_types_extra_specs.py | 9 +- .../{ => v2}/contrib/test_volumes.py | 3 +- .../openstack/{ => v2}/contrib/test_vsa.py | 13 +- .../openstack/{ => v2}/extensions/__init__.py | 0 .../{ => v2}/extensions/foxinsocks.py | 2 +- .../api/openstack/{ => v2}/test_accounts.py | 2 +- nova/tests/api/openstack/{ => v2}/test_api.py | 11 +- .../tests/api/openstack/{ => v2}/test_auth.py | 18 +- .../api/openstack/{ => v2}/test_consoles.py | 2 +- .../api/openstack/{ => v2}/test_extensions.py | 41 ++-- .../api/openstack/{ => v2}/test_flavors.py | 2 +- .../openstack/{ => v2}/test_image_metadata.py | 5 +- .../api/openstack/{ => v2}/test_images.py | 7 +- .../api/openstack/{ => v2}/test_limits.py | 13 +- .../openstack/{ => v2}/test_server_actions.py | 25 ++- .../{ => v2}/test_server_metadata.py | 4 +- .../api/openstack/{ => v2}/test_servers.py | 17 +- .../api/openstack/{ => v2}/test_urlmap.py | 4 +- .../api/openstack/{ => v2}/test_users.py | 2 +- .../api/openstack/{ => v2}/test_versions.py | 4 +- .../api/openstack/{ => v2}/test_zones.py | 10 +- nova/tests/integrated/test_extensions.py | 2 +- nova/tests/test_hosts.py | 3 +- 111 files changed, 642 insertions(+), 671 deletions(-) delete mode 100644 nova/api/openstack/faults.py create mode 100644 nova/api/openstack/v2/__init__.py rename nova/api/openstack/{ => v2}/accounts.py (97%) rename nova/api/openstack/{ => v2}/auth.py (92%) rename nova/api/openstack/{ => v2}/consoles.py (100%) rename nova/api/openstack/{ => v2}/contrib/__init__.py (98%) rename nova/api/openstack/{ => v2}/contrib/admin_actions.py (98%) rename nova/api/openstack/{ => v2}/contrib/createserverext.py (95%) rename nova/api/openstack/{ => v2}/contrib/deferred_delete.py (93%) rename nova/api/openstack/{ => v2}/contrib/disk_config.py (98%) rename nova/api/openstack/{ => v2}/contrib/extended_status.py (96%) rename nova/api/openstack/{ => v2}/contrib/flavorextradata.py (96%) rename nova/api/openstack/{ => v2}/contrib/flavorextraspecs.py (98%) rename nova/api/openstack/{ => v2}/contrib/floating_ips.py (98%) rename nova/api/openstack/{ => v2}/contrib/hosts.py (97%) rename nova/api/openstack/{ => v2}/contrib/keypairs.py (98%) rename nova/api/openstack/{ => v2}/contrib/multinic.py (97%) rename nova/api/openstack/{ => v2}/contrib/quotas.py (98%) rename nova/api/openstack/{ => v2}/contrib/rescue.py (94%) rename nova/api/openstack/{ => v2}/contrib/security_groups.py (99%) rename nova/api/openstack/{ => v2}/contrib/simple_tenant_usage.py (99%) rename nova/api/openstack/{ => v2}/contrib/virtual_interfaces.py (96%) rename nova/api/openstack/{ => v2}/contrib/virtual_storage_arrays.py (99%) rename nova/api/openstack/{ => v2}/contrib/volumes.py (98%) rename nova/api/openstack/{ => v2}/contrib/volumetypes.py (99%) rename nova/api/openstack/{ => v2}/contrib/zones.py (92%) rename nova/api/openstack/{ => v2}/extensions.py (99%) rename nova/api/openstack/{ => v2}/flavors.py (98%) rename nova/api/openstack/{ => v2}/image_metadata.py (100%) rename nova/api/openstack/{ => v2}/images.py (97%) rename nova/api/openstack/{ => v2}/ips.py (96%) rename nova/api/openstack/{ => v2}/limits.py (98%) rename nova/api/openstack/{ => v2}/ratelimiting/__init__.py (99%) rename nova/api/openstack/{ => v2}/schemas/atom-link.rng (100%) rename nova/api/openstack/{ => v2}/schemas/atom.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/addresses.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/extension.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/extensions.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/flavor.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/flavors.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/flavors_index.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/image.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/images.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/images_index.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/limits.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/metadata.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/server.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/servers.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/servers_index.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/version.rng (100%) rename nova/api/openstack/{ => v2}/schemas/v1.1/versions.rng (100%) rename nova/api/openstack/{ => v2}/server_metadata.py (100%) rename nova/api/openstack/{ => v2}/servers.py (99%) rename nova/api/openstack/{ => v2}/urlmap.py (99%) rename nova/api/openstack/{ => v2}/users.py (98%) rename nova/api/openstack/{ => v2}/versions.py (97%) rename nova/api/openstack/{ => v2}/views/__init__.py (100%) rename nova/api/openstack/{ => v2}/views/addresses.py (96%) rename nova/api/openstack/{ => v2}/views/flavors.py (99%) rename nova/api/openstack/{ => v2}/views/images.py (100%) rename nova/api/openstack/{ => v2}/views/limits.py (100%) rename nova/api/openstack/{ => v2}/views/servers.py (95%) rename nova/api/openstack/{ => v2}/views/versions.py (100%) rename nova/api/openstack/{ => v2}/zones.py (98%) create mode 100644 nova/tests/api/openstack/v2/__init__.py rename nova/tests/api/openstack/{ => v2}/contrib/__init__.py (100%) rename nova/tests/api/openstack/{ => v2}/contrib/test_admin_actions.py (100%) rename nova/tests/api/openstack/{ => v2}/contrib/test_createserverext.py (99%) rename nova/tests/api/openstack/{ => v2}/contrib/test_disk_config.py (98%) rename nova/tests/api/openstack/{ => v2}/contrib/test_extendedstatus.py (99%) rename nova/tests/api/openstack/{ => v2}/contrib/test_flavors_extra_specs.py (97%) rename nova/tests/api/openstack/{ => v2}/contrib/test_floating_ips.py (96%) rename nova/tests/api/openstack/{ => v2}/contrib/test_keypairs.py (98%) rename nova/tests/api/openstack/{ => v2}/contrib/test_multinic_xs.py (99%) rename nova/tests/api/openstack/{ => v2}/contrib/test_quotas.py (98%) rename nova/tests/api/openstack/{ => v2}/contrib/test_rescue.py (99%) rename nova/tests/api/openstack/{ => v2}/contrib/test_security_groups.py (99%) rename nova/tests/api/openstack/{ => v2}/contrib/test_simple_tenant_usage.py (100%) rename nova/tests/api/openstack/{ => v2}/contrib/test_virtual_interfaces.py (97%) rename nova/tests/api/openstack/{ => v2}/contrib/test_volume_types.py (97%) rename nova/tests/api/openstack/{ => v2}/contrib/test_volume_types_extra_specs.py (97%) rename nova/tests/api/openstack/{ => v2}/contrib/test_volumes.py (99%) rename nova/tests/api/openstack/{ => v2}/contrib/test_vsa.py (98%) rename nova/tests/api/openstack/{ => v2}/extensions/__init__.py (100%) rename nova/tests/api/openstack/{ => v2}/extensions/foxinsocks.py (98%) rename nova/tests/api/openstack/{ => v2}/test_accounts.py (99%) rename nova/tests/api/openstack/{ => v2}/test_api.py (96%) rename nova/tests/api/openstack/{ => v2}/test_auth.py (95%) rename nova/tests/api/openstack/{ => v2}/test_consoles.py (99%) rename nova/tests/api/openstack/{ => v2}/test_extensions.py (96%) rename nova/tests/api/openstack/{ => v2}/test_flavors.py (99%) rename nova/tests/api/openstack/{ => v2}/test_image_metadata.py (99%) rename nova/tests/api/openstack/{ => v2}/test_images.py (99%) rename nova/tests/api/openstack/{ => v2}/test_limits.py (99%) rename nova/tests/api/openstack/{ => v2}/test_server_actions.py (97%) rename nova/tests/api/openstack/{ => v2}/test_server_metadata.py (99%) rename nova/tests/api/openstack/{ => v2}/test_servers.py (99%) rename nova/tests/api/openstack/{ => v2}/test_urlmap.py (98%) rename nova/tests/api/openstack/{ => v2}/test_users.py (99%) rename nova/tests/api/openstack/{ => v2}/test_versions.py (99%) rename nova/tests/api/openstack/{ => v2}/test_zones.py (99%) diff --git a/etc/nova/api-paste.ini b/etc/nova/api-paste.ini index 580191c010..145044df74 100644 --- a/etc/nova/api-paste.ini +++ b/etc/nova/api-paste.ini @@ -79,38 +79,39 @@ paste.app_factory = nova.api.ec2:Executor.factory ############# [composite:osapi] -use = call:nova.api.openstack.urlmap:urlmap_factory +use = call:nova.api.openstack.v2.urlmap:urlmap_factory /: osversions -/v1.1: openstackapi11 +/v1.1: openstack_api_v2 +/v2: openstack_api_v2 -[pipeline:openstackapi11] -pipeline = faultwrap noauth ratelimit serialize extensions osapiapp11 +[pipeline:openstack_api_v2] +pipeline = faultwrap noauth ratelimit serialize extensions osapi_app_v2 # NOTE(vish): use the following pipeline for deprecated auth -# pipeline = faultwrap auth ratelimit serialize extensions osapiapp11 +# pipeline = faultwrap auth ratelimit serialize extensions osapi_app_v2 [filter:faultwrap] -paste.filter_factory = nova.api.openstack:FaultWrapper.factory +paste.filter_factory = nova.api.openstack.v2:FaultWrapper.factory [filter:auth] -paste.filter_factory = nova.api.openstack.auth:AuthMiddleware.factory +paste.filter_factory = nova.api.openstack.v2.auth:AuthMiddleware.factory [filter:noauth] -paste.filter_factory = nova.api.openstack.auth:NoAuthMiddleware.factory +paste.filter_factory = nova.api.openstack.v2.auth:NoAuthMiddleware.factory [filter:ratelimit] -paste.filter_factory = nova.api.openstack.limits:RateLimitingMiddleware.factory +paste.filter_factory = nova.api.openstack.v2.limits:RateLimitingMiddleware.factory [filter:serialize] paste.filter_factory = nova.api.openstack.wsgi:LazySerializationMiddleware.factory [filter:extensions] -paste.filter_factory = nova.api.openstack.extensions:ExtensionMiddleware.factory +paste.filter_factory = nova.api.openstack.v2.extensions:ExtensionMiddleware.factory -[app:osapiapp11] -paste.app_factory = nova.api.openstack:APIRouter.factory +[app:osapi_app_v2] +paste.app_factory = nova.api.openstack.v2:APIRouter.factory [pipeline:osversions] pipeline = faultwrap osversionapp [app:osversionapp] -paste.app_factory = nova.api.openstack.versions:Versions.factory +paste.app_factory = nova.api.openstack.v2.versions:Versions.factory diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index 07911221d9..e69de29bb2 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -1,187 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# 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. - -""" -WSGI middleware for OpenStack API controllers. -""" - -import routes -import webob.dec -import webob.exc - -from nova.api.openstack import accounts -from nova.api.openstack import faults -from nova.api.openstack import consoles -from nova.api.openstack import flavors -from nova.api.openstack import images -from nova.api.openstack import image_metadata -from nova.api.openstack import ips -from nova.api.openstack import limits -from nova.api.openstack import servers -from nova.api.openstack import server_metadata -from nova.api.openstack import users -from nova.api.openstack import versions -from nova.api.openstack import wsgi -from nova.api.openstack import zones -from nova import flags -from nova import log as logging -from nova import wsgi as base_wsgi - - -LOG = logging.getLogger('nova.api.openstack') -FLAGS = flags.FLAGS -flags.DEFINE_bool('allow_admin_api', - False, - 'When True, this API service will accept admin operations.') -flags.DEFINE_bool('allow_instance_snapshots', - True, - 'When True, this API service will permit instance snapshot operations.') - - -class FaultWrapper(base_wsgi.Middleware): - """Calls down the middleware stack, making exceptions into faults.""" - - @webob.dec.wsgify(RequestClass=wsgi.Request) - def __call__(self, req): - try: - return req.get_response(self.application) - except Exception as ex: - LOG.exception(_("Caught error: %s"), unicode(ex)) - exc = webob.exc.HTTPInternalServerError() - return faults.Fault(exc) - - -class APIMapper(routes.Mapper): - def routematch(self, url=None, environ=None): - if url is "": - result = self._match("", environ) - return result[0], result[1] - return routes.Mapper.routematch(self, url, environ) - - -class ProjectMapper(APIMapper): - - def resource(self, member_name, collection_name, **kwargs): - if not ('parent_resource' in kwargs): - kwargs['path_prefix'] = '{project_id}/' - else: - parent_resource = kwargs['parent_resource'] - p_collection = parent_resource['collection_name'] - p_member = parent_resource['member_name'] - kwargs['path_prefix'] = '{project_id}/%s/:%s_id' % (p_collection, - p_member) - routes.Mapper.resource(self, member_name, - collection_name, - **kwargs) - - -class APIRouter(base_wsgi.Router): - """ - Routes requests on the OpenStack API to the appropriate controller - and method. - """ - - @classmethod - def factory(cls, global_config, **local_config): - """Simple paste factory, :class:`nova.wsgi.Router` doesn't have one""" - return cls() - - def __init__(self, ext_mgr=None): - self.server_members = {} - mapper = ProjectMapper() - self._setup_routes(mapper) - super(APIRouter, self).__init__(mapper) - - def _setup_routes(self, mapper): - server_members = self.server_members - server_members['action'] = 'POST' - if FLAGS.allow_admin_api: - LOG.debug(_("Including admin operations in API.")) - - server_members['diagnostics'] = 'GET' - server_members['actions'] = 'GET' - - mapper.resource("user", "users", - controller=users.create_resource(), - collection={'detail': 'GET'}) - - mapper.resource("account", "accounts", - controller=accounts.create_resource(), - collection={'detail': 'GET'}) - - mapper.resource("zone", "zones", - controller=zones.create_resource(), - collection={'detail': 'GET', - 'info': 'GET', - 'select': 'POST'}) - - mapper.connect("versions", "/", - controller=versions.create_resource(), - action='show') - - mapper.redirect("", "/") - - mapper.resource("console", "consoles", - controller=consoles.create_resource(), - parent_resource=dict(member_name='server', - collection_name='servers')) - - mapper.resource("server", "servers", - controller=servers.create_resource(), - collection={'detail': 'GET'}, - member=self.server_members) - - mapper.resource("ip", "ips", controller=ips.create_resource(), - parent_resource=dict(member_name='server', - collection_name='servers')) - - mapper.resource("image", "images", - controller=images.create_resource(), - collection={'detail': 'GET'}) - - mapper.resource("limit", "limits", - controller=limits.create_resource()) - - mapper.resource("flavor", "flavors", - controller=flavors.create_resource(), - collection={'detail': 'GET'}) - - image_metadata_controller = image_metadata.create_resource() - - mapper.resource("image_meta", "metadata", - controller=image_metadata_controller, - parent_resource=dict(member_name='image', - collection_name='images')) - - mapper.connect("metadata", "/{project_id}/images/{image_id}/metadata", - controller=image_metadata_controller, - action='update_all', - conditions={"method": ['PUT']}) - - server_metadata_controller = server_metadata.create_resource() - - mapper.resource("server_meta", "metadata", - controller=server_metadata_controller, - parent_resource=dict(member_name='server', - collection_name='servers')) - - mapper.connect("metadata", - "/{project_id}/servers/{server_id}/metadata", - controller=server_metadata_controller, - action='update_all', - conditions={"method": ['PUT']}) diff --git a/nova/api/openstack/faults.py b/nova/api/openstack/faults.py deleted file mode 100644 index 83381d7556..0000000000 --- a/nova/api/openstack/faults.py +++ /dev/null @@ -1,116 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2010 OpenStack LLC. -# 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. - - -import webob.dec -import webob.exc - -from nova.api.openstack import common -from nova.api.openstack import wsgi - - -class Fault(webob.exc.HTTPException): - """Wrap webob.exc.HTTPException to provide API friendly response.""" - - _fault_names = { - 400: "badRequest", - 401: "unauthorized", - 403: "resizeNotAllowed", - 404: "itemNotFound", - 405: "badMethod", - 409: "inProgress", - 413: "overLimit", - 415: "badMediaType", - 501: "notImplemented", - 503: "serviceUnavailable"} - - def __init__(self, exception): - """Create a Fault for the given webob.exc.exception.""" - self.wrapped_exc = exception - self.status_int = exception.status_int - - @webob.dec.wsgify(RequestClass=wsgi.Request) - def __call__(self, req): - """Generate a WSGI response based on the exception passed to ctor.""" - # Replace the body with fault details. - code = self.wrapped_exc.status_int - fault_name = self._fault_names.get(code, "cloudServersFault") - fault_data = { - fault_name: { - 'code': code, - 'message': self.wrapped_exc.explanation}} - if code == 413: - retry = self.wrapped_exc.headers['Retry-After'] - fault_data[fault_name]['retryAfter'] = retry - - # 'code' is an attribute on the fault tag itself - metadata = {'attributes': {fault_name: 'code'}} - - xml_serializer = wsgi.XMLDictSerializer(metadata, wsgi.XMLNS_V11) - - content_type = req.best_match_content_type() - serializer = { - 'application/xml': xml_serializer, - 'application/json': wsgi.JSONDictSerializer(), - }[content_type] - - self.wrapped_exc.body = serializer.serialize(fault_data) - self.wrapped_exc.content_type = content_type - - return self.wrapped_exc - - def __str__(self): - return self.wrapped_exc.__str__() - - -class OverLimitFault(webob.exc.HTTPException): - """ - Rate-limited request response. - """ - - def __init__(self, message, details, retry_time): - """ - Initialize new `OverLimitFault` with relevant information. - """ - self.wrapped_exc = webob.exc.HTTPRequestEntityTooLarge() - self.content = { - "overLimitFault": { - "code": self.wrapped_exc.status_int, - "message": message, - "details": details, - }, - } - - @webob.dec.wsgify(RequestClass=wsgi.Request) - def __call__(self, request): - """ - Return the wrapped exception with a serialized body conforming to our - error format. - """ - content_type = request.best_match_content_type() - metadata = {"attributes": {"overLimitFault": "code"}} - - xml_serializer = wsgi.XMLDictSerializer(metadata, wsgi.XMLNS_V11) - serializer = { - 'application/xml': xml_serializer, - 'application/json': wsgi.JSONDictSerializer(), - }[content_type] - - content = serializer.serialize(self.content) - self.wrapped_exc.body = content - - return self.wrapped_exc diff --git a/nova/api/openstack/v2/__init__.py b/nova/api/openstack/v2/__init__.py new file mode 100644 index 0000000000..1ea2ba250a --- /dev/null +++ b/nova/api/openstack/v2/__init__.py @@ -0,0 +1,186 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# 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. + +""" +WSGI middleware for OpenStack API controllers. +""" + +import routes +import webob.dec +import webob.exc + +from nova.api.openstack.v2 import accounts +from nova.api.openstack.v2 import consoles +from nova.api.openstack.v2 import flavors +from nova.api.openstack.v2 import images +from nova.api.openstack.v2 import image_metadata +from nova.api.openstack.v2 import ips +from nova.api.openstack.v2 import limits +from nova.api.openstack.v2 import servers +from nova.api.openstack.v2 import server_metadata +from nova.api.openstack.v2 import users +from nova.api.openstack.v2 import versions +from nova.api.openstack.v2 import zones +from nova.api.openstack import wsgi +from nova import flags +from nova import log as logging +from nova import wsgi as base_wsgi + + +LOG = logging.getLogger('nova.api.openstack.v2') +FLAGS = flags.FLAGS +flags.DEFINE_bool('allow_admin_api', + False, + 'When True, this API service will accept admin operations.') +flags.DEFINE_bool('allow_instance_snapshots', + True, + 'When True, this API service will permit instance snapshot operations.') + + +class FaultWrapper(base_wsgi.Middleware): + """Calls down the middleware stack, making exceptions into faults.""" + + @webob.dec.wsgify(RequestClass=wsgi.Request) + def __call__(self, req): + try: + return req.get_response(self.application) + except Exception as ex: + LOG.exception(_("Caught error: %s"), unicode(ex)) + exc = webob.exc.HTTPInternalServerError() + return wsgi.Fault(exc) + + +class APIMapper(routes.Mapper): + def routematch(self, url=None, environ=None): + if url is "": + result = self._match("", environ) + return result[0], result[1] + return routes.Mapper.routematch(self, url, environ) + + +class ProjectMapper(APIMapper): + + def resource(self, member_name, collection_name, **kwargs): + if not ('parent_resource' in kwargs): + kwargs['path_prefix'] = '{project_id}/' + else: + parent_resource = kwargs['parent_resource'] + p_collection = parent_resource['collection_name'] + p_member = parent_resource['member_name'] + kwargs['path_prefix'] = '{project_id}/%s/:%s_id' % (p_collection, + p_member) + routes.Mapper.resource(self, member_name, + collection_name, + **kwargs) + + +class APIRouter(base_wsgi.Router): + """ + Routes requests on the OpenStack API to the appropriate controller + and method. + """ + + @classmethod + def factory(cls, global_config, **local_config): + """Simple paste factory, :class:`nova.wsgi.Router` doesn't have one""" + return cls() + + def __init__(self, ext_mgr=None): + self.server_members = {} + mapper = ProjectMapper() + self._setup_routes(mapper) + super(APIRouter, self).__init__(mapper) + + def _setup_routes(self, mapper): + server_members = self.server_members + server_members['action'] = 'POST' + if FLAGS.allow_admin_api: + LOG.debug(_("Including admin operations in API.")) + + server_members['diagnostics'] = 'GET' + server_members['actions'] = 'GET' + + mapper.resource("user", "users", + controller=users.create_resource(), + collection={'detail': 'GET'}) + + mapper.resource("account", "accounts", + controller=accounts.create_resource(), + collection={'detail': 'GET'}) + + mapper.resource("zone", "zones", + controller=zones.create_resource(), + collection={'detail': 'GET', + 'info': 'GET', + 'select': 'POST'}) + + mapper.connect("versions", "/", + controller=versions.create_resource(), + action='show') + + mapper.redirect("", "/") + + mapper.resource("console", "consoles", + controller=consoles.create_resource(), + parent_resource=dict(member_name='server', + collection_name='servers')) + + mapper.resource("server", "servers", + controller=servers.create_resource(), + collection={'detail': 'GET'}, + member=self.server_members) + + mapper.resource("ip", "ips", controller=ips.create_resource(), + parent_resource=dict(member_name='server', + collection_name='servers')) + + mapper.resource("image", "images", + controller=images.create_resource(), + collection={'detail': 'GET'}) + + mapper.resource("limit", "limits", + controller=limits.create_resource()) + + mapper.resource("flavor", "flavors", + controller=flavors.create_resource(), + collection={'detail': 'GET'}) + + image_metadata_controller = image_metadata.create_resource() + + mapper.resource("image_meta", "metadata", + controller=image_metadata_controller, + parent_resource=dict(member_name='image', + collection_name='images')) + + mapper.connect("metadata", "/{project_id}/images/{image_id}/metadata", + controller=image_metadata_controller, + action='update_all', + conditions={"method": ['PUT']}) + + server_metadata_controller = server_metadata.create_resource() + + mapper.resource("server_meta", "metadata", + controller=server_metadata_controller, + parent_resource=dict(member_name='server', + collection_name='servers')) + + mapper.connect("metadata", + "/{project_id}/servers/{server_id}/metadata", + controller=server_metadata_controller, + action='update_all', + conditions={"method": ['PUT']}) diff --git a/nova/api/openstack/accounts.py b/nova/api/openstack/v2/accounts.py similarity index 97% rename from nova/api/openstack/accounts.py rename to nova/api/openstack/v2/accounts.py index 3a19d5c893..0f15842611 100644 --- a/nova/api/openstack/accounts.py +++ b/nova/api/openstack/v2/accounts.py @@ -15,18 +15,16 @@ import webob.exc +from nova.api.openstack import wsgi +from nova.api.openstack import xmlutil +from nova.auth import manager from nova import exception from nova import flags from nova import log as logging -from nova.auth import manager -from nova.api.openstack import faults -from nova.api.openstack import wsgi -from nova.api.openstack import xmlutil - FLAGS = flags.FLAGS -LOG = logging.getLogger('nova.api.openstack') +LOG = logging.getLogger('nova.api.openstack.v2.accounts') def _translate_keys(account): diff --git a/nova/api/openstack/auth.py b/nova/api/openstack/v2/auth.py similarity index 92% rename from nova/api/openstack/auth.py rename to nova/api/openstack/v2/auth.py index d435f8318f..c0ea30671b 100644 --- a/nova/api/openstack/auth.py +++ b/nova/api/openstack/v2/auth.py @@ -19,25 +19,25 @@ import hashlib import os import time -import webob.exc import webob.dec +import webob.exc +from nova.api.openstack import common +from nova.api.openstack import wsgi from nova import auth from nova import context from nova import exception from nova import flags from nova import log as logging from nova import utils -from nova import wsgi -from nova.api.openstack import common -from nova.api.openstack import faults +from nova import wsgi as base_wsgi -LOG = logging.getLogger('nova.api.openstack') +LOG = logging.getLogger('nova.api.openstack.v2.auth') FLAGS = flags.FLAGS flags.DECLARE('use_forwarded_for', 'nova.api.auth') -class NoAuthMiddleware(wsgi.Middleware): +class NoAuthMiddleware(base_wsgi.Middleware): """Return a fake token if one isn't specified.""" @webob.dec.wsgify(RequestClass=wsgi.Request) @@ -73,7 +73,7 @@ class NoAuthMiddleware(wsgi.Middleware): return self.application -class AuthMiddleware(wsgi.Middleware): +class AuthMiddleware(base_wsgi.Middleware): """Authorize the openstack API request or return an HTTP Forbidden.""" def __init__(self, application, db_driver=None): @@ -92,12 +92,12 @@ class AuthMiddleware(wsgi.Middleware): token = req.headers["X-Auth-Token"] msg = _("%(user_id)s could not be found with token '%(token)s'") LOG.warn(msg % locals()) - return faults.Fault(webob.exc.HTTPUnauthorized()) + return wsgi.Fault(webob.exc.HTTPUnauthorized()) # Get all valid projects for the user projects = self.auth.get_projects(user_id) if not projects: - return faults.Fault(webob.exc.HTTPUnauthorized()) + return wsgi.Fault(webob.exc.HTTPUnauthorized()) project_id = "" path_parts = req.path.split('/') @@ -110,9 +110,9 @@ class AuthMiddleware(wsgi.Middleware): try: project = self.auth.get_project(project_id) except exception.ProjectNotFound: - return faults.Fault(webob.exc.HTTPUnauthorized()) + return wsgi.Fault(webob.exc.HTTPUnauthorized()) if project_id not in [p.id for p in projects]: - return faults.Fault(webob.exc.HTTPUnauthorized()) + return wsgi.Fault(webob.exc.HTTPUnauthorized()) else: # As a fallback, set project_id from the headers, which is the v1.0 # behavior. As a last resort, be forgiving to the user and set @@ -137,7 +137,7 @@ class AuthMiddleware(wsgi.Middleware): msg = _("%(user_id)s must be an admin or a " "member of %(project_id)s") LOG.warn(msg % locals()) - return faults.Fault(webob.exc.HTTPUnauthorized()) + return wsgi.Fault(webob.exc.HTTPUnauthorized()) return self.application @@ -155,7 +155,7 @@ class AuthMiddleware(wsgi.Middleware): msg = _("Authentication requests must be made against a version " "root (e.g. /v1.0 or /v1.1).") LOG.warn(msg) - return faults.Fault(webob.exc.HTTPUnauthorized(explanation=msg)) + return wsgi.Fault(webob.exc.HTTPUnauthorized(explanation=msg)) def _get_auth_header(key): """Ensures that the KeyError returned is meaningful.""" @@ -169,7 +169,7 @@ class AuthMiddleware(wsgi.Middleware): except KeyError as ex: msg = _("Could not find %s in request.") % ex LOG.warn(msg) - return faults.Fault(webob.exc.HTTPUnauthorized(explanation=msg)) + return wsgi.Fault(webob.exc.HTTPUnauthorized(explanation=msg)) token, user = self._authorize_user(username, key, req) if user and token: @@ -184,7 +184,7 @@ class AuthMiddleware(wsgi.Middleware): LOG.debug(_("Successfully authenticated '%s'") % username) return res else: - return faults.Fault(webob.exc.HTTPUnauthorized()) + return wsgi.Fault(webob.exc.HTTPUnauthorized()) def authorize_token(self, token_hash): """ retrieves user information from the datastore given a token diff --git a/nova/api/openstack/consoles.py b/nova/api/openstack/v2/consoles.py similarity index 100% rename from nova/api/openstack/consoles.py rename to nova/api/openstack/v2/consoles.py index 7d8c0523e6..ad0d8cbb46 100644 --- a/nova/api/openstack/consoles.py +++ b/nova/api/openstack/v2/consoles.py @@ -15,13 +15,13 @@ # License for the specific language governing permissions and limitations # under the License. -from webob import exc import webob +from webob import exc -from nova import console -from nova import exception from nova.api.openstack import wsgi from nova.api.openstack import xmlutil +from nova import console +from nova import exception def _translate_keys(cons): diff --git a/nova/api/openstack/contrib/__init__.py b/nova/api/openstack/v2/contrib/__init__.py similarity index 98% rename from nova/api/openstack/contrib/__init__.py rename to nova/api/openstack/v2/contrib/__init__.py index b3d4df69bb..d361dac9c0 100644 --- a/nova/api/openstack/contrib/__init__.py +++ b/nova/api/openstack/v2/contrib/__init__.py @@ -28,7 +28,7 @@ from nova import log as logging from nova import utils -LOG = logging.getLogger('nova.api.openstack.contrib') +LOG = logging.getLogger('nova.api.openstack.v2.contrib') def standard_extensions(ext_mgr): diff --git a/nova/api/openstack/contrib/admin_actions.py b/nova/api/openstack/v2/contrib/admin_actions.py similarity index 98% rename from nova/api/openstack/contrib/admin_actions.py rename to nova/api/openstack/v2/contrib/admin_actions.py index 81b23a8a07..632a8dc0e5 100644 --- a/nova/api/openstack/contrib/admin_actions.py +++ b/nova/api/openstack/v2/contrib/admin_actions.py @@ -19,16 +19,16 @@ import traceback import webob from webob import exc +from nova.api.openstack.v2 import extensions from nova import compute from nova import exception from nova import flags from nova import log as logging -from nova.api.openstack import extensions from nova.scheduler import api as scheduler_api FLAGS = flags.FLAGS -LOG = logging.getLogger("nova.api.openstack.contrib.admin_actions") +LOG = logging.getLogger("nova.api.openstack.v2.contrib.admin_actions") class Admin_actions(extensions.ExtensionDescriptor): diff --git a/nova/api/openstack/contrib/createserverext.py b/nova/api/openstack/v2/contrib/createserverext.py similarity index 95% rename from nova/api/openstack/contrib/createserverext.py rename to nova/api/openstack/v2/contrib/createserverext.py index 4e6556f5d2..a207d1bc5a 100644 --- a/nova/api/openstack/contrib/createserverext.py +++ b/nova/api/openstack/v2/contrib/createserverext.py @@ -14,9 +14,9 @@ # License for the specific language governing permissions and limitations # under the License -from nova.api.openstack import extensions -from nova.api.openstack import servers -from nova.api.openstack import views +from nova.api.openstack.v2 import extensions +from nova.api.openstack.v2 import servers +from nova.api.openstack.v2 import views from nova.api.openstack import wsgi diff --git a/nova/api/openstack/contrib/deferred_delete.py b/nova/api/openstack/v2/contrib/deferred_delete.py similarity index 93% rename from nova/api/openstack/contrib/deferred_delete.py rename to nova/api/openstack/v2/contrib/deferred_delete.py index 8415ca4b32..95eb8f42c0 100644 --- a/nova/api/openstack/contrib/deferred_delete.py +++ b/nova/api/openstack/v2/contrib/deferred_delete.py @@ -17,13 +17,13 @@ import webob +from nova.api.openstack.v2 import extensions +from nova.api.openstack.v2 import servers from nova import compute from nova import log as logging -from nova.api.openstack import extensions -from nova.api.openstack import servers -LOG = logging.getLogger("nova.api.contrib.deferred-delete") +LOG = logging.getLogger("nova.api.openstack.v2.contrib.deferred-delete") class Deferred_delete(extensions.ExtensionDescriptor): diff --git a/nova/api/openstack/contrib/disk_config.py b/nova/api/openstack/v2/contrib/disk_config.py similarity index 98% rename from nova/api/openstack/contrib/disk_config.py rename to nova/api/openstack/v2/contrib/disk_config.py index 20da999a7f..6e26c1daad 100644 --- a/nova/api/openstack/contrib/disk_config.py +++ b/nova/api/openstack/v2/contrib/disk_config.py @@ -16,11 +16,11 @@ """Disk Config extension.""" -from webob import exc from xml.dom import minidom -from nova.api.openstack import extensions -from nova.api.openstack import servers +from webob import exc + +from nova.api.openstack.v2 import extensions from nova.api.openstack import xmlutil from nova import compute from nova import log as logging diff --git a/nova/api/openstack/contrib/extended_status.py b/nova/api/openstack/v2/contrib/extended_status.py similarity index 96% rename from nova/api/openstack/contrib/extended_status.py rename to nova/api/openstack/v2/contrib/extended_status.py index 625f3ab2bc..5e0a697801 100644 --- a/nova/api/openstack/contrib/extended_status.py +++ b/nova/api/openstack/v2/contrib/extended_status.py @@ -19,17 +19,16 @@ import traceback import webob from webob import exc +from nova.api.openstack.v2 import extensions +from nova.api.openstack import xmlutil from nova import compute from nova import exception from nova import flags from nova import log as logging -from nova.api.openstack import extensions -from nova.api.openstack import faults -from nova.api.openstack import xmlutil FLAGS = flags.FLAGS -LOG = logging.getLogger("nova.api.openstack.contrib.extendedstatus") +LOG = logging.getLogger("nova.api.openstack.v2.contrib.extendedstatus") class Extended_status(extensions.ExtensionDescriptor): diff --git a/nova/api/openstack/contrib/flavorextradata.py b/nova/api/openstack/v2/contrib/flavorextradata.py similarity index 96% rename from nova/api/openstack/contrib/flavorextradata.py rename to nova/api/openstack/v2/contrib/flavorextradata.py index f696d161b6..0b09380544 100644 --- a/nova/api/openstack/contrib/flavorextradata.py +++ b/nova/api/openstack/v2/contrib/flavorextradata.py @@ -1,3 +1,5 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + # Copyright 2011 Canonical Ltd. # All Rights Reserved. # @@ -22,7 +24,7 @@ attributes. This extension adds to that list: swap """ -from nova.api.openstack import extensions +from nova.api.openstack.v2 import extensions class Flavorextradata(extensions.ExtensionDescriptor): @@ -32,5 +34,3 @@ class Flavorextradata(extensions.ExtensionDescriptor): alias = "os-flavor-extra-data" namespace = "http://docs.openstack.org/ext/flavor_extra_data/api/v1.1" updated = "2011-09-14T00:00:00+00:00" - -# vim: tabstop=4 shiftwidth=4 softtabstop=4 diff --git a/nova/api/openstack/contrib/flavorextraspecs.py b/nova/api/openstack/v2/contrib/flavorextraspecs.py similarity index 98% rename from nova/api/openstack/contrib/flavorextraspecs.py rename to nova/api/openstack/v2/contrib/flavorextraspecs.py index d71e9cf8bd..bb38ea64e0 100644 --- a/nova/api/openstack/contrib/flavorextraspecs.py +++ b/nova/api/openstack/v2/contrib/flavorextraspecs.py @@ -19,10 +19,9 @@ from webob import exc +from nova.api.openstack.v2 import extensions from nova import db from nova import exception -from nova.api.openstack import extensions -from nova.api.openstack import wsgi class FlavorExtraSpecsController(object): diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/v2/contrib/floating_ips.py similarity index 98% rename from nova/api/openstack/contrib/floating_ips.py rename to nova/api/openstack/v2/contrib/floating_ips.py index b64251e530..9689eac48d 100644 --- a/nova/api/openstack/contrib/floating_ips.py +++ b/nova/api/openstack/v2/contrib/floating_ips.py @@ -15,17 +15,18 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License + import webob +from nova.api.openstack.v2 import extensions from nova import compute from nova import exception from nova import log as logging from nova import network from nova import rpc -from nova.api.openstack import extensions -LOG = logging.getLogger('nova.api.openstack.contrib.floating_ips') +LOG = logging.getLogger('nova.api.openstack.v2.contrib.floating_ips') def _translate_floating_ip_view(floating_ip): diff --git a/nova/api/openstack/contrib/hosts.py b/nova/api/openstack/v2/contrib/hosts.py similarity index 97% rename from nova/api/openstack/contrib/hosts.py rename to nova/api/openstack/v2/contrib/hosts.py index 736843c3dc..eb50745203 100644 --- a/nova/api/openstack/contrib/hosts.py +++ b/nova/api/openstack/v2/contrib/hosts.py @@ -17,17 +17,16 @@ import webob.exc +from nova.api.openstack import common +from nova.api.openstack.v2 import extensions from nova import compute from nova import exception from nova import flags from nova import log as logging -from nova.api.openstack import common -from nova.api.openstack import extensions -from nova.api.openstack import faults from nova.scheduler import api as scheduler_api -LOG = logging.getLogger("nova.api.hosts") +LOG = logging.getLogger("nova.api.openstack.v2.contrib.hosts") FLAGS = flags.FLAGS diff --git a/nova/api/openstack/contrib/keypairs.py b/nova/api/openstack/v2/contrib/keypairs.py similarity index 98% rename from nova/api/openstack/contrib/keypairs.py rename to nova/api/openstack/v2/contrib/keypairs.py index ee5cad530a..e57d400016 100644 --- a/nova/api/openstack/contrib/keypairs.py +++ b/nova/api/openstack/v2/contrib/keypairs.py @@ -24,10 +24,10 @@ import tempfile import webob from webob import exc +from nova.api.openstack.v2 import extensions from nova import crypto from nova import db from nova import exception -from nova.api.openstack import extensions class KeypairController(object): diff --git a/nova/api/openstack/contrib/multinic.py b/nova/api/openstack/v2/contrib/multinic.py similarity index 97% rename from nova/api/openstack/contrib/multinic.py rename to nova/api/openstack/v2/contrib/multinic.py index 26968646d8..561e246b5c 100644 --- a/nova/api/openstack/contrib/multinic.py +++ b/nova/api/openstack/v2/contrib/multinic.py @@ -18,13 +18,13 @@ import webob from webob import exc -from nova.api.openstack import extensions +from nova.api.openstack.v2 import extensions from nova import compute from nova import exception from nova import log as logging -LOG = logging.getLogger("nova.api.multinic") +LOG = logging.getLogger("nova.api.openstack.v2.contrib.multinic") # Note: The class name is as it has to be for this to be loaded as an diff --git a/nova/api/openstack/contrib/quotas.py b/nova/api/openstack/v2/contrib/quotas.py similarity index 98% rename from nova/api/openstack/contrib/quotas.py rename to nova/api/openstack/v2/contrib/quotas.py index 184b4d12fe..7ad426c44c 100644 --- a/nova/api/openstack/contrib/quotas.py +++ b/nova/api/openstack/v2/contrib/quotas.py @@ -17,10 +17,10 @@ import webob +from nova.api.openstack.v2 import extensions from nova import db from nova import exception from nova import quota -from nova.api.openstack import extensions class QuotaSetsController(object): diff --git a/nova/api/openstack/contrib/rescue.py b/nova/api/openstack/v2/contrib/rescue.py similarity index 94% rename from nova/api/openstack/contrib/rescue.py rename to nova/api/openstack/v2/contrib/rescue.py index d3f38b2009..b63bf9ec5d 100644 --- a/nova/api/openstack/contrib/rescue.py +++ b/nova/api/openstack/v2/contrib/rescue.py @@ -17,8 +17,7 @@ import webob from webob import exc -from nova.api.openstack import extensions as exts -from nova.api.openstack import faults +from nova.api.openstack.v2 import extensions as exts from nova import compute from nova import exception from nova import flags @@ -27,7 +26,7 @@ from nova import utils FLAGS = flags.FLAGS -LOG = logging.getLogger("nova.api.contrib.rescue") +LOG = logging.getLogger("nova.api.openstack.v2.contrib.rescue") class Rescue(exts.ExtensionDescriptor): diff --git a/nova/api/openstack/contrib/security_groups.py b/nova/api/openstack/v2/contrib/security_groups.py similarity index 99% rename from nova/api/openstack/contrib/security_groups.py rename to nova/api/openstack/v2/contrib/security_groups.py index fd11876290..50f129bd61 100644 --- a/nova/api/openstack/contrib/security_groups.py +++ b/nova/api/openstack/v2/contrib/security_groups.py @@ -16,25 +16,23 @@ """The security groups extension.""" import urllib +from xml.dom import minidom + from webob import exc import webob +from nova.api.openstack import common +from nova.api.openstack.v2 import extensions +from nova.api.openstack import wsgi from nova import compute from nova import db from nova import exception from nova import flags from nova import log as logging -from nova import rpc from nova import utils -from nova.api.openstack import common -from nova.api.openstack import extensions -from nova.api.openstack import wsgi -from nova.compute import power_state - -from xml.dom import minidom -LOG = logging.getLogger("nova.api.contrib.security_groups") +LOG = logging.getLogger("nova.api.openstack.v2.contrib.security_groups") FLAGS = flags.FLAGS diff --git a/nova/api/openstack/contrib/simple_tenant_usage.py b/nova/api/openstack/v2/contrib/simple_tenant_usage.py similarity index 99% rename from nova/api/openstack/contrib/simple_tenant_usage.py rename to nova/api/openstack/v2/contrib/simple_tenant_usage.py index 3399ac2be5..e896371ed0 100644 --- a/nova/api/openstack/contrib/simple_tenant_usage.py +++ b/nova/api/openstack/v2/contrib/simple_tenant_usage.py @@ -15,17 +15,18 @@ # License for the specific language governing permissions and limitations # under the License. -import urlparse -import webob - from datetime import datetime +import urlparse + +import webob +from webob import exc + +from nova.api.openstack.v2 import extensions +from nova.api.openstack.v2 import views +from nova.compute import api +from nova.db.sqlalchemy.session import get_session from nova import exception from nova import flags -from nova.compute import api -from nova.api.openstack import extensions -from nova.api.openstack import views -from nova.db.sqlalchemy.session import get_session -from webob import exc FLAGS = flags.FLAGS diff --git a/nova/api/openstack/contrib/virtual_interfaces.py b/nova/api/openstack/v2/contrib/virtual_interfaces.py similarity index 96% rename from nova/api/openstack/contrib/virtual_interfaces.py rename to nova/api/openstack/v2/contrib/virtual_interfaces.py index 0afd2119d8..1975a8dc0c 100644 --- a/nova/api/openstack/contrib/virtual_interfaces.py +++ b/nova/api/openstack/v2/contrib/virtual_interfaces.py @@ -15,14 +15,14 @@ """The virtual interfaces extension.""" +from nova.api.openstack import common +from nova.api.openstack.v2 import extensions +from nova.api.openstack import wsgi from nova import log as logging from nova import network -from nova.api.openstack import common -from nova.api.openstack import extensions -from nova.api.openstack import wsgi -LOG = logging.getLogger("nova.api.virtual_interfaces") +LOG = logging.getLogger("nova.api.openstack.v2.contrib.virtual_interfaces") def _translate_vif_summary_view(_context, vif): diff --git a/nova/api/openstack/contrib/virtual_storage_arrays.py b/nova/api/openstack/v2/contrib/virtual_storage_arrays.py similarity index 99% rename from nova/api/openstack/contrib/virtual_storage_arrays.py rename to nova/api/openstack/v2/contrib/virtual_storage_arrays.py index a6bf72960c..f3a7831d54 100644 --- a/nova/api/openstack/contrib/virtual_storage_arrays.py +++ b/nova/api/openstack/v2/contrib/virtual_storage_arrays.py @@ -21,25 +21,25 @@ import webob from webob import exc -from nova import vsa -from nova import volume +from nova.api.openstack import common +from nova.api.openstack.v2.contrib import volumes +from nova.api.openstack.v2 import extensions +from nova.api.openstack.v2 import servers +from nova.api.openstack import wsgi from nova import compute +from nova.compute import instance_types from nova import network from nova import db from nova import quota from nova import exception -from nova import log as logging -from nova.api.openstack import common -from nova.api.openstack import extensions -from nova.api.openstack import wsgi -from nova.api.openstack import servers -from nova.api.openstack.contrib import volumes -from nova.compute import instance_types - from nova import flags +from nova import log as logging +from nova import vsa +from nova import volume + FLAGS = flags.FLAGS -LOG = logging.getLogger("nova.api.vsa") +LOG = logging.getLogger("nova.api.openstack.v2.contrib.vsa") def _vsa_view(context, vsa, details=False, instances=None): diff --git a/nova/api/openstack/contrib/volumes.py b/nova/api/openstack/v2/contrib/volumes.py similarity index 98% rename from nova/api/openstack/contrib/volumes.py rename to nova/api/openstack/v2/contrib/volumes.py index 917cfc61bb..5d86282f21 100644 --- a/nova/api/openstack/contrib/volumes.py +++ b/nova/api/openstack/v2/contrib/volumes.py @@ -18,6 +18,9 @@ from webob import exc import webob +from nova.api.openstack import common +from nova.api.openstack.v2 import extensions +from nova.api.openstack.v2 import servers from nova import compute from nova import db from nova import exception @@ -26,12 +29,9 @@ from nova import log as logging from nova import quota from nova import volume from nova.volume import volume_types -from nova.api.openstack import common -from nova.api.openstack import extensions -from nova.api.openstack import servers -LOG = logging.getLogger("nova.api.volumes") +LOG = logging.getLogger("nova.api.openstack.v2.contrib.volumes") FLAGS = flags.FLAGS diff --git a/nova/api/openstack/contrib/volumetypes.py b/nova/api/openstack/v2/contrib/volumetypes.py similarity index 99% rename from nova/api/openstack/contrib/volumetypes.py rename to nova/api/openstack/v2/contrib/volumetypes.py index 64a9e0f025..ca3866c99a 100644 --- a/nova/api/openstack/contrib/volumetypes.py +++ b/nova/api/openstack/v2/contrib/volumetypes.py @@ -19,11 +19,11 @@ from webob import exc +from nova.api.openstack.v2 import extensions +from nova.api.openstack import wsgi from nova import db from nova import exception from nova.volume import volume_types -from nova.api.openstack import extensions -from nova.api.openstack import wsgi class VolumeTypesController(object): diff --git a/nova/api/openstack/contrib/zones.py b/nova/api/openstack/v2/contrib/zones.py similarity index 92% rename from nova/api/openstack/contrib/zones.py rename to nova/api/openstack/v2/contrib/zones.py index 628b8182fa..76a2357132 100644 --- a/nova/api/openstack/contrib/zones.py +++ b/nova/api/openstack/v2/contrib/zones.py @@ -20,10 +20,10 @@ from nova import flags from nova import log as logging -from nova.api.openstack import extensions +from nova.api.openstack.v2 import extensions -LOG = logging.getLogger("nova.api.zones") +LOG = logging.getLogger("nova.api.openstack.v2.contrib.zones") FLAGS = flags.FLAGS diff --git a/nova/api/openstack/extensions.py b/nova/api/openstack/v2/extensions.py similarity index 99% rename from nova/api/openstack/extensions.py rename to nova/api/openstack/v2/extensions.py index 7da10513e4..a5cf863ed4 100644 --- a/nova/api/openstack/extensions.py +++ b/nova/api/openstack/v2/extensions.py @@ -27,18 +27,18 @@ import routes import webob.dec import webob.exc +import nova.api.openstack.v2 +from nova.api.openstack import common +from nova.api.openstack import wsgi +from nova.api.openstack import xmlutil from nova import exception from nova import flags from nova import log as logging from nova import utils from nova import wsgi as base_wsgi -import nova.api.openstack -from nova.api.openstack import common -from nova.api.openstack import wsgi -from nova.api.openstack import xmlutil -LOG = logging.getLogger('nova.api.openstack.extensions') +LOG = logging.getLogger('nova.api.openstack.v2.extensions') FLAGS = flags.FLAGS @@ -273,7 +273,7 @@ class ExtensionMiddleware(base_wsgi.Middleware): ext_mgr = ExtensionManager() self.ext_mgr = ext_mgr - mapper = nova.api.openstack.ProjectMapper() + mapper = nova.api.openstack.v2.ProjectMapper() serializer = wsgi.ResponseSerializer( {'application/xml': ExtensionsXMLSerializer()}) diff --git a/nova/api/openstack/flavors.py b/nova/api/openstack/v2/flavors.py similarity index 98% rename from nova/api/openstack/flavors.py rename to nova/api/openstack/v2/flavors.py index 7680ef1cae..d5b673c7f4 100644 --- a/nova/api/openstack/flavors.py +++ b/nova/api/openstack/v2/flavors.py @@ -15,10 +15,10 @@ # License for the specific language governing permissions and limitations # under the License. -import webob from lxml import etree +import webob -from nova.api.openstack.views import flavors as flavors_view +from nova.api.openstack.v2.views import flavors as flavors_view from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova.compute import instance_types diff --git a/nova/api/openstack/image_metadata.py b/nova/api/openstack/v2/image_metadata.py similarity index 100% rename from nova/api/openstack/image_metadata.py rename to nova/api/openstack/v2/image_metadata.py index adb6bee4bd..e3cfac4e01 100644 --- a/nova/api/openstack/image_metadata.py +++ b/nova/api/openstack/v2/image_metadata.py @@ -17,12 +17,12 @@ from webob import exc +from nova.api.openstack import common +from nova.api.openstack import wsgi from nova import exception from nova import flags from nova import image from nova import utils -from nova.api.openstack import common -from nova.api.openstack import wsgi FLAGS = flags.FLAGS diff --git a/nova/api/openstack/images.py b/nova/api/openstack/v2/images.py similarity index 97% rename from nova/api/openstack/images.py rename to nova/api/openstack/v2/images.py index f3ef63b49a..84b7b17db5 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/v2/images.py @@ -18,20 +18,18 @@ import os.path from lxml import etree import webob.exc +from nova.api.openstack import common +from nova.api.openstack.v2.views import images as views_images +from nova.api.openstack import wsgi +from nova.api.openstack import xmlutil from nova import compute from nova import exception from nova import flags import nova.image from nova import log -from nova.api.openstack import common -from nova.api.openstack import image_metadata -from nova.api.openstack import servers -from nova.api.openstack import wsgi -from nova.api.openstack import xmlutil -from nova.api.openstack.views import images as views_images -LOG = log.getLogger('nova.api.openstack.images') +LOG = log.getLogger('nova.api.openstack.v2.images') FLAGS = flags.FLAGS SUPPORTED_FILTERS = { diff --git a/nova/api/openstack/ips.py b/nova/api/openstack/v2/ips.py similarity index 96% rename from nova/api/openstack/ips.py rename to nova/api/openstack/v2/ips.py index 2bef453a29..7057546650 100644 --- a/nova/api/openstack/ips.py +++ b/nova/api/openstack/v2/ips.py @@ -16,19 +16,18 @@ # under the License. from lxml import etree - from webob import exc import nova from nova.api.openstack import common +from nova.api.openstack.v2.views import addresses as view_addresses from nova.api.openstack import wsgi from nova.api.openstack import xmlutil -from nova.api.openstack.views import addresses as view_addresses from nova import log as logging from nova import flags -LOG = logging.getLogger('nova.api.openstack.ips') +LOG = logging.getLogger('nova.api.openstack.v2.ips') FLAGS = flags.FLAGS diff --git a/nova/api/openstack/limits.py b/nova/api/openstack/v2/limits.py similarity index 98% rename from nova/api/openstack/limits.py rename to nova/api/openstack/v2/limits.py index 56e8395268..04ff9e647f 100644 --- a/nova/api/openstack/limits.py +++ b/nova/api/openstack/v2/limits.py @@ -17,28 +17,26 @@ Module dedicated functions/classes dealing with rate limiting requests. """ +from collections import defaultdict import copy import httplib import json -from lxml import etree import math import re import time import urllib + +from lxml import etree +from webob.dec import wsgify import webob.exc -from collections import defaultdict - -from webob.dec import wsgify - +from nova.api.openstack import common +from nova.api.openstack.v2.views import limits as limits_views +from nova.api.openstack import wsgi +from nova.api.openstack import xmlutil from nova import quota from nova import utils from nova import wsgi as base_wsgi -from nova.api.openstack import common -from nova.api.openstack import faults -from nova.api.openstack.views import limits as limits_views -from nova.api.openstack import wsgi -from nova.api.openstack import xmlutil # Convenience constants for the limits dictionary passed to Limiter(). @@ -275,7 +273,7 @@ class RateLimitingMiddleware(base_wsgi.Middleware): if delay: msg = _("This request was rate-limited.") retry = time.time() + delay - return faults.OverLimitFault(msg, error, retry) + return wsgi.OverLimitFault(msg, error, retry) req.environ["nova.limits"] = self._limiter.get_limits(username) diff --git a/nova/api/openstack/ratelimiting/__init__.py b/nova/api/openstack/v2/ratelimiting/__init__.py similarity index 99% rename from nova/api/openstack/ratelimiting/__init__.py rename to nova/api/openstack/v2/ratelimiting/__init__.py index 9ede548c2a..78dc465a7d 100644 --- a/nova/api/openstack/ratelimiting/__init__.py +++ b/nova/api/openstack/v2/ratelimiting/__init__.py @@ -20,11 +20,12 @@ import httplib import time import urllib + import webob.dec import webob.exc from nova import wsgi -from nova.api.openstack import faults +from nova.api.openstack import wsgi as os_wsgi # Convenience constants for the limits dictionary passed to Limiter(). PER_SECOND = 1 @@ -83,7 +84,7 @@ class RateLimitingMiddleware(wsgi.Middleware): exc = webob.exc.HTTPRequestEntityTooLarge( explanation=('Too many requests.'), headers={'Retry-After': time.time() + delay}) - raise faults.Fault(exc) + raise os_wsgi.Fault(exc) return application def get_delay(self, action_name, username): diff --git a/nova/api/openstack/schemas/atom-link.rng b/nova/api/openstack/v2/schemas/atom-link.rng similarity index 100% rename from nova/api/openstack/schemas/atom-link.rng rename to nova/api/openstack/v2/schemas/atom-link.rng diff --git a/nova/api/openstack/schemas/atom.rng b/nova/api/openstack/v2/schemas/atom.rng similarity index 100% rename from nova/api/openstack/schemas/atom.rng rename to nova/api/openstack/v2/schemas/atom.rng diff --git a/nova/api/openstack/schemas/v1.1/addresses.rng b/nova/api/openstack/v2/schemas/v1.1/addresses.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/addresses.rng rename to nova/api/openstack/v2/schemas/v1.1/addresses.rng diff --git a/nova/api/openstack/schemas/v1.1/extension.rng b/nova/api/openstack/v2/schemas/v1.1/extension.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/extension.rng rename to nova/api/openstack/v2/schemas/v1.1/extension.rng diff --git a/nova/api/openstack/schemas/v1.1/extensions.rng b/nova/api/openstack/v2/schemas/v1.1/extensions.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/extensions.rng rename to nova/api/openstack/v2/schemas/v1.1/extensions.rng diff --git a/nova/api/openstack/schemas/v1.1/flavor.rng b/nova/api/openstack/v2/schemas/v1.1/flavor.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/flavor.rng rename to nova/api/openstack/v2/schemas/v1.1/flavor.rng diff --git a/nova/api/openstack/schemas/v1.1/flavors.rng b/nova/api/openstack/v2/schemas/v1.1/flavors.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/flavors.rng rename to nova/api/openstack/v2/schemas/v1.1/flavors.rng diff --git a/nova/api/openstack/schemas/v1.1/flavors_index.rng b/nova/api/openstack/v2/schemas/v1.1/flavors_index.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/flavors_index.rng rename to nova/api/openstack/v2/schemas/v1.1/flavors_index.rng diff --git a/nova/api/openstack/schemas/v1.1/image.rng b/nova/api/openstack/v2/schemas/v1.1/image.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/image.rng rename to nova/api/openstack/v2/schemas/v1.1/image.rng diff --git a/nova/api/openstack/schemas/v1.1/images.rng b/nova/api/openstack/v2/schemas/v1.1/images.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/images.rng rename to nova/api/openstack/v2/schemas/v1.1/images.rng diff --git a/nova/api/openstack/schemas/v1.1/images_index.rng b/nova/api/openstack/v2/schemas/v1.1/images_index.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/images_index.rng rename to nova/api/openstack/v2/schemas/v1.1/images_index.rng diff --git a/nova/api/openstack/schemas/v1.1/limits.rng b/nova/api/openstack/v2/schemas/v1.1/limits.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/limits.rng rename to nova/api/openstack/v2/schemas/v1.1/limits.rng diff --git a/nova/api/openstack/schemas/v1.1/metadata.rng b/nova/api/openstack/v2/schemas/v1.1/metadata.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/metadata.rng rename to nova/api/openstack/v2/schemas/v1.1/metadata.rng diff --git a/nova/api/openstack/schemas/v1.1/server.rng b/nova/api/openstack/v2/schemas/v1.1/server.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/server.rng rename to nova/api/openstack/v2/schemas/v1.1/server.rng diff --git a/nova/api/openstack/schemas/v1.1/servers.rng b/nova/api/openstack/v2/schemas/v1.1/servers.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/servers.rng rename to nova/api/openstack/v2/schemas/v1.1/servers.rng diff --git a/nova/api/openstack/schemas/v1.1/servers_index.rng b/nova/api/openstack/v2/schemas/v1.1/servers_index.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/servers_index.rng rename to nova/api/openstack/v2/schemas/v1.1/servers_index.rng diff --git a/nova/api/openstack/schemas/v1.1/version.rng b/nova/api/openstack/v2/schemas/v1.1/version.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/version.rng rename to nova/api/openstack/v2/schemas/v1.1/version.rng diff --git a/nova/api/openstack/schemas/v1.1/versions.rng b/nova/api/openstack/v2/schemas/v1.1/versions.rng similarity index 100% rename from nova/api/openstack/schemas/v1.1/versions.rng rename to nova/api/openstack/v2/schemas/v1.1/versions.rng diff --git a/nova/api/openstack/server_metadata.py b/nova/api/openstack/v2/server_metadata.py similarity index 100% rename from nova/api/openstack/server_metadata.py rename to nova/api/openstack/v2/server_metadata.py index 4145898c1f..47dbe2fbda 100644 --- a/nova/api/openstack/server_metadata.py +++ b/nova/api/openstack/v2/server_metadata.py @@ -17,9 +17,9 @@ from webob import exc -from nova import compute from nova.api.openstack import common from nova.api.openstack import wsgi +from nova import compute from nova import exception diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/v2/servers.py similarity index 99% rename from nova/api/openstack/servers.py rename to nova/api/openstack/v2/servers.py index 8b11b30f64..1ae7f80bf0 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/v2/servers.py @@ -23,13 +23,12 @@ from webob import exc import webob from xml.dom import minidom -import nova.api.openstack from nova.api.openstack import common -from nova.api.openstack import ips -from nova.api.openstack.views import addresses as views_addresses -from nova.api.openstack.views import flavors as views_flavors -from nova.api.openstack.views import images as views_images -from nova.api.openstack.views import servers as views_servers +from nova.api.openstack.v2 import ips +from nova.api.openstack.v2.views import addresses as views_addresses +from nova.api.openstack.v2.views import flavors as views_flavors +from nova.api.openstack.v2.views import images as views_images +from nova.api.openstack.v2.views import servers as views_servers from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute @@ -45,7 +44,7 @@ from nova.scheduler import api as scheduler_api from nova import utils -LOG = logging.getLogger('nova.api.openstack.servers') +LOG = logging.getLogger('nova.api.openstack.v2.servers') FLAGS = flags.FLAGS diff --git a/nova/api/openstack/urlmap.py b/nova/api/openstack/v2/urlmap.py similarity index 99% rename from nova/api/openstack/urlmap.py rename to nova/api/openstack/v2/urlmap.py index 199fa6130f..bae69198e7 100644 --- a/nova/api/openstack/urlmap.py +++ b/nova/api/openstack/v2/urlmap.py @@ -28,7 +28,7 @@ _option_header_piece_re = re.compile(r';\s*([^\s;=]+|%s)\s*' r'(?:=\s*([^;]+|%s))?\s*' % (_quoted_string_re, _quoted_string_re)) -LOG = logging.getLogger('nova.api.openstack.map') +LOG = logging.getLogger('nova.api.openstack.v2.map') def unquote_header_value(value): diff --git a/nova/api/openstack/users.py b/nova/api/openstack/v2/users.py similarity index 98% rename from nova/api/openstack/users.py rename to nova/api/openstack/v2/users.py index 9fac457634..9dba79e03d 100644 --- a/nova/api/openstack/users.py +++ b/nova/api/openstack/v2/users.py @@ -15,17 +15,17 @@ from webob import exc -from nova import exception -from nova import flags -from nova import log as logging from nova.api.openstack import common from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova.auth import manager +from nova import exception +from nova import flags +from nova import log as logging FLAGS = flags.FLAGS -LOG = logging.getLogger('nova.api.openstack') +LOG = logging.getLogger('nova.api.openstack.users') def _translate_keys(user): diff --git a/nova/api/openstack/versions.py b/nova/api/openstack/v2/versions.py similarity index 97% rename from nova/api/openstack/versions.py rename to nova/api/openstack/v2/versions.py index 5461ffce21..3c3d4068ca 100644 --- a/nova/api/openstack/versions.py +++ b/nova/api/openstack/v2/versions.py @@ -16,11 +16,12 @@ # under the License. from datetime import datetime + from lxml import etree import webob import webob.dec -import nova.api.openstack.views.versions +from nova.api.openstack.v2.views import versions as views_versions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil @@ -84,7 +85,7 @@ class Versions(wsgi.Resource): def dispatch(self, request, *args): """Respond to a request for all OpenStack API versions.""" - builder = nova.api.openstack.views.versions.get_view_builder(request) + builder = views_versions.get_view_builder(request) if request.path == '/': # List Versions return builder.build_versions(VERSIONS) @@ -95,7 +96,7 @@ class Versions(wsgi.Resource): class VersionV11(object): def show(self, req): - builder = nova.api.openstack.views.versions.get_view_builder(req) + builder = views_versions.get_view_builder(req) return builder.build_version(VERSIONS['v1.1']) diff --git a/nova/api/openstack/views/__init__.py b/nova/api/openstack/v2/views/__init__.py similarity index 100% rename from nova/api/openstack/views/__init__.py rename to nova/api/openstack/v2/views/__init__.py diff --git a/nova/api/openstack/views/addresses.py b/nova/api/openstack/v2/views/addresses.py similarity index 96% rename from nova/api/openstack/views/addresses.py rename to nova/api/openstack/v2/views/addresses.py index 1dbcaffe07..6f518b11a3 100644 --- a/nova/api/openstack/views/addresses.py +++ b/nova/api/openstack/v2/views/addresses.py @@ -23,7 +23,7 @@ from nova import log as logging FLAGS = flags.FLAGS -LOG = logging.getLogger('nova.api.openstack.views.addresses') +LOG = logging.getLogger('nova.api.openstack.v2.views.addresses') class ViewBuilder(common.ViewBuilder): diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/v2/views/flavors.py similarity index 99% rename from nova/api/openstack/views/flavors.py rename to nova/api/openstack/v2/views/flavors.py index f84ae5987e..7b170a6b21 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/v2/views/flavors.py @@ -17,7 +17,6 @@ import os.path - from nova.api.openstack import common diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/v2/views/images.py similarity index 100% rename from nova/api/openstack/views/images.py rename to nova/api/openstack/v2/views/images.py diff --git a/nova/api/openstack/views/limits.py b/nova/api/openstack/v2/views/limits.py similarity index 100% rename from nova/api/openstack/views/limits.py rename to nova/api/openstack/v2/views/limits.py diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/v2/views/servers.py similarity index 95% rename from nova/api/openstack/views/servers.py rename to nova/api/openstack/v2/views/servers.py index e6f4bc2c4e..979be930fd 100644 --- a/nova/api/openstack/views/servers.py +++ b/nova/api/openstack/v2/views/servers.py @@ -17,19 +17,16 @@ # under the License. import hashlib -import os from nova.api.openstack import common -from nova.api.openstack.views import addresses as views_addresses -from nova.api.openstack.views import flavors as views_flavors -from nova.api.openstack.views import images as views_images -from nova.compute import vm_states -from nova import exception +from nova.api.openstack.v2.views import addresses as views_addresses +from nova.api.openstack.v2.views import flavors as views_flavors +from nova.api.openstack.v2.views import images as views_images from nova import log as logging from nova import utils -LOG = logging.getLogger('nova.api.openstack.views.servers') +LOG = logging.getLogger('nova.api.openstack.v2.views.servers') class ViewBuilder(common.ViewBuilder): diff --git a/nova/api/openstack/views/versions.py b/nova/api/openstack/v2/views/versions.py similarity index 100% rename from nova/api/openstack/views/versions.py rename to nova/api/openstack/v2/views/versions.py diff --git a/nova/api/openstack/zones.py b/nova/api/openstack/v2/zones.py similarity index 98% rename from nova/api/openstack/zones.py rename to nova/api/openstack/v2/zones.py index 2a95cd0a46..8c5add2d16 100644 --- a/nova/api/openstack/zones.py +++ b/nova/api/openstack/v2/zones.py @@ -16,25 +16,23 @@ import json import urlparse +from nova.api.openstack import common +from nova.api.openstack.v2 import servers +from nova.api.openstack import xmlutil +from nova.api.openstack import wsgi +from nova.compute import api as compute from nova import crypto from nova import db from nova import exception from nova import flags from nova import log as logging - -from nova.compute import api as compute from nova.scheduler import api -from nova.api.openstack import common -from nova.api.openstack import servers -from nova.api.openstack import xmlutil -from nova.api.openstack import wsgi - FLAGS = flags.FLAGS -LOG = logging.getLogger('nova.api.openstack.zones') +LOG = logging.getLogger('nova.api.openstack.v2.zones') def _filter_keys(item, keys): diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 8c6b30ca93..7e4875066f 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -15,13 +15,11 @@ # License for the specific language governing permissions and limitations # under the License. -import json from lxml import etree import webob from xml.dom import minidom from xml.parsers import expat -import faults from nova import exception from nova import log as logging from nova import utils @@ -528,7 +526,7 @@ class Resource(wsgi.Application): serialized by requested content type. Exceptions derived from webob.exc.HTTPException will be automatically - wrapped in faults.Fault() to provide API friendly error responses. + wrapped in Fault() to provide API friendly error responses. """ @@ -556,10 +554,10 @@ class Resource(wsgi.Application): action, args, accept = self.deserializer.deserialize(request) except exception.InvalidContentType: msg = _("Unsupported Content-Type") - return faults.Fault(webob.exc.HTTPBadRequest(explanation=msg)) + return Fault(webob.exc.HTTPBadRequest(explanation=msg)) except exception.MalformedRequestBody: msg = _("Malformed request body") - return faults.Fault(webob.exc.HTTPBadRequest(explanation=msg)) + return Fault(webob.exc.HTTPBadRequest(explanation=msg)) project_id = args.pop("project_id", None) if 'nova.context' in request.environ and project_id: @@ -567,12 +565,12 @@ class Resource(wsgi.Application): try: action_result = self.dispatch(request, action, args) - except faults.Fault as ex: + except Fault as ex: LOG.info(_("Fault thrown: %s"), unicode(ex)) action_result = ex except webob.exc.HTTPException as ex: LOG.info(_("HTTP exception thrown: %s"), unicode(ex)) - action_result = faults.Fault(ex) + action_result = Fault(ex) if type(action_result) is dict or action_result is None: response = self.serializer.serialize(request, @@ -601,7 +599,7 @@ class Resource(wsgi.Application): return controller_method(req=request, **action_args) except TypeError as exc: LOG.exception(exc) - return faults.Fault(webob.exc.HTTPBadRequest()) + return Fault(webob.exc.HTTPBadRequest()) class Controller(object): @@ -612,3 +610,96 @@ class Controller(object): def __init__(self, view_builder=None): """Initialize controller with a view builder instance.""" self._view_builder = view_builder or self._view_builder_class() + + +class Fault(webob.exc.HTTPException): + """Wrap webob.exc.HTTPException to provide API friendly response.""" + + _fault_names = { + 400: "badRequest", + 401: "unauthorized", + 403: "resizeNotAllowed", + 404: "itemNotFound", + 405: "badMethod", + 409: "inProgress", + 413: "overLimit", + 415: "badMediaType", + 501: "notImplemented", + 503: "serviceUnavailable"} + + def __init__(self, exception): + """Create a Fault for the given webob.exc.exception.""" + self.wrapped_exc = exception + self.status_int = exception.status_int + + @webob.dec.wsgify(RequestClass=Request) + def __call__(self, req): + """Generate a WSGI response based on the exception passed to ctor.""" + # Replace the body with fault details. + code = self.wrapped_exc.status_int + fault_name = self._fault_names.get(code, "cloudServersFault") + fault_data = { + fault_name: { + 'code': code, + 'message': self.wrapped_exc.explanation}} + if code == 413: + retry = self.wrapped_exc.headers['Retry-After'] + fault_data[fault_name]['retryAfter'] = retry + + # 'code' is an attribute on the fault tag itself + metadata = {'attributes': {fault_name: 'code'}} + + xml_serializer = XMLDictSerializer(metadata, XMLNS_V11) + + content_type = req.best_match_content_type() + serializer = { + 'application/xml': xml_serializer, + 'application/json': JSONDictSerializer(), + }[content_type] + + self.wrapped_exc.body = serializer.serialize(fault_data) + self.wrapped_exc.content_type = content_type + + return self.wrapped_exc + + def __str__(self): + return self.wrapped_exc.__str__() + + +class OverLimitFault(webob.exc.HTTPException): + """ + Rate-limited request response. + """ + + def __init__(self, message, details, retry_time): + """ + Initialize new `OverLimitFault` with relevant information. + """ + self.wrapped_exc = webob.exc.HTTPRequestEntityTooLarge() + self.content = { + "overLimitFault": { + "code": self.wrapped_exc.status_int, + "message": message, + "details": details, + }, + } + + @webob.dec.wsgify(RequestClass=Request) + def __call__(self, request): + """ + Return the wrapped exception with a serialized body conforming to our + error format. + """ + content_type = request.best_match_content_type() + metadata = {"attributes": {"overLimitFault": "code"}} + + xml_serializer = XMLDictSerializer(metadata, XMLNS_V11) + serializer = { + 'application/xml': xml_serializer, + 'application/json': JSONDictSerializer(), + }[content_type] + + content = serializer.serialize(self.content) + self.wrapped_exc.body = content + + return self.wrapped_exc diff --git a/nova/api/openstack/xmlutil.py b/nova/api/openstack/xmlutil.py index 5779849b3e..db490e652c 100644 --- a/nova/api/openstack/xmlutil.py +++ b/nova/api/openstack/xmlutil.py @@ -31,9 +31,9 @@ XMLNS_ATOM = 'http://www.w3.org/2005/Atom' def validate_schema(xml, schema_name): if type(xml) is str: xml = etree.fromstring(xml) - base_path = 'nova/api/openstack/schemas/v1.1/' + base_path = 'nova/api/openstack/v2/schemas/v1.1/' if schema_name in ('atom', 'atom-link'): - base_path = 'nova/api/openstack/schemas/' + base_path = 'nova/api/openstack/v2/schemas/' schema_path = os.path.join(utils.novadir(), '%s%s.rng' % (base_path, schema_name)) schema_doc = etree.parse(schema_path) diff --git a/nova/flags.py b/nova/flags.py index 32cec119f8..c47c77ab12 100644 --- a/nova/flags.py +++ b/nova/flags.py @@ -369,7 +369,7 @@ DEFINE_integer('ec2_port', 8773, 'cloud controller port') DEFINE_string('ec2_scheme', 'http', 'prefix for ec2') DEFINE_string('ec2_path', '/services/Cloud', 'suffix for ec2') DEFINE_multistring('osapi_extension', - ['nova.api.openstack.contrib.standard_extensions'], + ['nova.api.openstack.v2.contrib.standard_extensions'], 'osapi extension to load') DEFINE_string('osapi_host', '$my_ip', 'ip of api server') DEFINE_string('osapi_scheme', 'http', 'prefix for openstack') diff --git a/nova/tests/api/openstack/__init__.py b/nova/tests/api/openstack/__init__.py index 00fcfbb009..e69de29bb2 100644 --- a/nova/tests/api/openstack/__init__.py +++ b/nova/tests/api/openstack/__init__.py @@ -1,16 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2010 OpenStack LLC. -# 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. diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py index 0f58cf55bb..c12ae5eab6 100644 --- a/nova/tests/api/openstack/fakes.py +++ b/nova/tests/api/openstack/fakes.py @@ -23,25 +23,25 @@ import webob.request from glance import client as glance_client -from nova import context -from nova import exception as exc -from nova import utils -from nova import wsgi -import nova.api.openstack.auth -from nova.api import openstack +import nova.api.openstack.v2.auth from nova.api import auth as api_auth -from nova.api.openstack import auth -from nova.api.openstack import extensions -from nova.api.openstack import limits -from nova.api.openstack import urlmap -from nova.api.openstack import versions +from nova.api.openstack import v2 +from nova.api.openstack.v2 import auth +from nova.api.openstack.v2 import extensions +from nova.api.openstack.v2 import limits +from nova.api.openstack.v2 import urlmap +from nova.api.openstack.v2 import versions from nova.api.openstack import wsgi as os_wsgi from nova.auth.manager import User, Project from nova.compute import instance_types from nova.compute import vm_states +from nova import context from nova.db.sqlalchemy import models +from nova import exception as exc import nova.image.fake from nova.tests.glance import stubs as glance_stubs +from nova import utils +from nova import wsgi class Context(object): @@ -72,35 +72,36 @@ def fake_wsgi(self, req): return self.application -def wsgi_app(inner_app11=None, fake_auth=True, fake_auth_context=None, +def wsgi_app(inner_app_v2=None, fake_auth=True, fake_auth_context=None, serialization=os_wsgi.LazySerializationMiddleware, use_no_auth=False): - if not inner_app11: - inner_app11 = openstack.APIRouter() + if not inner_app_v2: + inner_app_v2 = v2.APIRouter() if fake_auth: if fake_auth_context is not None: ctxt = fake_auth_context else: ctxt = context.RequestContext('fake', 'fake', auth_token=True) - api11 = openstack.FaultWrapper(api_auth.InjectContext(ctxt, + api_v2 = v2.FaultWrapper(api_auth.InjectContext(ctxt, limits.RateLimitingMiddleware( serialization( - extensions.ExtensionMiddleware(inner_app11))))) + extensions.ExtensionMiddleware(inner_app_v2))))) elif use_no_auth: - api11 = openstack.FaultWrapper(auth.NoAuthMiddleware( + api_v2 = v2.FaultWrapper(auth.NoAuthMiddleware( limits.RateLimitingMiddleware( serialization( - extensions.ExtensionMiddleware(inner_app11))))) + extensions.ExtensionMiddleware(inner_app_v2))))) else: - api11 = openstack.FaultWrapper(auth.AuthMiddleware( + api_v2 = v2.FaultWrapper(auth.AuthMiddleware( limits.RateLimitingMiddleware( serialization( - extensions.ExtensionMiddleware(inner_app11))))) + extensions.ExtensionMiddleware(inner_app_v2))))) Auth = auth mapper = urlmap.URLMap() - mapper['/v1.1'] = api11 - mapper['/'] = openstack.FaultWrapper(versions.Versions()) + mapper['/v2'] = api_v2 + mapper['/v1.1'] = api_v2 + mapper['/'] = v2.FaultWrapper(versions.Versions()) return mapper @@ -136,9 +137,9 @@ def stub_out_auth(stubs): def fake_auth_init(self, app): self.application = app - stubs.Set(nova.api.openstack.auth.AuthMiddleware, + stubs.Set(nova.api.openstack.v2.auth.AuthMiddleware, '__init__', fake_auth_init) - stubs.Set(nova.api.openstack.auth.AuthMiddleware, + stubs.Set(nova.api.openstack.v2.auth.AuthMiddleware, '__call__', fake_wsgi) @@ -147,10 +148,10 @@ def stub_out_rate_limiting(stubs): super(limits.RateLimitingMiddleware, self).__init__(app) self.application = app - stubs.Set(nova.api.openstack.limits.RateLimitingMiddleware, + stubs.Set(nova.api.openstack.v2.limits.RateLimitingMiddleware, '__init__', fake_rate_init) - stubs.Set(nova.api.openstack.limits.RateLimitingMiddleware, + stubs.Set(nova.api.openstack.v2.limits.RateLimitingMiddleware, '__call__', fake_wsgi) diff --git a/nova/tests/api/openstack/test_faults.py b/nova/tests/api/openstack/test_faults.py index 18bd136dff..87cb2d3feb 100644 --- a/nova/tests/api/openstack/test_faults.py +++ b/nova/tests/api/openstack/test_faults.py @@ -24,7 +24,6 @@ import webob.exc from nova import test from nova.api.openstack import common -from nova.api.openstack import faults from nova.api.openstack import wsgi @@ -46,7 +45,7 @@ class TestFaults(test.TestCase): ] for request in requests: - fault = faults.Fault(webob.exc.HTTPBadRequest(explanation='scram')) + fault = wsgi.Fault(webob.exc.HTTPBadRequest(explanation='scram')) response = request.get_response(fault) expected = { @@ -69,7 +68,7 @@ class TestFaults(test.TestCase): for request in requests: exc = webob.exc.HTTPRequestEntityTooLarge - fault = faults.Fault(exc(explanation='sorry', + fault = wsgi.Fault(exc(explanation='sorry', headers={'Retry-After': 4})) response = request.get_response(fault) @@ -89,7 +88,7 @@ class TestFaults(test.TestCase): """Ensure the ability to raise `Fault`s in WSGI-ified methods.""" @webob.dec.wsgify def raiser(req): - raise faults.Fault(webob.exc.HTTPNotFound(explanation='whut?')) + raise wsgi.Fault(webob.exc.HTTPNotFound(explanation='whut?')) req = webob.Request.blank('/.xml') resp = req.get_response(raiser) @@ -99,7 +98,7 @@ class TestFaults(test.TestCase): def test_fault_has_status_int(self): """Ensure the status_int is set correctly on faults""" - fault = faults.Fault(webob.exc.HTTPBadRequest(explanation='what?')) + fault = wsgi.Fault(webob.exc.HTTPBadRequest(explanation='what?')) self.assertEqual(fault.status_int, 400) def test_xml_serializer(self): @@ -107,7 +106,7 @@ class TestFaults(test.TestCase): request = webob.Request.blank('/v1.1', headers={"Accept": "application/xml"}) - fault = faults.Fault(webob.exc.HTTPBadRequest(explanation='scram')) + fault = wsgi.Fault(webob.exc.HTTPBadRequest(explanation='scram')) response = request.get_response(fault) self.assertTrue(common.XML_NS_V11 in response.body) diff --git a/nova/tests/api/openstack/v2/__init__.py b/nova/tests/api/openstack/v2/__init__.py new file mode 100644 index 0000000000..00fcfbb009 --- /dev/null +++ b/nova/tests/api/openstack/v2/__init__.py @@ -0,0 +1,16 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 OpenStack LLC. +# 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. diff --git a/nova/tests/api/openstack/contrib/__init__.py b/nova/tests/api/openstack/v2/contrib/__init__.py similarity index 100% rename from nova/tests/api/openstack/contrib/__init__.py rename to nova/tests/api/openstack/v2/contrib/__init__.py diff --git a/nova/tests/api/openstack/contrib/test_admin_actions.py b/nova/tests/api/openstack/v2/contrib/test_admin_actions.py similarity index 100% rename from nova/tests/api/openstack/contrib/test_admin_actions.py rename to nova/tests/api/openstack/v2/contrib/test_admin_actions.py diff --git a/nova/tests/api/openstack/contrib/test_createserverext.py b/nova/tests/api/openstack/v2/contrib/test_createserverext.py similarity index 99% rename from nova/tests/api/openstack/contrib/test_createserverext.py rename to nova/tests/api/openstack/v2/contrib/test_createserverext.py index f7ee969177..5c9e0499ae 100644 --- a/nova/tests/api/openstack/contrib/test_createserverext.py +++ b/nova/tests/api/openstack/v2/contrib/test_createserverext.py @@ -22,12 +22,12 @@ from xml.dom import minidom import webob +import nova from nova import db from nova import exception from nova import flags from nova import rpc from nova import test -import nova.api.openstack from nova.tests.api.openstack import fakes diff --git a/nova/tests/api/openstack/contrib/test_disk_config.py b/nova/tests/api/openstack/v2/contrib/test_disk_config.py similarity index 98% rename from nova/tests/api/openstack/contrib/test_disk_config.py rename to nova/tests/api/openstack/v2/contrib/test_disk_config.py index 40875cb846..ac2391a046 100644 --- a/nova/tests/api/openstack/contrib/test_disk_config.py +++ b/nova/tests/api/openstack/v2/contrib/test_disk_config.py @@ -14,19 +14,19 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + import datetime -import nova.db.api -import nova.rpc - -from nova import flags -from nova import test -from nova import utils -from nova.api import openstack -from nova.api.openstack import extensions -from nova.api.openstack import servers +from nova.api.openstack import v2 +from nova.api.openstack.v2 import extensions from nova.api.openstack import wsgi +import nova.db.api +from nova import flags +import nova.rpc +from nova import test from nova.tests.api.openstack import fakes +from nova import utils + MANUAL_INSTANCE_UUID = fakes.FAKE_UUID AUTO_INSTANCE_UUID = fakes.FAKE_UUID.replace('a', 'b') @@ -113,7 +113,7 @@ class DiskConfigTestCase(test.TestCase): self.stubs.Set(nova.db, 'instance_create', fake_instance_create) - app = openstack.APIRouter() + app = v2.APIRouter() app = extensions.ExtensionMiddleware(app) app = wsgi.LazySerializationMiddleware(app) self.app = app diff --git a/nova/tests/api/openstack/contrib/test_extendedstatus.py b/nova/tests/api/openstack/v2/contrib/test_extendedstatus.py similarity index 99% rename from nova/tests/api/openstack/contrib/test_extendedstatus.py rename to nova/tests/api/openstack/v2/contrib/test_extendedstatus.py index 0065f6fdec..54246727cb 100644 --- a/nova/tests/api/openstack/contrib/test_extendedstatus.py +++ b/nova/tests/api/openstack/v2/contrib/test_extendedstatus.py @@ -14,6 +14,7 @@ # under the License. import json + import webob from nova import compute diff --git a/nova/tests/api/openstack/contrib/test_flavors_extra_specs.py b/nova/tests/api/openstack/v2/contrib/test_flavors_extra_specs.py similarity index 97% rename from nova/tests/api/openstack/contrib/test_flavors_extra_specs.py rename to nova/tests/api/openstack/v2/contrib/test_flavors_extra_specs.py index 5784743eec..5f9be886fe 100644 --- a/nova/tests/api/openstack/contrib/test_flavors_extra_specs.py +++ b/nova/tests/api/openstack/v2/contrib/test_flavors_extra_specs.py @@ -16,15 +16,14 @@ # under the License. import json -import stubout -import webob import os.path +import stubout +import webob +from nova.api.openstack.v2 import extensions +from nova.api.openstack.v2.contrib import flavorextraspecs from nova import test -from nova.api import openstack -from nova.api.openstack import extensions -from nova.api.openstack.contrib import flavorextraspecs from nova.tests.api.openstack import fakes import nova.wsgi diff --git a/nova/tests/api/openstack/contrib/test_floating_ips.py b/nova/tests/api/openstack/v2/contrib/test_floating_ips.py similarity index 96% rename from nova/tests/api/openstack/contrib/test_floating_ips.py rename to nova/tests/api/openstack/v2/contrib/test_floating_ips.py index 63831f31f5..ded3634065 100644 --- a/nova/tests/api/openstack/contrib/test_floating_ips.py +++ b/nova/tests/api/openstack/v2/contrib/test_floating_ips.py @@ -15,8 +15,11 @@ import json import stubout + import webob +from nova.api.openstack.v2.contrib import floating_ips +from nova.api.openstack.v2.contrib import floating_ips from nova import compute from nova import context from nova import db @@ -24,11 +27,7 @@ from nova import network from nova import rpc from nova import test from nova.tests.api.openstack import fakes -from nova.tests.api.openstack import test_servers - - -from nova.api.openstack.contrib import floating_ips -from nova.api.openstack.contrib.floating_ips import _translate_floating_ip_view +from nova.tests.api.openstack.v2 import test_servers def network_api_get_floating_ip(self, context, id): @@ -143,7 +142,7 @@ class FloatingIpTest(test.TestCase): floating_ip_address = self._create_floating_ip() floating_ip = db.floating_ip_get_by_address(self.context, floating_ip_address) - view = _translate_floating_ip_view(floating_ip) + view = floating_ips._translate_floating_ip_view(floating_ip) self.assertTrue('floating_ip' in view) self.assertTrue(view['floating_ip']['id']) self.assertEqual(view['floating_ip']['ip'], self.address) @@ -152,7 +151,7 @@ class FloatingIpTest(test.TestCase): def test_translate_floating_ip_view_dict(self): floating_ip = {'id': 0, 'address': '10.0.0.10', 'fixed_ip': None} - view = _translate_floating_ip_view(floating_ip) + view = floating_ips._translate_floating_ip_view(floating_ip) self.assertTrue('floating_ip' in view) def test_floating_ips_list(self): diff --git a/nova/tests/api/openstack/contrib/test_keypairs.py b/nova/tests/api/openstack/v2/contrib/test_keypairs.py similarity index 98% rename from nova/tests/api/openstack/contrib/test_keypairs.py rename to nova/tests/api/openstack/v2/contrib/test_keypairs.py index 92e401aac2..b2f595e5e8 100644 --- a/nova/tests/api/openstack/contrib/test_keypairs.py +++ b/nova/tests/api/openstack/v2/contrib/test_keypairs.py @@ -14,12 +14,13 @@ # under the License. import json + import webob +from nova.api.openstack.v2.contrib.keypairs import KeypairController from nova import context from nova import db from nova import test -from nova.api.openstack.contrib.keypairs import KeypairController from nova.tests.api.openstack import fakes diff --git a/nova/tests/api/openstack/contrib/test_multinic_xs.py b/nova/tests/api/openstack/v2/contrib/test_multinic_xs.py similarity index 99% rename from nova/tests/api/openstack/contrib/test_multinic_xs.py rename to nova/tests/api/openstack/v2/contrib/test_multinic_xs.py index 90999a3847..68f99d363f 100644 --- a/nova/tests/api/openstack/contrib/test_multinic_xs.py +++ b/nova/tests/api/openstack/v2/contrib/test_multinic_xs.py @@ -14,6 +14,7 @@ # under the License. import json + import stubout import webob diff --git a/nova/tests/api/openstack/contrib/test_quotas.py b/nova/tests/api/openstack/v2/contrib/test_quotas.py similarity index 98% rename from nova/tests/api/openstack/contrib/test_quotas.py rename to nova/tests/api/openstack/v2/contrib/test_quotas.py index 6374dfd933..15fb20f94a 100644 --- a/nova/tests/api/openstack/contrib/test_quotas.py +++ b/nova/tests/api/openstack/v2/contrib/test_quotas.py @@ -18,12 +18,11 @@ import json import webob +from nova.api.openstack.v2.contrib.quotas import QuotaSetsController from nova import context from nova import test from nova.tests.api.openstack import fakes -from nova.api.openstack.contrib.quotas import QuotaSetsController - def quota_set(id): return {'quota_set': {'id': id, 'metadata_items': 128, 'volumes': 10, diff --git a/nova/tests/api/openstack/contrib/test_rescue.py b/nova/tests/api/openstack/v2/contrib/test_rescue.py similarity index 99% rename from nova/tests/api/openstack/contrib/test_rescue.py rename to nova/tests/api/openstack/v2/contrib/test_rescue.py index f5b69865c2..9058d101e4 100644 --- a/nova/tests/api/openstack/contrib/test_rescue.py +++ b/nova/tests/api/openstack/v2/contrib/test_rescue.py @@ -13,6 +13,7 @@ # under the License. import json + import webob from nova import compute diff --git a/nova/tests/api/openstack/contrib/test_security_groups.py b/nova/tests/api/openstack/v2/contrib/test_security_groups.py similarity index 99% rename from nova/tests/api/openstack/contrib/test_security_groups.py rename to nova/tests/api/openstack/v2/contrib/test_security_groups.py index 1e7a439b03..fd4e0841d3 100644 --- a/nova/tests/api/openstack/contrib/test_security_groups.py +++ b/nova/tests/api/openstack/v2/contrib/test_security_groups.py @@ -15,15 +15,16 @@ # under the License. import json -import mox -import nova import unittest -import webob from xml.dom import minidom +import mox +import webob + +from nova.api.openstack.v2.contrib import security_groups +import nova.db from nova import exception from nova import test -from nova.api.openstack.contrib import security_groups from nova.tests.api.openstack import fakes diff --git a/nova/tests/api/openstack/contrib/test_simple_tenant_usage.py b/nova/tests/api/openstack/v2/contrib/test_simple_tenant_usage.py similarity index 100% rename from nova/tests/api/openstack/contrib/test_simple_tenant_usage.py rename to nova/tests/api/openstack/v2/contrib/test_simple_tenant_usage.py index 2430b9d51b..56e7be0d2c 100644 --- a/nova/tests/api/openstack/contrib/test_simple_tenant_usage.py +++ b/nova/tests/api/openstack/v2/contrib/test_simple_tenant_usage.py @@ -19,10 +19,10 @@ import datetime import json import webob +from nova.compute import api from nova import context from nova import flags from nova import test -from nova.compute import api from nova.tests.api.openstack import fakes diff --git a/nova/tests/api/openstack/contrib/test_virtual_interfaces.py b/nova/tests/api/openstack/v2/contrib/test_virtual_interfaces.py similarity index 97% rename from nova/tests/api/openstack/contrib/test_virtual_interfaces.py rename to nova/tests/api/openstack/v2/contrib/test_virtual_interfaces.py index 0e3b45c105..4285eaaaf7 100644 --- a/nova/tests/api/openstack/contrib/test_virtual_interfaces.py +++ b/nova/tests/api/openstack/v2/contrib/test_virtual_interfaces.py @@ -14,13 +14,14 @@ # under the License. import json + import webob -from nova import test -from nova import network -from nova.tests.api.openstack import fakes -from nova.api.openstack.contrib.virtual_interfaces import \ +from nova.api.openstack.v2.contrib.virtual_interfaces import \ ServerVirtualInterfaceController +from nova import network +from nova import test +from nova.tests.api.openstack import fakes def get_vifs_by_instance(self, context, server_id): diff --git a/nova/tests/api/openstack/contrib/test_volume_types.py b/nova/tests/api/openstack/v2/contrib/test_volume_types.py similarity index 97% rename from nova/tests/api/openstack/contrib/test_volume_types.py rename to nova/tests/api/openstack/v2/contrib/test_volume_types.py index ec1c44854a..9da77349db 100644 --- a/nova/tests/api/openstack/contrib/test_volume_types.py +++ b/nova/tests/api/openstack/v2/contrib/test_volume_types.py @@ -14,18 +14,20 @@ # under the License. import json + import stubout import webob +from nova.api.openstack.v2.contrib import volumetypes from nova import exception from nova import context from nova import test from nova import log as logging -from nova.api.openstack.contrib import volumetypes from nova.volume import volume_types from nova.tests.api.openstack import fakes -LOG = logging.getLogger('nova.tests.api.openstack.test_volume_types') +LOG = logging.getLogger('nova.tests.api.openstack.v2.contrib.' + 'test_volume_types') last_param = {} diff --git a/nova/tests/api/openstack/contrib/test_volume_types_extra_specs.py b/nova/tests/api/openstack/v2/contrib/test_volume_types_extra_specs.py similarity index 97% rename from nova/tests/api/openstack/contrib/test_volume_types_extra_specs.py rename to nova/tests/api/openstack/v2/contrib/test_volume_types_extra_specs.py index 796478838a..9083d9d722 100644 --- a/nova/tests/api/openstack/contrib/test_volume_types_extra_specs.py +++ b/nova/tests/api/openstack/v2/contrib/test_volume_types_extra_specs.py @@ -18,15 +18,14 @@ # under the License. import json -import stubout -import webob import os.path +import stubout +import webob +from nova.api.openstack.v2 import extensions +from nova.api.openstack.v2.contrib import volumetypes from nova import test -from nova.api import openstack -from nova.api.openstack import extensions -from nova.api.openstack.contrib import volumetypes from nova.tests.api.openstack import fakes import nova.wsgi diff --git a/nova/tests/api/openstack/contrib/test_volumes.py b/nova/tests/api/openstack/v2/contrib/test_volumes.py similarity index 99% rename from nova/tests/api/openstack/contrib/test_volumes.py rename to nova/tests/api/openstack/v2/contrib/test_volumes.py index a130d11404..529abf225b 100644 --- a/nova/tests/api/openstack/contrib/test_volumes.py +++ b/nova/tests/api/openstack/v2/contrib/test_volumes.py @@ -15,12 +15,13 @@ import datetime import json + import webob import nova +from nova.compute import instance_types from nova import flags from nova import test -from nova.compute import instance_types from nova.tests.api.openstack import fakes diff --git a/nova/tests/api/openstack/contrib/test_vsa.py b/nova/tests/api/openstack/v2/contrib/test_vsa.py similarity index 98% rename from nova/tests/api/openstack/contrib/test_vsa.py rename to nova/tests/api/openstack/v2/contrib/test_vsa.py index 6f6ea8e329..b4055a204c 100644 --- a/nova/tests/api/openstack/contrib/test_vsa.py +++ b/nova/tests/api/openstack/v2/contrib/test_vsa.py @@ -14,27 +14,26 @@ # under the License. import json -import stubout import unittest + +import stubout import webob +from nova.api.openstack.v2.contrib.virtual_storage_arrays import _vsa_view from nova import context -from nova import db +import nova.db from nova import exception from nova import flags from nova import log as logging from nova import test +from nova.tests.api.openstack import fakes from nova import volume from nova import vsa -from nova.api import openstack -from nova.tests.api.openstack import fakes -import nova.wsgi -from nova.api.openstack.contrib.virtual_storage_arrays import _vsa_view FLAGS = flags.FLAGS -LOG = logging.getLogger('nova.tests.api.openstack.vsa') +LOG = logging.getLogger('nova.tests.api.openstack.v2.contrib.test_vsa') last_param = {} diff --git a/nova/tests/api/openstack/extensions/__init__.py b/nova/tests/api/openstack/v2/extensions/__init__.py similarity index 100% rename from nova/tests/api/openstack/extensions/__init__.py rename to nova/tests/api/openstack/v2/extensions/__init__.py diff --git a/nova/tests/api/openstack/extensions/foxinsocks.py b/nova/tests/api/openstack/v2/extensions/foxinsocks.py similarity index 98% rename from nova/tests/api/openstack/extensions/foxinsocks.py rename to nova/tests/api/openstack/v2/extensions/foxinsocks.py index cbf101f473..05a9954961 100644 --- a/nova/tests/api/openstack/extensions/foxinsocks.py +++ b/nova/tests/api/openstack/v2/extensions/foxinsocks.py @@ -18,7 +18,7 @@ import json import webob.exc -from nova.api.openstack import extensions +from nova.api.openstack.v2 import extensions class FoxInSocksController(object): diff --git a/nova/tests/api/openstack/test_accounts.py b/nova/tests/api/openstack/v2/test_accounts.py similarity index 99% rename from nova/tests/api/openstack/test_accounts.py rename to nova/tests/api/openstack/v2/test_accounts.py index ea96e1348d..ab3ecafde7 100644 --- a/nova/tests/api/openstack/test_accounts.py +++ b/nova/tests/api/openstack/v2/test_accounts.py @@ -20,7 +20,7 @@ from lxml import etree import webob from nova import test -from nova.api.openstack import accounts +from nova.api.openstack.v2 import accounts from nova.auth.manager import User from nova.tests.api.openstack import fakes diff --git a/nova/tests/api/openstack/test_api.py b/nova/tests/api/openstack/v2/test_api.py similarity index 96% rename from nova/tests/api/openstack/test_api.py rename to nova/tests/api/openstack/v2/test_api.py index b7a0b01efc..318c03a883 100644 --- a/nova/tests/api/openstack/test_api.py +++ b/nova/tests/api/openstack/v2/test_api.py @@ -17,15 +17,14 @@ import json +from lxml import etree import webob.exc import webob.dec - -from lxml import etree from webob import Request from nova import test -from nova.api import openstack -from nova.api.openstack import faults +from nova.api.openstack import v2 +from nova.api.openstack.v2 import wsgi from nova.tests.api.openstack import fakes @@ -33,7 +32,7 @@ class APITest(test.TestCase): def _wsgi_app(self, inner_app): # simpler version of the app than fakes.wsgi_app - return openstack.FaultWrapper(inner_app) + return v2.FaultWrapper(inner_app) def test_malformed_json(self): req = webob.Request.blank('/') @@ -94,7 +93,7 @@ class APITest(test.TestCase): @webob.dec.wsgify def raise_api_fault(req): exc = webob.exc.HTTPNotFound(explanation='Raised a webob.exc') - return faults.Fault(exc) + return wsgi.Fault(exc) #api.application = succeed api = self._wsgi_app(succeed) diff --git a/nova/tests/api/openstack/test_auth.py b/nova/tests/api/openstack/v2/test_auth.py similarity index 95% rename from nova/tests/api/openstack/test_auth.py rename to nova/tests/api/openstack/v2/test_auth.py index d6a52d4f0b..05058c5550 100644 --- a/nova/tests/api/openstack/test_auth.py +++ b/nova/tests/api/openstack/v2/test_auth.py @@ -20,8 +20,8 @@ import datetime import webob import webob.dec -import nova.api -import nova.api.openstack.auth +import nova.api.openstack.v2 +import nova.api.openstack.v2.auth import nova.auth.manager from nova import context from nova import db @@ -33,7 +33,7 @@ class Test(test.TestCase): def setUp(self): super(Test, self).setUp() - self.stubs.Set(nova.api.openstack.auth.AuthMiddleware, + self.stubs.Set(nova.api.openstack.v2.auth.AuthMiddleware, '__init__', fakes.fake_auth_init) self.stubs.Set(context, 'RequestContext', fakes.FakeRequestContext) fakes.FakeAuthManager.clear_fakes() @@ -80,7 +80,7 @@ class Test(test.TestCase): self.assertEqual(result.headers['X-Storage-Url'], "") token = result.headers['X-Auth-Token'] - self.stubs.Set(nova.api.openstack, 'APIRouter', fakes.FakeRouter) + self.stubs.Set(nova.api.openstack.v2, 'APIRouter', fakes.FakeRouter) req = webob.Request.blank('/v1.1/user1_project') req.headers['X-Auth-Token'] = token result = req.get_response(fakes.wsgi_app(fake_auth=False)) @@ -125,7 +125,7 @@ class Test(test.TestCase): self.assertEqual(result.status, '204 No Content') token = result.headers['X-Auth-Token'] - self.stubs.Set(nova.api.openstack, 'APIRouter', fakes.FakeRouter) + self.stubs.Set(nova.api.openstack.v2, 'APIRouter', fakes.FakeRouter) req = webob.Request.blank('/v1.1/user2_project') req.headers['X-Auth-Token'] = token result = req.get_response(fakes.wsgi_app(fake_auth=False)) @@ -178,7 +178,7 @@ class Test(test.TestCase): self.assertEqual(result.status, '204 No Content') token = result.headers['X-Auth-Token'] - self.stubs.Set(nova.api.openstack, 'APIRouter', fakes.FakeRouter) + self.stubs.Set(nova.api.openstack.v2, 'APIRouter', fakes.FakeRouter) req = webob.Request.blank('/v1.1/user2_project') req.headers['X-Auth-Token'] = token result = req.get_response(fakes.wsgi_app(fake_auth=False)) @@ -201,7 +201,7 @@ class Test(test.TestCase): self.assertEqual(result.status, '204 No Content') token = result.headers['X-Auth-Token'] - self.stubs.Set(nova.api.openstack, 'APIRouter', fakes.FakeRouter) + self.stubs.Set(nova.api.openstack.v2, 'APIRouter', fakes.FakeRouter) req = webob.Request.blank('/v1.1/user2_project') req.headers['X-Auth-Token'] = token result = req.get_response(fakes.wsgi_app(fake_auth=False)) @@ -238,7 +238,7 @@ class TestFunctional(test.TestCase): class TestLimiter(test.TestCase): def setUp(self): super(TestLimiter, self).setUp() - self.stubs.Set(nova.api.openstack.auth.AuthMiddleware, + self.stubs.Set(nova.api.openstack.v2.auth.AuthMiddleware, '__init__', fakes.fake_auth_init) self.stubs.Set(context, 'RequestContext', fakes.FakeRequestContext) fakes.FakeAuthManager.clear_fakes() @@ -262,7 +262,7 @@ class TestLimiter(test.TestCase): self.assertEqual(len(result.headers['X-Auth-Token']), 40) token = result.headers['X-Auth-Token'] - self.stubs.Set(nova.api.openstack, 'APIRouter', fakes.FakeRouter) + self.stubs.Set(nova.api.openstack.v2, 'APIRouter', fakes.FakeRouter) req = webob.Request.blank('/v1.1/test') req.method = 'POST' req.headers['X-Auth-Token'] = token diff --git a/nova/tests/api/openstack/test_consoles.py b/nova/tests/api/openstack/v2/test_consoles.py similarity index 99% rename from nova/tests/api/openstack/test_consoles.py rename to nova/tests/api/openstack/v2/test_consoles.py index 0b682be0af..fc6479f917 100644 --- a/nova/tests/api/openstack/test_consoles.py +++ b/nova/tests/api/openstack/v2/test_consoles.py @@ -22,7 +22,7 @@ import json from lxml import etree import webob -from nova.api.openstack import consoles +from nova.api.openstack.v2 import consoles from nova import console from nova import db from nova.compute import vm_states diff --git a/nova/tests/api/openstack/test_extensions.py b/nova/tests/api/openstack/v2/test_extensions.py similarity index 96% rename from nova/tests/api/openstack/test_extensions.py rename to nova/tests/api/openstack/v2/test_extensions.py index b4fe3e7300..5d388ddd3c 100644 --- a/nova/tests/api/openstack/test_extensions.py +++ b/nova/tests/api/openstack/v2/test_extensions.py @@ -17,19 +17,20 @@ import json import os.path + import webob from lxml import etree +from nova.api.openstack import v2 +from nova.api.openstack.v2 import extensions +from nova.api.openstack.v2 import flavors +from nova.api.openstack import wsgi +from nova.api.openstack import xmlutil from nova import context from nova import flags from nova import test -from nova import wsgi as base_wsgi -from nova.api import openstack -from nova.api.openstack import extensions -from nova.api.openstack import flavors -from nova.api.openstack import wsgi -from nova.api.openstack import xmlutil from nova.tests.api.openstack import fakes +from nova import wsgi as base_wsgi FLAGS = flags.FLAGS @@ -88,7 +89,7 @@ class ExtensionTestCase(test.TestCase): def setUp(self): super(ExtensionTestCase, self).setUp() ext_list = FLAGS.osapi_extension[:] - ext_list.append('nova.tests.api.openstack.extensions.' + ext_list.append('nova.tests.api.openstack.v2.extensions.' 'foxinsocks.Foxinsocks') self.flags(osapi_extension=ext_list) @@ -123,7 +124,7 @@ class ExtensionControllerTest(ExtensionTestCase): self.ext_list.sort() def test_list_extensions_json(self): - app = openstack.APIRouter() + app = v2.APIRouter() ext_midware = extensions.ExtensionMiddleware(app) ser_midware = wsgi.LazySerializationMiddleware(ext_midware) request = webob.Request.blank("/123/extensions") @@ -150,7 +151,7 @@ class ExtensionControllerTest(ExtensionTestCase): ) def test_get_extension_json(self): - app = openstack.APIRouter() + app = v2.APIRouter() ext_midware = extensions.ExtensionMiddleware(app) ser_midware = wsgi.LazySerializationMiddleware(ext_midware) request = webob.Request.blank("/123/extensions/FOXNSOX") @@ -167,14 +168,14 @@ class ExtensionControllerTest(ExtensionTestCase): "links": []}) def test_get_non_existing_extension_json(self): - app = openstack.APIRouter() + app = v2.APIRouter() ext_midware = extensions.ExtensionMiddleware(app) request = webob.Request.blank("/123/extensions/4") response = request.get_response(ext_midware) self.assertEqual(404, response.status_int) def test_list_extensions_xml(self): - app = openstack.APIRouter() + app = v2.APIRouter() ext_midware = extensions.ExtensionMiddleware(app) ser_midware = wsgi.LazySerializationMiddleware(ext_midware) request = webob.Request.blank("/123/extensions") @@ -202,7 +203,7 @@ class ExtensionControllerTest(ExtensionTestCase): xmlutil.validate_schema(root, 'extensions') def test_get_extension_xml(self): - app = openstack.APIRouter() + app = v2.APIRouter() ext_midware = extensions.ExtensionMiddleware(app) ser_midware = wsgi.LazySerializationMiddleware(ext_midware) request = webob.Request.blank("/123/extensions/FOXNSOX") @@ -229,7 +230,7 @@ class ResourceExtensionTest(ExtensionTestCase): def test_no_extension_present(self): manager = StubExtensionManager(None) - app = openstack.APIRouter() + app = v2.APIRouter() ext_midware = extensions.ExtensionMiddleware(app, manager) ser_midware = wsgi.LazySerializationMiddleware(ext_midware) request = webob.Request.blank("/blah") @@ -240,7 +241,7 @@ class ResourceExtensionTest(ExtensionTestCase): res_ext = extensions.ResourceExtension('tweedles', StubController(response_body)) manager = StubExtensionManager(res_ext) - app = openstack.APIRouter() + app = v2.APIRouter() ext_midware = extensions.ExtensionMiddleware(app, manager) ser_midware = wsgi.LazySerializationMiddleware(ext_midware) request = webob.Request.blank("/123/tweedles") @@ -252,7 +253,7 @@ class ResourceExtensionTest(ExtensionTestCase): res_ext = extensions.ResourceExtension('tweedles', StubController(response_body)) manager = StubExtensionManager(res_ext) - app = openstack.APIRouter() + app = v2.APIRouter() ext_midware = extensions.ExtensionMiddleware(app, manager) ser_midware = wsgi.LazySerializationMiddleware(ext_midware) request = webob.Request.blank("/123/tweedles") @@ -264,7 +265,7 @@ class ResourceExtensionTest(ExtensionTestCase): res_ext = extensions.ResourceExtension('tweedles', StubController(response_body)) manager = StubExtensionManager(res_ext) - app = openstack.APIRouter() + app = v2.APIRouter() ext_midware = extensions.ExtensionMiddleware(app, manager) ser_midware = wsgi.LazySerializationMiddleware(ext_midware) request = webob.Request.blank("/123/tweedles") @@ -285,7 +286,7 @@ class ResourceExtensionTest(ExtensionTestCase): res_ext = extensions.ResourceExtension('tweedles', StubController(response_body)) manager = StubExtensionManager(res_ext) - app = openstack.APIRouter() + app = v2.APIRouter() ext_midware = extensions.ExtensionMiddleware(app, manager) ser_midware = wsgi.LazySerializationMiddleware(ext_midware) request = webob.Request.blank("/123/tweedles/1") @@ -312,7 +313,7 @@ class ExtensionManagerTest(ExtensionTestCase): response_body = "Try to say this Mr. Knox, sir..." def test_get_resources(self): - app = openstack.APIRouter() + app = v2.APIRouter() ext_midware = extensions.ExtensionMiddleware(app) ser_midware = wsgi.LazySerializationMiddleware(ext_midware) request = webob.Request.blank("/123/foxnsocks") @@ -323,7 +324,7 @@ class ExtensionManagerTest(ExtensionTestCase): def test_invalid_extensions(self): # Don't need the serialization middleware here because we're # not testing any serialization - app = openstack.APIRouter() + app = v2.APIRouter() ext_midware = extensions.ExtensionMiddleware(app) ext_mgr = ext_midware.ext_mgr ext_mgr.register(InvalidExtension()) @@ -334,7 +335,7 @@ class ExtensionManagerTest(ExtensionTestCase): class ActionExtensionTest(ExtensionTestCase): def _send_server_action_request(self, url, body): - app = openstack.APIRouter() + app = v2.APIRouter() ext_midware = extensions.ExtensionMiddleware(app) ser_midware = wsgi.LazySerializationMiddleware(ext_midware) request = webob.Request.blank(url) diff --git a/nova/tests/api/openstack/test_flavors.py b/nova/tests/api/openstack/v2/test_flavors.py similarity index 99% rename from nova/tests/api/openstack/test_flavors.py rename to nova/tests/api/openstack/v2/test_flavors.py index 24d81ef671..c62291ad15 100644 --- a/nova/tests/api/openstack/test_flavors.py +++ b/nova/tests/api/openstack/v2/test_flavors.py @@ -20,7 +20,7 @@ import json from lxml import etree import webob -from nova.api.openstack import flavors +from nova.api.openstack.v2 import flavors from nova.api.openstack import xmlutil import nova.compute.instance_types from nova import exception diff --git a/nova/tests/api/openstack/test_image_metadata.py b/nova/tests/api/openstack/v2/test_image_metadata.py similarity index 99% rename from nova/tests/api/openstack/test_image_metadata.py rename to nova/tests/api/openstack/v2/test_image_metadata.py index dc0cf1671b..a4f2f155dd 100644 --- a/nova/tests/api/openstack/test_image_metadata.py +++ b/nova/tests/api/openstack/v2/test_image_metadata.py @@ -18,11 +18,10 @@ import json import webob - -from nova.tests.api.openstack import fakes -from nova.api.openstack import image_metadata +from nova.api.openstack.v2 import image_metadata from nova import flags from nova import test +from nova.tests.api.openstack import fakes FLAGS = flags.FLAGS diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/v2/test_images.py similarity index 99% rename from nova/tests/api/openstack/test_images.py rename to nova/tests/api/openstack/v2/test_images.py index eb200046f2..b02b6ff2de 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/v2/test_images.py @@ -20,14 +20,15 @@ Tests of the new image services, both as a service layer, and as a WSGI layer """ +import urlparse + from lxml import etree import stubout -import urlparse import webob -from nova.api.openstack import images +from nova.api.openstack.v2 import images +from nova.api.openstack.v2.views import images as images_view from nova.api.openstack import xmlutil -from nova.api.openstack.views import images as images_view from nova import test from nova import utils from nova.tests.api.openstack import fakes diff --git a/nova/tests/api/openstack/test_limits.py b/nova/tests/api/openstack/v2/test_limits.py similarity index 99% rename from nova/tests/api/openstack/test_limits.py rename to nova/tests/api/openstack/v2/test_limits.py index 96e30f7568..e167f450cb 100644 --- a/nova/tests/api/openstack/test_limits.py +++ b/nova/tests/api/openstack/v2/test_limits.py @@ -19,19 +19,20 @@ Tests dealing with HTTP rate-limiting. import httplib import json -from lxml import etree import StringIO -import stubout import time import unittest -import webob from xml.dom import minidom -import nova.context -from nova.api.openstack import limits -from nova.api.openstack import views +from lxml import etree +import stubout +import webob + +from nova.api.openstack.v2 import limits +from nova.api.openstack.v2 import views from nova.api.openstack import wsgi from nova.api.openstack import xmlutil +import nova.context from nova import test diff --git a/nova/tests/api/openstack/test_server_actions.py b/nova/tests/api/openstack/v2/test_server_actions.py similarity index 97% rename from nova/tests/api/openstack/test_server_actions.py rename to nova/tests/api/openstack/v2/test_server_actions.py index 9d50483b8c..3adde3b7a9 100644 --- a/nova/tests/api/openstack/test_server_actions.py +++ b/nova/tests/api/openstack/v2/test_server_actions.py @@ -1,3 +1,18 @@ +# Copyright 2011 OpenStack LLC. +# 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. + import base64 import datetime import json @@ -5,17 +20,17 @@ import json import stubout import webob -from nova import context -from nova import utils -from nova import exception -from nova import flags -from nova.api.openstack import servers +from nova.api.openstack.v2 import servers from nova.compute import vm_states from nova.compute import instance_types +from nova import context import nova.db +from nova import exception +from nova import flags from nova import test from nova.tests.api.openstack import common from nova.tests.api.openstack import fakes +from nova import utils FLAGS = flags.FLAGS diff --git a/nova/tests/api/openstack/test_server_metadata.py b/nova/tests/api/openstack/v2/test_server_metadata.py similarity index 99% rename from nova/tests/api/openstack/test_server_metadata.py rename to nova/tests/api/openstack/v2/test_server_metadata.py index 1e0cba5419..49ff1bcd85 100644 --- a/nova/tests/api/openstack/test_server_metadata.py +++ b/nova/tests/api/openstack/v2/test_server_metadata.py @@ -18,13 +18,13 @@ import json import webob -from nova.api.openstack import server_metadata +from nova.api.openstack.v2 import server_metadata import nova.db from nova import exception from nova import flags from nova import test -from nova import utils from nova.tests.api.openstack import fakes +from nova import utils FLAGS = flags.FLAGS diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/v2/test_servers.py similarity index 99% rename from nova/tests/api/openstack/test_servers.py rename to nova/tests/api/openstack/v2/test_servers.py index 7eaaaa489d..34a5dfa519 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/v2/test_servers.py @@ -16,35 +16,28 @@ # License for the specific language governing permissions and limitations # under the License. -import base64 import datetime import json -import unittest import urlparse -from xml.dom import minidom from lxml import etree import webob -import nova.api.openstack -from nova.api.openstack import servers -from nova.api.openstack import ips +import nova.api.openstack.v2 +from nova.api.openstack.v2 import ips +from nova.api.openstack.v2 import servers from nova.api.openstack import xmlutil import nova.compute.api from nova.compute import instance_types from nova.compute import task_states from nova.compute import vm_states -from nova import context -from nova import db import nova.db from nova.db.sqlalchemy.models import InstanceMetadata -from nova import exception from nova import flags import nova.image.fake import nova.rpc import nova.scheduler.api from nova import test -from nova.tests.api.openstack import common from nova.tests.api.openstack import fakes from nova import utils @@ -2226,7 +2219,7 @@ class TestServerCreateRequestXMLDeserializer(test.TestCase): class TestAddressesXMLSerialization(test.TestCase): - serializer = nova.api.openstack.ips.IPXMLSerializer() + serializer = nova.api.openstack.v2.ips.IPXMLSerializer() def test_xml_declaration(self): fixture = { @@ -2304,7 +2297,7 @@ class ServersViewBuilderTest(test.TestCase): include_fake_metadata=False) self.uuid = self.instance['uuid'] - self.view_builder = nova.api.openstack.views.servers.ViewBuilder() + self.view_builder = nova.api.openstack.v2.views.servers.ViewBuilder() self.request = fakes.HTTPRequest.blank("/v1.1") def test_build_server(self): diff --git a/nova/tests/api/openstack/test_urlmap.py b/nova/tests/api/openstack/v2/test_urlmap.py similarity index 98% rename from nova/tests/api/openstack/test_urlmap.py rename to nova/tests/api/openstack/v2/test_urlmap.py index 3995765e5d..61a2373475 100644 --- a/nova/tests/api/openstack/test_urlmap.py +++ b/nova/tests/api/openstack/v2/test_urlmap.py @@ -16,11 +16,11 @@ import json import webob -from nova import test from nova import log as logging +from nova import test from nova.tests.api.openstack import fakes -LOG = logging.getLogger('nova.tests.api.openstack.test_urlmap') +LOG = logging.getLogger('nova.tests.api.openstack.v2.test_urlmap') class UrlmapTest(test.TestCase): diff --git a/nova/tests/api/openstack/test_users.py b/nova/tests/api/openstack/v2/test_users.py similarity index 99% rename from nova/tests/api/openstack/test_users.py rename to nova/tests/api/openstack/v2/test_users.py index 82fce68ffe..454b7cae76 100644 --- a/nova/tests/api/openstack/test_users.py +++ b/nova/tests/api/openstack/v2/test_users.py @@ -20,7 +20,7 @@ import webob from nova import test from nova import utils -from nova.api.openstack import users +from nova.api.openstack.v2 import users from nova.auth.manager import User, Project from nova.tests.api.openstack import fakes diff --git a/nova/tests/api/openstack/test_versions.py b/nova/tests/api/openstack/v2/test_versions.py similarity index 99% rename from nova/tests/api/openstack/test_versions.py rename to nova/tests/api/openstack/v2/test_versions.py index a6e30187bc..392e31a46e 100644 --- a/nova/tests/api/openstack/test_versions.py +++ b/nova/tests/api/openstack/v2/test_versions.py @@ -22,8 +22,8 @@ from lxml import etree import stubout import webob -from nova.api.openstack import versions -from nova.api.openstack import views +from nova.api.openstack.v2 import versions +from nova.api.openstack.v2 import views from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import context diff --git a/nova/tests/api/openstack/test_zones.py b/nova/tests/api/openstack/v2/test_zones.py similarity index 99% rename from nova/tests/api/openstack/test_zones.py rename to nova/tests/api/openstack/v2/test_zones.py index 496c3e8e6c..4a3e3ed477 100644 --- a/nova/tests/api/openstack/test_zones.py +++ b/nova/tests/api/openstack/v2/test_zones.py @@ -20,15 +20,15 @@ from lxml import etree import stubout import webob -import nova.db +from nova.api.openstack.v2 import zones +from nova.api.openstack import xmlutil from nova import context from nova import crypto +import nova.db from nova import flags -from nova import test -from nova.api.openstack import xmlutil -from nova.api.openstack import zones -from nova.tests.api.openstack import fakes from nova.scheduler import api +from nova import test +from nova.tests.api.openstack import fakes FLAGS = flags.FLAGS diff --git a/nova/tests/integrated/test_extensions.py b/nova/tests/integrated/test_extensions.py index 958f584abb..4318e30f2d 100644 --- a/nova/tests/integrated/test_extensions.py +++ b/nova/tests/integrated/test_extensions.py @@ -30,7 +30,7 @@ class ExtensionsTest(integrated_helpers._IntegratedTestBase): def _get_flags(self): f = super(ExtensionsTest, self)._get_flags() f['osapi_extension'] = FLAGS.osapi_extension[:] - f['osapi_extension'].append('nova.tests.api.openstack.extensions.' + f['osapi_extension'].append('nova.tests.api.openstack.v2.extensions.' 'foxinsocks.Foxinsocks') return f diff --git a/nova/tests/test_hosts.py b/nova/tests/test_hosts.py index becc74cddb..32fb5d2cf2 100644 --- a/nova/tests/test_hosts.py +++ b/nova/tests/test_hosts.py @@ -13,7 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import stubout import webob.exc from nova import context @@ -21,7 +20,7 @@ from nova import exception from nova import flags from nova import log as logging from nova import test -from nova.api.openstack.contrib import hosts as os_hosts +from nova.api.openstack.v2.contrib import hosts as os_hosts from nova.scheduler import api as scheduler_api