From 74390d4920e692e7c85462232a6256774c6eabae Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Thu, 22 Dec 2011 00:46:09 -0500 Subject: Move 'actions' subresource into extension Related to blueprint separate-nova-adminapi Change-Id: I6929c5c467f339bc91ac8185d6217a55a5369a58 --- nova/api/openstack/v2/__init__.py | 7 +-- .../api/openstack/v2/contrib/server_action_list.py | 61 ++++++++++++++++++++++ nova/api/openstack/v2/servers.py | 15 ------ 3 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 nova/api/openstack/v2/contrib/server_action_list.py (limited to 'nova/api') diff --git a/nova/api/openstack/v2/__init__.py b/nova/api/openstack/v2/__init__.py index 8a574ffa5..82a8764a0 100644 --- a/nova/api/openstack/v2/__init__.py +++ b/nova/api/openstack/v2/__init__.py @@ -105,7 +105,6 @@ class APIRouter(base_wsgi.Router): if ext_mgr is None: ext_mgr = extensions.ExtensionManager() - self.server_members = {} mapper = ProjectMapper() self._setup_routes(mapper) self._setup_ext_routes(mapper, ext_mgr) @@ -133,13 +132,9 @@ class APIRouter(base_wsgi.Router): mapper.resource(resource.collection, resource.collection, **kargs) 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['actions'] = 'GET' - mapper.resource("user", "users", controller=users.create_resource(), collection={'detail': 'GET'}) @@ -168,7 +163,7 @@ class APIRouter(base_wsgi.Router): mapper.resource("server", "servers", controller=servers.create_resource(), collection={'detail': 'GET'}, - member=self.server_members) + member={'action': 'POST'}) mapper.resource("ip", "ips", controller=ips.create_resource(), parent_resource=dict(member_name='server', diff --git a/nova/api/openstack/v2/contrib/server_action_list.py b/nova/api/openstack/v2/contrib/server_action_list.py new file mode 100644 index 000000000..62f21dbbf --- /dev/null +++ b/nova/api/openstack/v2/contrib/server_action_list.py @@ -0,0 +1,61 @@ +# 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 + + +class ServerActionListController(object): + + def index(self, req, server_id): + context = req.environ["nova.context"] + compute_api = compute.API() + + try: + instance = compute_api.get(context, server_id) + except exception.NotFound: + raise webob.exc.HTTPNotFound(_("Instance not found")) + + items = compute_api.get_actions(context, instance) + + def _format_item(item): + return { + 'created_at': str(item['created_at']), + 'action': item['action'], + 'error': item['error'], + } + + return {'actions': [_format_item(item) for item in items]} + + +class Server_action_list(extensions.ExtensionDescriptor): + """Allow Admins to view pending server actions""" + + name = "ServerActionList" + alias = "os-server-action-list" + namespace = "http://docs.openstack.org/ext/server-actions-list/api/v1.1" + updated = "2011-12-21T00:00:00+00:00" + admin_only = True + + def get_resources(self): + parent_def = {'member_name': 'server', 'collection_name': 'servers'} + #NOTE(bcwaldon): This should be prefixed with 'os-' + ext = extensions.ResourceExtension('actions', + ServerActionListController(), + parent=parent_def) + return [ext] diff --git a/nova/api/openstack/v2/servers.py b/nova/api/openstack/v2/servers.py index 51ccaadde..dda6e6e96 100644 --- a/nova/api/openstack/v2/servers.py +++ b/nova/api/openstack/v2/servers.py @@ -627,21 +627,6 @@ class Controller(wsgi.Controller): raise exc.HTTPUnprocessableEntity() return webob.Response(status_int=202) - def actions(self, req, id): - """Permit Admins to retrieve server actions.""" - ctxt = req.environ["nova.context"] - instance = self._get_server(ctxt, id) - items = self.compute_api.get_actions(ctxt, instance) - actions = [] - # TODO(jk0): Do not do pre-serialization here once the default - # serializer is updated - for item in items: - actions.append(dict( - created_at=str(item.created_at), - action=item.action, - error=item.error)) - return dict(actions=actions) - def _resize(self, req, instance_id, flavor_id): """Begin the resize process with given instance/flavor.""" context = req.environ["nova.context"] -- cgit