Skip to content

Commit 0228790

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Cleanup of 'server migration list' command"
2 parents eb75c44 + 5fd399e commit 0228790

2 files changed

Lines changed: 211 additions & 167 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 109 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,99 +1981,99 @@ def _show_progress(progress):
19811981

19821982

19831983
class ListMigration(command.Command):
1984-
_description = _("""List server migrations.""")
1984+
_description = _("""List server migrations""")
19851985

19861986
def get_parser(self, prog_name):
19871987
parser = super(ListMigration, self).get_parser(prog_name)
19881988
parser.add_argument(
1989-
"--server",
1990-
metavar="<server>",
1991-
dest='server',
1992-
default=None,
1993-
help=_('Server to show migration details (name or ID).')
1989+
'--server',
1990+
metavar='<server>',
1991+
help=_(
1992+
'Filter migrations by server (name or ID)'
1993+
)
19941994
)
19951995
parser.add_argument(
1996-
"--host",
1997-
metavar="<host>",
1998-
default=None,
1999-
help=_('Fetch migrations for the given host.')
1996+
'--host',
1997+
metavar='<host>',
1998+
help=_(
1999+
'Filter migrations by source or destination host'
2000+
),
20002001
)
20012002
parser.add_argument(
2002-
"--status",
2003-
metavar="<status>",
2004-
default=None,
2005-
help=_('Fetch migrations for the given status.')
2003+
'--status',
2004+
metavar='<status>',
2005+
help=_('Filter migrations by status')
20062006
)
20072007
parser.add_argument(
2008-
"--marker",
2009-
metavar="<marker>",
2010-
dest='marker',
2011-
default=None,
2012-
help=_("The last migration of the previous page; displays list "
2013-
"of migrations after 'marker'. Note that the marker is "
2014-
"the migration UUID. (Supported with "
2015-
"``--os-compute-api-version`` 2.59 or greater.)")
2008+
'--marker',
2009+
metavar='<marker>',
2010+
help=_(
2011+
"The last migration of the previous page; displays list "
2012+
"of migrations after 'marker'. Note that the marker is "
2013+
"the migration UUID. "
2014+
"(supported with --os-compute-api-version 2.59 or above)"
2015+
),
20162016
)
20172017
parser.add_argument(
2018-
"--limit",
2019-
metavar="<limit>",
2020-
dest='limit',
2018+
'--limit',
2019+
metavar='<limit>',
20212020
type=int,
2022-
default=None,
2023-
help=_("Maximum number of migrations to display. Note that there "
2024-
"is a configurable max limit on the server, and the limit "
2025-
"that is used will be the minimum of what is requested "
2026-
"here and what is configured in the server. "
2027-
"(Supported with ``--os-compute-api-version`` 2.59 "
2028-
"or greater.)")
2021+
help=_(
2022+
"Maximum number of migrations to display. Note that there "
2023+
"is a configurable max limit on the server, and the limit "
2024+
"that is used will be the minimum of what is requested "
2025+
"here and what is configured in the server. "
2026+
"(supported with --os-compute-api-version 2.59 or above)"
2027+
),
20292028
)
20302029
parser.add_argument(
20312030
'--changes-since',
20322031
dest='changes_since',
20332032
metavar='<changes-since>',
2034-
default=None,
2035-
help=_("List only migrations changed later or equal to a certain "
2036-
"point of time. The provided time should be an ISO 8061 "
2037-
"formatted time, e.g. ``2016-03-04T06:27:59Z``. "
2038-
"(Supported with ``--os-compute-api-version`` 2.59 "
2039-
"or greater.)")
2033+
help=_(
2034+
"List only migrations changed later or equal to a certain "
2035+
"point of time. The provided time should be an ISO 8061 "
2036+
"formatted time, e.g. ``2016-03-04T06:27:59Z``. "
2037+
"(supported with --os-compute-api-version 2.59 or above)"
2038+
),
20402039
)
20412040
parser.add_argument(
20422041
'--changes-before',
20432042
dest='changes_before',
20442043
metavar='<changes-before>',
2045-
default=None,
2046-
help=_("List only migrations changed earlier or equal to a "
2047-
"certain point of time. The provided time should be an ISO "
2048-
"8061 formatted time, e.g. ``2016-03-04T06:27:59Z``. "
2049-
"(Supported with ``--os-compute-api-version`` 2.66 or "
2050-
"greater.)")
2044+
help=_(
2045+
"List only migrations changed earlier or equal to a "
2046+
"certain point of time. The provided time should be an ISO "
2047+
"8061 formatted time, e.g. ``2016-03-04T06:27:59Z``. "
2048+
"(supported with --os-compute-api-version 2.66 or above)"
2049+
),
20512050
)
20522051
parser.add_argument(
20532052
'--project',
20542053
metavar='<project>',
20552054
dest='project_id',
2056-
default=None,
2057-
help=_("Filter the migrations by the given project ID. "
2058-
"(Supported with ``--os-compute-api-version`` 2.80 "
2059-
"or greater.)"),
2055+
help=_(
2056+
"Filter migrations by project (ID) "
2057+
"(supported with --os-compute-api-version 2.80 or above)"
2058+
),
20602059
)
20612060
parser.add_argument(
20622061
'--user',
20632062
metavar='<user>',
20642063
dest='user_id',
2065-
default=None,
2066-
help=_("Filter the migrations by the given user ID. "
2067-
"(Supported with ``--os-compute-api-version`` 2.80 "
2068-
"or greater.)"),
2064+
help=_(
2065+
"Filter migrations by user (ID) "
2066+
"(supported with --os-compute-api-version 2.80 or above)"
2067+
),
20692068
)
20702069
return parser
20712070

