~ubuntu-cloud-archive/ubuntu/precise/nova/trunk

« back to all changes in this revision

Viewing changes to nova/api/openstack/compute/contrib/server_action_list.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2011 OpenStack LLC.
2
 
# All Rights Reserved.
3
 
#
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
7
 
#
8
 
#         http://www.apache.org/licenses/LICENSE-2.0
9
 
#
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
14
 
#    under the License.
15
 
 
16
 
import webob.exc
17
 
 
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
23
 
 
24
 
 
25
 
sa_nsmap = {None: wsgi.XMLNS_V11}
26
 
authorize = extensions.extension_authorizer('compute', 'server_action_list')
27
 
 
28
 
 
29
 
class ServerActionsTemplate(xmlutil.TemplateBuilder):
30
 
    def construct(self):
31
 
        root = xmlutil.TemplateElement('actions')
32
 
        elem = xmlutil.SubTemplateElement(root, 'action', selector='actions')
33
 
        elem.set('created_at')
34
 
        elem.set('action')
35
 
        elem.set('error')
36
 
        return xmlutil.MasterTemplate(root, 1, nsmap=sa_nsmap)
37
 
 
38
 
 
39
 
class ServerActionListController(object):
40
 
    @wsgi.serializers(xml=ServerActionsTemplate)
41
 
    def index(self, req, server_id):
42
 
        context = req.environ["nova.context"]
43
 
        authorize(context)
44
 
        compute_api = compute.API()
45
 
 
46
 
        try:
47
 
            instance = compute_api.get(context, server_id)
48
 
        except exception.NotFound:
49
 
            raise webob.exc.HTTPNotFound(_("Instance not found"))
50
 
 
51
 
        items = compute_api.get_actions(context, instance)
52
 
 
53
 
        def _format_item(item):
54
 
            return {
55
 
                'created_at': str(item['created_at']),
56
 
                'action': item['action'],
57
 
                'error': item['error'],
58
 
            }
59
 
 
60
 
        return {'actions': [_format_item(item) for item in items]}
61
 
 
62
 
 
63
 
class Server_action_list(extensions.ExtensionDescriptor):
64
 
    """Allow Admins to view pending server actions"""
65
 
 
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"
71
 
 
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(),
77
 
                                           parent=parent_def)
78
 
        return [ext]