Remove APIRouter of legacy v2 API code

This patch removes the APIRouter because there is not any code
which uses the APIRouter. In addition, this patch update the
corresponding reno for explaining actual way for api-paste.ini.

Partially implements blueprint remove-legacy-v2-api-code

Change-Id: I136eb6ce7478f9ff692ebcbe1b14aa76222826bf
This commit is contained in:
Ken'ichi Ohmichi 2016-05-08 11:27:57 +09:00
parent f07306ee3d
commit 120d77e076
4 changed files with 3 additions and 197 deletions

View File

@ -57,9 +57,6 @@ paste.filter_factory = oslo_middleware.http_proxy_to_wsgi:HTTPProxyToWSGI.factor
[filter:legacy_v2_compatible]
paste.filter_factory = nova.api.openstack:LegacyV2CompatibleWrapper.factory
[app:osapi_compute_app_legacy_v2]
paste.app_factory = nova.api.openstack.compute:APIRouter.factory
[app:osapi_compute_app_v21]
paste.app_factory = nova.api.openstack.compute:APIRouterV21.factory

View File

@ -29,7 +29,6 @@ from nova.api.openstack import extensions
from nova.api.openstack import wsgi
import nova.conf
from nova import exception
from nova.i18n import _
from nova.i18n import _LC
from nova.i18n import _LE
from nova.i18n import _LI
@ -221,85 +220,6 @@ class PlainMapper(APIMapper):
**kwargs)
class APIRouter(base_wsgi.Router):
"""Routes requests on the OpenStack API to the appropriate controller
and method.
"""
ExtensionManager = None # override in subclasses
@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, init_only=None):
if ext_mgr is None:
if self.ExtensionManager:
ext_mgr = self.ExtensionManager()
else:
raise Exception(_("Must specify an ExtensionManager class"))
mapper = ProjectMapper()
self.resources = {}
self._setup_routes(mapper, ext_mgr, init_only)
self._setup_ext_routes(mapper, ext_mgr, init_only)
self._setup_extensions(ext_mgr)
super(APIRouter, self).__init__(mapper)
def _setup_ext_routes(self, mapper, ext_mgr, init_only):
for resource in ext_mgr.get_resources():
LOG.debug('Extending resource: %s',
resource.collection)
if init_only is not None and resource.collection not in init_only:
continue
inherits = None
if resource.inherits:
inherits = self.resources.get(resource.inherits)
if not resource.controller:
resource.controller = inherits.controller
wsgi_resource = wsgi.Resource(resource.controller,
inherits=inherits)
self.resources[resource.collection] = wsgi_resource
kargs = dict(
controller=wsgi_resource,
collection=resource.collection_actions,
member=resource.member_actions)
if resource.parent:
kargs['parent_resource'] = resource.parent
mapper.resource(resource.collection, resource.collection, **kargs)
if resource.custom_routes_fn:
resource.custom_routes_fn(mapper, wsgi_resource)
def _setup_extensions(self, ext_mgr):
for extension in ext_mgr.get_controller_extensions():
collection = extension.collection
controller = extension.controller
msg_format_dict = {'collection': collection,
'ext_name': extension.extension.name}
if collection not in self.resources:
LOG.warning(_LW('Extension %(ext_name)s: Cannot extend '
'resource %(collection)s: No such resource'),
msg_format_dict)
continue
LOG.debug('Extension %(ext_name)s extended resource: '
'%(collection)s',
msg_format_dict)
resource = self.resources[collection]
resource.register_actions(controller)
resource.register_extensions(controller)
def _setup_routes(self, mapper, ext_mgr, init_only):
raise NotImplementedError()
class APIRouterV21(base_wsgi.Router):
"""Routes requests on the OpenStack v2.1 API to the appropriate controller
and method.

View File

@ -22,126 +22,13 @@ from oslo_log import log as logging
import nova.api.openstack
from nova.api.openstack.compute import extension_info
from nova.api.openstack.compute.legacy_v2 import consoles as v2_consoles
from nova.api.openstack.compute.legacy_v2 import extensions as v2_extensions
from nova.api.openstack.compute.legacy_v2 import flavors as v2_flavors
from nova.api.openstack.compute.legacy_v2 import image_metadata \
as v2_image_metadata
from nova.api.openstack.compute.legacy_v2 import images as v2_images
from nova.api.openstack.compute.legacy_v2 import ips as v2_ips
from nova.api.openstack.compute.legacy_v2 import limits as v2_limits
from nova.api.openstack.compute.legacy_v2 import server_metadata \
as v2_server_metadata
from nova.api.openstack.compute.legacy_v2 import servers as v2_servers
from nova.api.openstack.compute.legacy_v2 import versions \
as legacy_v2_versions
import nova.conf
from nova.i18n import _LW
CONF = nova.conf.CONF
LOG = logging.getLogger(__name__)
class APIRouter(nova.api.openstack.APIRouter):
"""Routes requests on the OpenStack API to the appropriate controller
and method.
"""
ExtensionManager = v2_extensions.ExtensionManager
def __init__(self, ext_mgr=None, init_only=None):
LOG.warning(_LW(
"Deprecated: Starting with the Liberty release, the v2 API was "
"already deprecated and the v2.1 API is set as the default. Nova "
"also supports v2.1 API legacy v2 compatible mode for switching "
"to v2.1 API smoothly. For more information on how to configure "
"v2.1 API and legacy v2 compatible mode, please refer Nova "
"api-paste.ini sample file."))
super(APIRouter, self).__init__(ext_mgr=ext_mgr,
init_only=init_only)
def _setup_routes(self, mapper, ext_mgr, init_only):
if init_only is None or 'versions' in init_only:
self.resources['versions'] = legacy_v2_versions.create_resource()
mapper.connect("versions", "/",
controller=self.resources['versions'],
action='show',
conditions={"method": ['GET']})
mapper.redirect("", "/")
if init_only is None or 'consoles' in init_only:
self.resources['consoles'] = v2_consoles.create_resource()
mapper.resource("console", "consoles",
controller=self.resources['consoles'],
parent_resource=dict(member_name='server',
collection_name='servers'))
if init_only is None or 'consoles' in init_only or \
'servers' in init_only or 'ips' in init_only:
self.resources['servers'] = v2_servers.create_resource(ext_mgr)
mapper.resource("server", "servers",
controller=self.resources['servers'],
collection={'detail': 'GET'},
member={'action': 'POST'})
if init_only is None or 'ips' in init_only:
self.resources['ips'] = v2_ips.create_resource()
mapper.resource("ip", "ips", controller=self.resources['ips'],
parent_resource=dict(member_name='server',
collection_name='servers'))
if init_only is None or 'images' in init_only:
self.resources['images'] = v2_images.create_resource()
mapper.resource("image", "images",
controller=self.resources['images'],
collection={'detail': 'GET'})
if init_only is None or 'limits' in init_only:
self.resources['limits'] = v2_limits.create_resource()
mapper.resource("limit", "limits",
controller=self.resources['limits'])
if init_only is None or 'flavors' in init_only:
self.resources['flavors'] = v2_flavors.create_resource()
mapper.resource("flavor", "flavors",
controller=self.resources['flavors'],
collection={'detail': 'GET'},
member={'action': 'POST'})
if init_only is None or 'image_metadata' in init_only:
v2immeta = v2_image_metadata
self.resources['image_metadata'] = v2immeta.create_resource()
image_metadata_controller = self.resources['image_metadata']
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']})
if init_only is None or 'server_metadata' in init_only:
self.resources['server_metadata'] = \
v2_server_metadata.create_resource()
server_metadata_controller = self.resources['server_metadata']
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']})
class APIRouterV21(nova.api.openstack.APIRouterV21):
"""Routes requests on the OpenStack API to the appropriate controller
and method.

View File

@ -7,4 +7,6 @@ upgrade:
compatible API before switch to v2.1 API, user can use v2.1 API code as
v2 API compatible mode. That compatible mode is closer to v2 API
behaviour which is v2 API compatible without restrict input validation
and microversions support.
and microversions support. So if using openstack_compute_api_legacy_v2
in /etc/nova/api-paste.ini for the API endpoint /v2, user need to switch
the endpoint to openstack_compute_api_v21_legacy_v2_compatible instead.