20722071
def print_migrations(self, parsed_args, compute_client, migrations):
2073-
columns = ['Source Node', 'Dest Node', 'Source Compute',
2074-
'Dest Compute', 'Dest Host', 'Status',
2075-
'Server UUID', 'Old Flavor', 'New Flavor',
2076-
'Created At', 'Updated At']
2072+
columns = [
2073+
'Source Node', 'Dest Node', 'Source Compute', 'Dest Compute',
2074+
'Dest Host', 'Status', 'Server UUID', 'Old Flavor', 'New Flavor',
2075+
'Created At', 'Updated At',
2076+
]
20772077

20782078
# Insert migrations UUID after ID
20792079
if compute_client.api_version >= api_versions.APIVersion("2.59"):
@@ -2093,48 +2093,73 @@ def print_migrations(self, parsed_args, compute_client, migrations):
20932093
if parsed_args.user_id:
20942094
columns.insert(len(columns) - 2, "User")
20952095

2096-
columns_header = columns
2097-
return (columns_header, (utils.get_item_properties(
2098-
mig, columns) for mig in migrations))
2096+
return (
2097+
columns,
2098+
(utils.get_item_properties(mig, columns) for mig in migrations),
2099+
)
20992100

21002101
def take_action(self, parsed_args):
21012102
compute_client = self.app.client_manager.compute
21022103

21032104
search_opts = {
2104-
"host": parsed_args.host,
2105-
"server": parsed_args.server,
2106-
"status": parsed_args.status,
2105+
'host': parsed_args.host,
2106+
'server': parsed_args.server,
2107+
'status': parsed_args.status,
21072108
}
21082109

2109-
if (parsed_args.marker or parsed_args.limit or
2110-
parsed_args.changes_since):
2111-
if compute_client.api_version < api_versions.APIVersion("2.59"):
2112-
msg = _("marker, limit and/or changes_since is not supported "
2113-
"for --os-compute-api-version less than 2.59")
2110+
if parsed_args.marker:
2111+
if compute_client.api_version < api_versions.APIVersion('2.59'):
2112+
msg = _(
2113+
'--os-compute-api-version 2.59 or greater is required to '
2114+
'support the --marker option'
2115+
)
21142116
raise exceptions.CommandError(msg)
2115-
if parsed_args.marker:
2116-
search_opts['marker'] = parsed_args.marker
2117-
if parsed_args.limit:
2118-
search_opts['limit'] = parsed_args.limit
2119-
if parsed_args.changes_since:
2120-
search_opts['changes_since'] = parsed_args.changes_since
2117+
search_opts['marker'] = parsed_args.marker
2118+
2119+
if parsed_args.limit:
2120+
if compute_client.api_version < api_versions.APIVersion('2.59'):
2121+
msg = _(
2122+
'--os-compute-api-version 2.59 or greater is required to '
2123+
'support the --limit option'
2124+
)
2125+
raise exceptions.CommandError(msg)
2126+
search_opts['limit'] = parsed_args.limit
2127+
2128+
if parsed_args.changes_since:
2129+
if compute_client.api_version < api_versions.APIVersion('2.59'):
2130+
msg = _(
2131+
'--os-compute-api-version 2.59 or greater is required to '
2132+
'support the --changes-since option'
2133+
)
2134+
raise exceptions.CommandError(msg)
2135+
search_opts['changes_since'] = parsed_args.changes_since
21212136

21222137
if parsed_args.changes_before:
2123-
if compute_client.api_version < api_versions.APIVersion("2.66"):
2124-
msg = _("changes_before is not supported for "
2125-
"--os-compute-api-version less than 2.66")
2138+
if compute_client.api_version < api_versions.APIVersion('2.66'):
2139+
msg = _(
2140+
'--os-compute-api-version 2.66 or greater is required to '
2141+
'support the --changes-before option'
2142+
)
21262143
raise exceptions.CommandError(msg)
21272144
search_opts['changes_before'] = parsed_args.changes_before
21282145

2129-
if parsed_args.project_id or parsed_args.user_id:
2130-
if compute_client.api_version < api_versions.APIVersion("2.80"):
2131-
msg = _("Project and/or user is not supported for "
2132-
"--os-compute-api-version less than 2.80")
2146+
if parsed_args.project_id:
2147+
if compute_client.api_version < api_versions.APIVersion('2.80'):
2148+
msg = _(
2149+
'--os-compute-api-version 2.80 or greater is required to '
2150+
'support the --project option'
2151+
)
2152+
raise exceptions.CommandError(msg)
2153+
search_opts['project_id'] = parsed_args.project_id
2154+
2155+
if parsed_args.user_id:
2156+
if compute_client.api_version < api_versions.APIVersion('2.80'):
2157+
msg = _(
2158+
'--os-compute-api-version 2.80 or greater is required to '
2159+
'support the --user option'
2160+
)
21332161
raise exceptions.CommandError(msg)
2134-
if parsed_args.project_id:
2135-
search_opts['project_id'] = parsed_args.project_id
2136-
if parsed_args.user_id:
2137-
search_opts['user_id'] = parsed_args.user_id
2162+
search_opts['user_id'] = parsed_args.user_id
21382163

21392164
migrations = compute_client.migrations.list(**search_opts)
21402165

0 commit comments

Comments
 (0)