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_servers_migrate.py 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 HostServersMigrateResponse(base.Resource):
  20. pass
  21. def _server_migrate(cs, server):
  22. success = True
  23. error_message = ""
  24. try:
  25. cs.servers.migrate(server['uuid'])
  26. except Exception as e:
  27. success = False
  28. error_message = _("Error while migrating instance: %s") % e
  29. return HostServersMigrateResponse(base.Manager,
  30. {"server_uuid": server['uuid'],
  31. "migration_accepted": success,
  32. "error_message": error_message})
  33. @cliutils.arg('host', metavar='<host>', help='Name of host.')
  34. def do_host_servers_migrate(cs, args):
  35. """Migrate all instances of the specified host to other available hosts."""
  36. hypervisors = cs.hypervisors.search(args.host, servers=True)
  37. response = []
  38. for hyper in hypervisors:
  39. if hasattr(hyper, 'servers'):
  40. for server in hyper.servers:
  41. response.append(_server_migrate(cs, server))
  42. utils.print_list(response,
  43. ["Server UUID", "Migration Accepted", "Error Message"])