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.

migrations.py 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  2. # not use this file except in compliance with the License. You may obtain
  3. # a copy of the License at
  4. #
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10. # License for the specific language governing permissions and limitations
  11. # under the License.
  12. """
  13. migration interface
  14. """
  15. from six.moves.urllib import parse
  16. from novaclient import base
  17. from novaclient.i18n import _
  18. from novaclient.openstack.common import cliutils
  19. from novaclient import utils
  20. class Migration(base.Resource):
  21. def __repr__(self):
  22. return "<Migration: %s>" % self.id
  23. class MigrationManager(base.ManagerWithFind):
  24. resource_class = Migration
  25. def list(self, host=None, status=None, cell_name=None):
  26. """
  27. Get a list of migrations.
  28. :param host: (optional) filter migrations by host name.
  29. :param status: (optional) filter migrations by status.
  30. :param cell_name: (optional) filter migrations for a cell.
  31. """
  32. opts = {}
  33. if host:
  34. opts['host'] = host
  35. if status:
  36. opts['status'] = status
  37. if cell_name:
  38. opts['cell_name'] = cell_name
  39. # Transform the dict to a sequence of two-element tuples in fixed
  40. # order, then the encoded string will be consistent in Python 2&3.
  41. new_opts = sorted(opts.items(), key=lambda x: x[0])
  42. query_string = "?%s" % parse.urlencode(new_opts) if new_opts else ""
  43. return self._list("/os-migrations%s" % query_string, "migrations")
  44. @cliutils.arg(
  45. '--host',
  46. dest='host',
  47. metavar='<host>',
  48. help=_('Fetch migrations for the given host.'))
  49. @cliutils.arg(
  50. '--status',
  51. dest='status',
  52. metavar='<status>',
  53. help=_('Fetch migrations for the given status.'))
  54. @cliutils.arg(
  55. '--cell_name',
  56. dest='cell_name',
  57. metavar='<cell_name>',
  58. help=_('Fetch migrations for the given cell_name.'))
  59. def do_migration_list(cs, args):
  60. """Print a list of migrations."""
  61. _print_migrations(cs.migrations.list(args.host, args.status,
  62. args.cell_name))
  63. def _print_migrations(migrations):
  64. fields = ['Source Node', 'Dest Node', 'Source Compute', 'Dest Compute',
  65. 'Dest Host', 'Status', 'Instance UUID', 'Old Flavor',
  66. 'New Flavor', 'Created At', 'Updated At']
  67. def old_flavor(migration):
  68. return migration.old_instance_type_id
  69. def new_flavor(migration):
  70. return migration.new_instance_type_id
  71. formatters = {'Old Flavor': old_flavor, 'New Flavor': new_flavor}
  72. utils.print_list(migrations, fields, formatters)