Add instance-uuid
flag to the migration-list
The user needs to query the specific server's migration history. The 'os-migrations' support 'instance_uuid' as query filter, but that isn't enabled in the migration-list command. This patch enable that filter. Change-Id: I137b94f4d73836bcc163b66ab20ee2987042a40f
This commit is contained in:
parent
2ed7d2b5d0
commit
59f885896a
@ -1937,7 +1937,7 @@ class FakeSessionClient(base_client.SessionClient):
|
|||||||
return self.get_os_cells_capacities()
|
return self.get_os_cells_capacities()
|
||||||
|
|
||||||
def get_os_migrations(self, **kw):
|
def get_os_migrations(self, **kw):
|
||||||
migration = {
|
migration1 = {
|
||||||
"created_at": "2012-10-29T13:42:02.000000",
|
"created_at": "2012-10-29T13:42:02.000000",
|
||||||
"dest_compute": "compute2",
|
"dest_compute": "compute2",
|
||||||
"dest_host": "1.2.3.4",
|
"dest_host": "1.2.3.4",
|
||||||
@ -1952,10 +1952,35 @@ class FakeSessionClient(base_client.SessionClient):
|
|||||||
"updated_at": "2012-10-29T13:42:02.000000"
|
"updated_at": "2012-10-29T13:42:02.000000"
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.api_version >= api_versions.APIVersion("2.23"):
|
migration2 = {
|
||||||
migration.update({"migration_type": "live-migration"})
|
"created_at": "2012-10-29T13:42:02.000000",
|
||||||
|
"dest_compute": "compute2",
|
||||||
|
"dest_host": "1.2.3.4",
|
||||||
|
"dest_node": "node2",
|
||||||
|
"id": '1234',
|
||||||
|
"instance_uuid": "instance_id_456",
|
||||||
|
"new_instance_type_id": 2,
|
||||||
|
"old_instance_type_id": 1,
|
||||||
|
"source_compute": "compute1",
|
||||||
|
"source_node": "node1",
|
||||||
|
"status": "Done",
|
||||||
|
"updated_at": "2013-11-50T13:42:02.000000"
|
||||||
|
}
|
||||||
|
|
||||||
migrations = {'migrations': [migration]}
|
if self.api_version >= api_versions.APIVersion("2.23"):
|
||||||
|
migration1.update({"migration_type": "live-migration"})
|
||||||
|
migration2.update({"migration_type": "live-migration"})
|
||||||
|
|
||||||
|
migration_list = []
|
||||||
|
instance_uuid = kw.get('instance_uuid', None)
|
||||||
|
if instance_uuid == migration1['instance_uuid']:
|
||||||
|
migration_list.append(migration1)
|
||||||
|
elif instance_uuid == migration2['instance_uuid']:
|
||||||
|
migration_list.append(migration2)
|
||||||
|
elif instance_uuid is None:
|
||||||
|
migration_list.extend([migration1, migration2])
|
||||||
|
|
||||||
|
migrations = {'migrations': migration_list}
|
||||||
|
|
||||||
return (200, FAKE_RESPONSE_HEADERS, migrations)
|
return (200, FAKE_RESPONSE_HEADERS, migrations)
|
||||||
|
|
||||||
|
@ -47,3 +47,15 @@ class MigrationsTest(utils.TestCase):
|
|||||||
'/os-migrations?cell_name=child1&host=host1&status=finished')
|
'/os-migrations?cell_name=child1&host=host1&status=finished')
|
||||||
for m in ml:
|
for m in ml:
|
||||||
self.assertIsInstance(m, migrations.Migration)
|
self.assertIsInstance(m, migrations.Migration)
|
||||||
|
|
||||||
|
def test_list_migrations_with_instance_uuid_filter(self):
|
||||||
|
ml = self.cs.migrations.list('host1', 'finished', 'child1',
|
||||||
|
'instance_id_456')
|
||||||
|
self.assert_request_id(ml, fakes.FAKE_REQUEST_ID_LIST)
|
||||||
|
|
||||||
|
self.cs.assert_called(
|
||||||
|
'GET',
|
||||||
|
('/os-migrations?cell_name=child1&host=host1&'
|
||||||
|
'instance_uuid=instance_id_456&status=finished'))
|
||||||
|
self.assertEqual(1, len(ml))
|
||||||
|
self.assertEqual('instance_id_456', ml[0].instance_uuid)
|
||||||
|
@ -28,7 +28,7 @@ class Migration(base.Resource):
|
|||||||
class MigrationManager(base.ManagerWithFind):
|
class MigrationManager(base.ManagerWithFind):
|
||||||
resource_class = Migration
|
resource_class = Migration
|
||||||
|
|
||||||
def list(self, host=None, status=None, cell_name=None):
|
def list(self, host=None, status=None, cell_name=None, instance_uuid=None):
|
||||||
"""
|
"""
|
||||||
Get a list of migrations.
|
Get a list of migrations.
|
||||||
:param host: (optional) filter migrations by host name.
|
:param host: (optional) filter migrations by host name.
|
||||||
@ -45,6 +45,8 @@ class MigrationManager(base.ManagerWithFind):
|
|||||||
"deprecated since Pike, and will "
|
"deprecated since Pike, and will "
|
||||||
"be removed in a future release."))
|
"be removed in a future release."))
|
||||||
opts['cell_name'] = cell_name
|
opts['cell_name'] = cell_name
|
||||||
|
if instance_uuid:
|
||||||
|
opts['instance_uuid'] = instance_uuid
|
||||||
|
|
||||||
# Transform the dict to a sequence of two-element tuples in fixed
|
# Transform the dict to a sequence of two-element tuples in fixed
|
||||||
# order, then the encoded string will be consistent in Python 2&3.
|
# order, then the encoded string will be consistent in Python 2&3.
|
||||||
|
@ -4834,6 +4834,11 @@ def _print_migrations(cs, migrations):
|
|||||||
utils.print_list(migrations, fields, formatters)
|
utils.print_list(migrations, fields, formatters)
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg(
|
||||||
|
'--instance-uuid',
|
||||||
|
dest='instance_uuid',
|
||||||
|
metavar='<instance_uuid>',
|
||||||
|
help=_('Fetch migrations for the given instance.'))
|
||||||
@utils.arg(
|
@utils.arg(
|
||||||
'--host',
|
'--host',
|
||||||
dest='host',
|
dest='host',
|
||||||
@ -4855,5 +4860,6 @@ def _print_migrations(cs, migrations):
|
|||||||
'removed after version 8.0.0.'))
|
'removed after version 8.0.0.'))
|
||||||
def do_migration_list(cs, args):
|
def do_migration_list(cs, args):
|
||||||
"""Print a list of migrations."""
|
"""Print a list of migrations."""
|
||||||
migrations = cs.migrations.list(args.host, args.status)
|
migrations = cs.migrations.list(args.host, args.status, None,
|
||||||
|
instance_uuid=args.instance_uuid)
|
||||||
_print_migrations(cs, migrations)
|
_print_migrations(cs, migrations)
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
A new ``--instance-uuid`` option is added to ``nova migration-list``
|
||||||
|
command. This is used to query the migration history of a specific server
|
||||||
|
by the migration-list command. Please use ``nova server-migration-list``
|
||||||
|
command for querying in-progress migrations of a specific server.
|
Loading…
Reference in New Issue
Block a user