summaryrefslogtreecommitdiff
path: root/novaclient/v2/contrib/instance_action.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/contrib/instance_action.py')
-rw-r--r--novaclient/v2/contrib/instance_action.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/novaclient/v2/contrib/instance_action.py b/novaclient/v2/contrib/instance_action.py
new file mode 100644
index 0000000..10e518e
--- /dev/null
+++ b/novaclient/v2/contrib/instance_action.py
@@ -0,0 +1,72 @@
1# Copyright 2013 Rackspace Hosting
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
16import pprint
17
18from novaclient import base
19from novaclient.i18n import _
20from novaclient.openstack.common import cliutils
21from novaclient import utils
22
23
24class InstanceActionManager(base.ManagerWithFind):
25 resource_class = base.Resource
26
27 def get(self, server, request_id):
28 """
29 Get details of an action performed on an instance.
30
31 :param request_id: The request_id of the action to get.
32 """
33 return self._get("/servers/%s/os-instance-actions/%s" %
34 (base.getid(server), request_id), 'instanceAction')
35
36 def list(self, server):
37 """
38 Get a list of actions performed on an server.
39 """
40 return self._list('/servers/%s/os-instance-actions' %
41 base.getid(server), 'instanceActions')
42
43
44@cliutils.arg(
45 'server',
46 metavar='<server>',
47 help=_('Name or UUID of the server to show an action for.'))
48@cliutils.arg(
49 'request_id',
50 metavar='<request_id>',
51 help=_('Request ID of the action to get.'))
52def do_instance_action(cs, args):
53 """Show an action."""
54 server = utils.find_resource(cs.servers, args.server)
55 action_resource = cs.instance_action.get(server, args.request_id)
56 action = action_resource._info
57 if 'events' in action:
58 action['events'] = pprint.pformat(action['events'])
59 utils.print_dict(action)
60
61
62@cliutils.arg(
63 'server',
64 metavar='<server>',
65 help=_('Name or UUID of the server to list actions for.'))
66def do_instance_action_list(cs, args):
67 """List actions on a server."""
68 server = utils.find_resource(cs.servers, args.server)
69 actions = cs.instance_action.list(server)
70 utils.print_list(actions,
71 ['Action', 'Request_ID', 'Message', 'Start_Time'],
72 sortby_index=3)