From 500da76ab281adc227eb0431ba8e286ca9d2d590 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Wed, 21 Dec 2011 15:37:27 -0500 Subject: Move 'diagnostics' subresource to admin extension Related to blueprint separate-nova-adminapi Change-Id: Ibbb2e4d638c16e3209ca4b3d71892a5d7e874ca4 --- nova/api/openstack/v2/__init__.py | 1 - .../api/openstack/v2/contrib/server_diagnostics.py | 53 ++++++++++++++++++++++ nova/api/openstack/v2/servers.py | 8 ---- 3 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 nova/api/openstack/v2/contrib/server_diagnostics.py (limited to 'nova/api') diff --git a/nova/api/openstack/v2/__init__.py b/nova/api/openstack/v2/__init__.py index 5575cd184..8a574ffa5 100644 --- a/nova/api/openstack/v2/__init__.py +++ b/nova/api/openstack/v2/__init__.py @@ -138,7 +138,6 @@ class APIRouter(base_wsgi.Router): if FLAGS.allow_admin_api: LOG.debug(_("Including admin operations in API.")) - server_members['diagnostics'] = 'GET' server_members['actions'] = 'GET' mapper.resource("user", "users", diff --git a/nova/api/openstack/v2/contrib/server_diagnostics.py b/nova/api/openstack/v2/contrib/server_diagnostics.py new file mode 100644 index 000000000..cfcf3627b --- /dev/null +++ b/nova/api/openstack/v2/contrib/server_diagnostics.py @@ -0,0 +1,53 @@ +# 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 webob.exc + +from nova.api.openstack.v2 import extensions +from nova import compute +from nova import exception +from nova.scheduler import api as scheduler_api + + +class ServerDiagnosticsController(object): + @exception.novaclient_converter + @scheduler_api.redirect_handler + def index(self, req, server_id): + context = req.environ["nova.context"] + compute_api = compute.API() + try: + instance = compute_api.get(context, id) + except exception.NotFound(): + raise webob.exc.HTTPNotFound(_("Instance not found")) + + return compute_api.get_diagnostics(context, instance) + + +class Server_diagnostics(extensions.ExtensionDescriptor): + """Allow Admins to view server diagnostics through server action""" + + name = "ServerDiagnostics" + alias = "os-server-diagnostics" + namespace = "http://docs.openstack.org/ext/server-diagnostics/api/v1.1" + updated = "2011-12-21T00:00:00+00:00" + admin_only = False + + def get_resources(self): + parent_def = {'member_name': 'server', 'collection_name': 'servers'} + #NOTE(bcwaldon): This should be prefixed with 'os-' + ext = extensions.ResourceExtension('diagnostics', + ServerDiagnosticsController(), + parent=parent_def) + return [ext] diff --git a/nova/api/openstack/v2/servers.py b/nova/api/openstack/v2/servers.py index 5c49dc725..51ccaadde 100644 --- a/nova/api/openstack/v2/servers.py +++ b/nova/api/openstack/v2/servers.py @@ -627,14 +627,6 @@ class Controller(wsgi.Controller): raise exc.HTTPUnprocessableEntity() return webob.Response(status_int=202) - @exception.novaclient_converter - @scheduler_api.redirect_handler - def diagnostics(self, req, id): - """Permit Admins to retrieve server diagnostics.""" - ctxt = req.environ["nova.context"] - instance = self._get_server(ctxt, id) - return self.compute_api.get_diagnostics(ctxt, instance) - def actions(self, req, id): """Permit Admins to retrieve server actions.""" ctxt = req.environ["nova.context"] -- cgit