OpenStack Compute (Nova) Client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

instance_action.py 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. import pprint
  16. from novaclient import base
  17. from novaclient.i18n import _
  18. from novaclient.openstack.common import cliutils
  19. from novaclient import utils
  20. class InstanceActionManager(base.ManagerWithFind):
  21. resource_class = base.Resource
  22. def get(self, server, request_id):
  23. """
  24. Get details of an action performed on an instance.
  25. :param request_id: The request_id of the action to get.
  26. """
  27. return self._get("/servers/%s/os-instance-actions/%s" %
  28. (base.getid(server), request_id), 'instanceAction')
  29. def list(self, server):
  30. """
  31. Get a list of actions performed on an server.
  32. """
  33. return self._list('/servers/%s/os-instance-actions' %
  34. base.getid(server), 'instanceActions')
  35. @cliutils.arg(
  36. 'server',
  37. metavar='<server>',
  38. help=_('Name or UUID of the server to show an action for.'))
  39. @cliutils.arg(
  40. 'request_id',
  41. metavar='<request_id>',
  42. help=_('Request ID of the action to get.'))
  43. def do_instance_action(cs, args):
  44. """Show an action."""
  45. server = utils.find_resource(cs.servers, args.server)
  46. action_resource = cs.instance_action.get(server, args.request_id)
  47. action = action_resource._info
  48. if 'events' in action:
  49. action['events'] = pprint.pformat(action['events'])
  50. utils.print_dict(action)
  51. @cliutils.arg(
  52. 'server',
  53. metavar='<server>',
  54. help=_('Name or UUID of the server to list actions for.'))
  55. def do_instance_action_list(cs, args):
  56. """List actions on a server."""
  57. server = utils.find_resource(cs.servers, args.server)
  58. actions = cs.instance_action.list(server)
  59. utils.print_list(actions,
  60. ['Action', 'Request_ID', 'Message', 'Start_Time'],
  61. sortby_index=3)