From d5ae8d5667fee22ba4df4feea53224874a19d167 Mon Sep 17 00:00:00 2001 From: Chris Yeoh Date: Sat, 18 May 2013 12:48:44 +0930 Subject: Adds check that the core V3 API is loaded Adds infrastructure to be able to check that the core V3 API plugins are present and raise an exception and abort if any are missing. The list is deliberately hard coded though it is not yet complete and will be expanded as the core APIs are ported and it is decided exactly what will be considered to be the core API. Partially implements blueprint v3-api-extension-framework Change-Id: Ic2c1d5cd6836ee18819106558880682cf4cda487 --- nova/api/openstack/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'nova/api') diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index 3687ce111..3455b812d 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -28,6 +28,7 @@ import webob.exc from nova.api.openstack import extensions from nova.api.openstack import wsgi +from nova import exception from nova import notifications from nova.openstack.common import log as logging from nova import utils @@ -55,6 +56,11 @@ CONF = cfg.CONF CONF.register_group(api_opts_group) CONF.register_opts(api_opts, api_opts_group) +# List of v3 API extensions which are considered to form +# the core API and so must be present +# TODO(cyeoh): Expand this list as the core APIs are ported to V3 +API_V3_CORE_EXTENSIONS = set(['servers']) + class FaultWrapper(base_wsgi.Middleware): """Calls down the middleware stack, making exceptions into faults.""" @@ -306,8 +312,22 @@ class APIRouterV3(base_wsgi.Router): mapper=mapper) self.api_extension_manager.map(self._register_controllers) + missing_core_extensions = self.get_missing_core_extensions( + self.loaded_extension_info.get_extensions().keys()) + if missing_core_extensions: + LOG.critical(_("Missing core API extensions: %s"), + missing_core_extensions) + raise exception.CoreAPIMissing( + missing_apis=missing_core_extensions) + super(APIRouterV3, self).__init__(mapper) + @staticmethod + def get_missing_core_extensions(extensions_loaded): + extensions_loaded = set(extensions_loaded) + missing_extensions = API_V3_CORE_EXTENSIONS - extensions_loaded + return missing_extensions + @property def loaded_extension_info(self): raise NotImplementedError() -- cgit