diff options
| author | Brian Waldon <brian.waldon@rackspace.com> | 2011-12-21 15:37:27 -0500 |
|---|---|---|
| committer | Brian Waldon <brian.waldon@rackspace.com> | 2011-12-21 16:13:18 -0500 |
| commit | 500da76ab281adc227eb0431ba8e286ca9d2d590 (patch) | |
| tree | 05487e98f87b67349ce22dd85bca3e01fc910603 | |
| parent | d0c77ebc0ea122030e681ba1400d0325e396cfb5 (diff) | |
| download | nova-500da76ab281adc227eb0431ba8e286ca9d2d590.tar.gz nova-500da76ab281adc227eb0431ba8e286ca9d2d590.tar.xz nova-500da76ab281adc227eb0431ba8e286ca9d2d590.zip | |
Move 'diagnostics' subresource to admin extension
Related to blueprint separate-nova-adminapi
Change-Id: Ibbb2e4d638c16e3209ca4b3d71892a5d7e874ca4
| -rw-r--r-- | nova/api/openstack/v2/__init__.py | 1 | ||||
| -rw-r--r-- | nova/api/openstack/v2/contrib/server_diagnostics.py | 53 | ||||
| -rw-r--r-- | nova/api/openstack/v2/servers.py | 8 | ||||
| -rw-r--r-- | nova/tests/api/openstack/v2/contrib/test_server_diagnostics.py | 55 | ||||
| -rw-r--r-- | nova/tests/api/openstack/v2/test_extensions.py | 1 | ||||
| -rw-r--r-- | nova/tests/api/openstack/v2/test_servers.py | 1 |
6 files changed, 109 insertions, 10 deletions
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"] diff --git a/nova/tests/api/openstack/v2/contrib/test_server_diagnostics.py b/nova/tests/api/openstack/v2/contrib/test_server_diagnostics.py new file mode 100644 index 000000000..f7d6932d0 --- /dev/null +++ b/nova/tests/api/openstack/v2/contrib/test_server_diagnostics.py @@ -0,0 +1,55 @@ +# Copyright 2011 Eldar Nugaev +# 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 json + +from nova.api.openstack import v2 +from nova.api.openstack.v2 import extensions +from nova.api.openstack import wsgi +import nova.compute +from nova import test +from nova.tests.api.openstack import fakes +import nova.utils + + +def fake_get_diagnostics(self, _context, instance_uuid): + return {'data': 'Some diagnostic info'} + + +def fake_instance_get(self, _context, instance_uuid): + return {'uuid': instance_uuid} + + +class ServerDiagnosticsTest(test.TestCase): + + def setUp(self): + super(ServerDiagnosticsTest, self).setUp() + self.flags(allow_admin_api=True) + self.flags(verbose=True) + self.stubs.Set(nova.compute.API, 'get_diagnostics', + fake_get_diagnostics) + self.stubs.Set(nova.compute.API, 'get', fake_instance_get) + self.compute_api = nova.compute.API() + + self.router = v2.APIRouter() + ext_middleware = extensions.ExtensionMiddleware(self.router) + self.app = wsgi.LazySerializationMiddleware(ext_middleware) + + def test_get_diagnostics(self): + uuid = nova.utils.gen_uuid() + req = fakes.HTTPRequest.blank('/fake/servers/%s/diagnostics' % uuid) + res = req.get_response(self.app) + output = json.loads(res.body) + self.assertEqual(output, {'data': 'Some diagnostic info'}) diff --git a/nova/tests/api/openstack/v2/test_extensions.py b/nova/tests/api/openstack/v2/test_extensions.py index a3027194b..5c5bf1adf 100644 --- a/nova/tests/api/openstack/v2/test_extensions.py +++ b/nova/tests/api/openstack/v2/test_extensions.py @@ -114,6 +114,7 @@ class ExtensionControllerTest(ExtensionTestCase): "Quotas", "Rescue", "SecurityGroups", + "ServerDiagnostics", "SimpleTenantUsage", "VSAs", "VirtualInterfaces", diff --git a/nova/tests/api/openstack/v2/test_servers.py b/nova/tests/api/openstack/v2/test_servers.py index a792a8998..e29049ef7 100644 --- a/nova/tests/api/openstack/v2/test_servers.py +++ b/nova/tests/api/openstack/v2/test_servers.py @@ -205,7 +205,6 @@ class ServersControllerTest(test.TestCase): instance_addresses) self.stubs.Set(nova.db, 'instance_get_floating_address', instance_addresses) - self.stubs.Set(nova.compute.API, "get_diagnostics", fake_compute_api) self.stubs.Set(nova.compute.API, "get_actions", fake_compute_actions) self.config_drive = None |
