diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 294b468331..fddafaee69 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -2065,6 +2065,14 @@ class ListMigration(command.Command): metavar='', help=_('Filter migrations by status') ) + parser.add_argument( + '--type', + metavar='', + choices=[ + 'evacuation', 'live-migration', 'cold-migration', 'resize', + ], + help=_('Filter migrations by type'), + ) parser.add_argument( '--marker', metavar='', @@ -2140,10 +2148,6 @@ class ListMigration(command.Command): if compute_client.api_version >= api_versions.APIVersion("2.59"): columns.insert(0, "UUID") - # TODO(brinzhang): It also suppports filter migrations by type - # since 2.1. https://review.opendev.org/#/c/675117 supported - # filtering the migrations by 'migration_type' and 'source_compute' - # in novaclient, that will be added in OSC by follow-up. if compute_client.api_version >= api_versions.APIVersion("2.23"): columns.insert(0, "Id") columns.insert(len(columns) - 2, "Type") @@ -2168,6 +2172,13 @@ class ListMigration(command.Command): 'status': parsed_args.status, } + if parsed_args.type: + migration_type = parsed_args.type + # we're using an alias because the default value is confusing + if migration_type == 'cold-migration': + migration_type = 'migration' + search_opts['type'] = migration_type + if parsed_args.marker: if compute_client.api_version < api_versions.APIVersion('2.59'): msg = _( diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 380ef66b4e..15cdbf1637 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -4092,6 +4092,7 @@ class TestListMigration(TestServer): '--server', 'server1', '--host', 'host1', '--status', 'migrating', + '--type', 'cold-migration', ] verifylist = [ ('server', 'server1'), @@ -4106,6 +4107,7 @@ class TestListMigration(TestServer): 'status': 'migrating', 'host': 'host1', 'server': 'server1', + 'type': 'migration', } self.migrations_mock.list.assert_called_with(**kwargs)