1
# Copyright 2011 OpenStack LLC.
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
18
from nova.api.openstack import extensions
19
from nova.api.openstack import wsgi
20
from nova.api.openstack import xmlutil
21
from nova import compute
22
from nova import exception
25
sa_nsmap = {None: wsgi.XMLNS_V11}
26
authorize = extensions.extension_authorizer('compute', 'server_action_list')
29
class ServerActionsTemplate(xmlutil.TemplateBuilder):
31
root = xmlutil.TemplateElement('actions')
32
elem = xmlutil.SubTemplateElement(root, 'action', selector='actions')
33
elem.set('created_at')
36
return xmlutil.MasterTemplate(root, 1, nsmap=sa_nsmap)
39
class ServerActionListController(object):
40
@wsgi.serializers(xml=ServerActionsTemplate)
41
def index(self, req, server_id):
42
context = req.environ["nova.context"]
44
compute_api = compute.API()
47
instance = compute_api.get(context, server_id)
48
except exception.NotFound:
49
raise webob.exc.HTTPNotFound(_("Instance not found"))
51
items = compute_api.get_actions(context, instance)
53
def _format_item(item):
55
'created_at': str(item['created_at']),
56
'action': item['action'],
57
'error': item['error'],
60
return {'actions': [_format_item(item) for item in items]}
63
class Server_action_list(extensions.ExtensionDescriptor):
64
"""Allow Admins to view pending server actions"""
66
name = "ServerActionList"
67
alias = "os-server-action-list"
68
namespace = ("http://docs.openstack.org/compute/ext/"
69
"server-actions-list/api/v1.1")
70
updated = "2011-12-21T00:00:00+00:00"
72
def get_resources(self):
73
parent_def = {'member_name': 'server', 'collection_name': 'servers'}
74
#NOTE(bcwaldon): This should be prefixed with 'os-'
75
ext = extensions.ResourceExtension('actions',
76
ServerActionListController(),