diff --git a/novaclient/tests/unit/v2/fakes.py b/novaclient/tests/unit/v2/fakes.py index 1aaf76d4f..dedbd395c 100644 --- a/novaclient/tests/unit/v2/fakes.py +++ b/novaclient/tests/unit/v2/fakes.py @@ -1937,7 +1937,7 @@ class FakeSessionClient(base_client.SessionClient): return self.get_os_cells_capacities() def get_os_migrations(self, **kw): - migration = { + migration1 = { "created_at": "2012-10-29T13:42:02.000000", "dest_compute": "compute2", "dest_host": "1.2.3.4", @@ -1952,10 +1952,35 @@ class FakeSessionClient(base_client.SessionClient): "updated_at": "2012-10-29T13:42:02.000000" } - if self.api_version >= api_versions.APIVersion("2.23"): - migration.update({"migration_type": "live-migration"}) + migration2 = { + "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) diff --git a/novaclient/tests/unit/v2/test_migrations.py b/novaclient/tests/unit/v2/test_migrations.py index b270f9c3c..e69d3327e 100644 --- a/novaclient/tests/unit/v2/test_migrations.py +++ b/novaclient/tests/unit/v2/test_migrations.py @@ -47,3 +47,15 @@ class MigrationsTest(utils.TestCase): '/os-migrations?cell_name=child1&host=host1&status=finished') for m in ml: 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) diff --git a/novaclient/v2/migrations.py b/novaclient/v2/migrations.py index 075e59d7a..5a39ed992 100644 --- a/novaclient/v2/migrations.py +++ b/novaclient/v2/migrations.py @@ -28,7 +28,7 @@ class Migration(base.Resource): class MigrationManager(base.ManagerWithFind): 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. :param host: (optional) filter migrations by host name. @@ -45,6 +45,8 @@ class MigrationManager(base.ManagerWithFind): "deprecated since Pike, and will " "be removed in a future release.")) 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 # order, then the encoded string will be consistent in Python 2&3. diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index 42bf9b7f7..0e18d1809 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -4834,6 +4834,11 @@ def _print_migrations(cs, migrations): utils.print_list(migrations, fields, formatters) +@utils.arg( + '--instance-uuid', + dest='instance_uuid', + metavar='', + help=_('Fetch migrations for the given instance.')) @utils.arg( '--host', dest='host', @@ -4855,5 +4860,6 @@ def _print_migrations(cs, migrations): 'removed after version 8.0.0.')) def do_migration_list(cs, args): """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) diff --git a/releasenotes/notes/instance-uuid-flag-in-migration-list-5d2fed7657d3def5.yaml b/releasenotes/notes/instance-uuid-flag-in-migration-list-5d2fed7657d3def5.yaml new file mode 100644 index 000000000..239c662ea --- /dev/null +++ b/releasenotes/notes/instance-uuid-flag-in-migration-list-5d2fed7657d3def5.yaml @@ -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.