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.

host_evacuate.py 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. from novaclient import base
  16. from novaclient.i18n import _
  17. from novaclient.openstack.common import cliutils
  18. from novaclient import utils
  19. class EvacuateHostResponse(base.Resource):
  20. pass
  21. def _server_evacuate(cs, server, args):
  22. success = True
  23. error_message = ""
  24. try:
  25. cs.servers.evacuate(server=server['uuid'], host=args.target_host,
  26. on_shared_storage=args.on_shared_storage)
  27. except Exception as e:
  28. success = False
  29. error_message = _("Error while evacuating instance: %s") % e
  30. return EvacuateHostResponse(base.Manager,
  31. {"server_uuid": server['uuid'],
  32. "evacuate_accepted": success,
  33. "error_message": error_message})
  34. @cliutils.arg('host', metavar='<host>', help='Name of host.')
  35. @cliutils.arg(
  36. '--target_host',
  37. metavar='<target_host>',
  38. default=None,
  39. help=_('Name of target host. If no host is specified the scheduler will '
  40. 'select a target.'))
  41. @cliutils.arg(
  42. '--on-shared-storage',
  43. dest='on_shared_storage',
  44. action="store_true",
  45. default=False,
  46. help=_('Specifies whether all instances files are on shared storage'))
  47. def do_host_evacuate(cs, args):
  48. """Evacuate all instances from failed host."""
  49. hypervisors = cs.hypervisors.search(args.host, servers=True)
  50. response = []
  51. for hyper in hypervisors:
  52. if hasattr(hyper, 'servers'):
  53. for server in hyper.servers:
  54. response.append(_server_evacuate(cs, server, args))
  55. utils.print_list(response,
  56. ["Server UUID", "Evacuate Accepted", "Error Message"])