Skip to content

Commit bf35f04

Browse files
committed
Add 'openstack server migration list --type' option
Another gap with novaclient closed. Change-Id: Id3ca95ceda6f438fa72496ab9ab15ac09bb64fa5 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
1 parent 5fd399e commit bf35f04

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,14 @@ def get_parser(self, prog_name):
18891889
metavar='<status>',
18901890
help=_('Filter migrations by status')
18911891
)
1892+
parser.add_argument(
1893+
'--type',
1894+
metavar='<type>',
1895+
choices=[
1896+
'evacuation', 'live-migration', 'cold-migration', 'resize',
1897+
],
1898+
help=_('Filter migrations by type'),
1899+
)
18921900
parser.add_argument(
18931901
'--marker',
18941902
metavar='<marker>',
@@ -1964,10 +1972,6 @@ def print_migrations(self, parsed_args, compute_client, migrations):
19641972
if compute_client.api_version >= api_versions.APIVersion("2.59"):
19651973
columns.insert(0, "UUID")
19661974

1967-
# TODO(brinzhang): It also suppports filter migrations by type
1968-
# since 2.1. https://review.opendev.org/#/c/675117 supported
1969-
# filtering the migrations by 'migration_type' and 'source_compute'
1970-
# in novaclient, that will be added in OSC by follow-up.
19711975
if compute_client.api_version >= api_versions.APIVersion("2.23"):
19721976
columns.insert(0, "Id")
19731977
columns.insert(len(columns) - 2, "Type")
@@ -1992,6 +1996,13 @@ def take_action(self, parsed_args):
19921996
'status': parsed_args.status,
19931997
}
19941998

1999+
if parsed_args.type:
2000+
migration_type = parsed_args.type
2001+
# we're using an alias because the default value is confusing
2002+
if migration_type == 'cold-migration':
2003+
migration_type = 'migration'
2004+
search_opts['type'] = migration_type
2005+
19952006
if parsed_args.marker:
19962007
if compute_client.api_version < api_versions.APIVersion('2.59'):
19972008
msg = _(

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3781,6 +3781,7 @@ def test_server_migration_list(self):
37813781
'--server', 'server1',
37823782
'--host', 'host1',
37833783
'--status', 'migrating',
3784+
'--type', 'cold-migration',
37843785
]
37853786
verifylist = [
37863787
('server', 'server1'),
@@ -3795,6 +3796,7 @@ def test_server_migration_list(self):
37953796
'status': 'migrating',
37963797
'host': 'host1',
37973798
'server': 'server1',
3799+
'type': 'migration',
37983800
}
37993801

38003802
self.migrations_mock.list.assert_called_with(**kwargs)

0 commit comments

Comments
 (0)