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_live.py 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright 2014 OpenStack Foundation
  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.i18n import _
  16. from novaclient.openstack.common import cliutils
  17. from novaclient import utils
  18. def _server_live_migrate(cs, server, args):
  19. class HostEvacuateLiveResponse(object):
  20. def __init__(self, server_uuid, live_migration_accepted,
  21. error_message):
  22. self.server_uuid = server_uuid
  23. self.live_migration_accepted = live_migration_accepted
  24. self.error_message = error_message
  25. success = True
  26. error_message = ""
  27. try:
  28. cs.servers.live_migrate(server['uuid'], args.target_host,
  29. args.block_migrate, args.disk_over_commit)
  30. except Exception as e:
  31. success = False
  32. error_message = _("Error while live migrating instance: %s") % e
  33. return HostEvacuateLiveResponse(server['uuid'],
  34. success,
  35. error_message)
  36. @cliutils.arg('host', metavar='<host>', help='Name of host.')
  37. @cliutils.arg(
  38. '--target-host',
  39. metavar='<target_host>',
  40. default=None,
  41. help=_('Name of target host.'))
  42. @cliutils.arg(
  43. '--block-migrate',
  44. action='store_true',
  45. default=False,
  46. help=_('Enable block migration.'))
  47. @cliutils.arg(
  48. '--disk-over-commit',
  49. action='store_true',
  50. default=False,
  51. help=_('Enable disk overcommit.'))
  52. def do_host_evacuate_live(cs, args):
  53. """Live migrate all instances of the specified host
  54. to other available hosts.
  55. """
  56. hypervisors = cs.hypervisors.search(args.host, servers=True)
  57. response = []
  58. for hyper in hypervisors:
  59. for server in getattr(hyper, 'servers', []):
  60. response.append(_server_live_migrate(cs, server, args))
  61. utils.print_list(response, ["Server UUID", "Live Migration Accepted",
  62. "Error Message"])