From ceaba4c5729b3defe51466b6c5c4bb28696edecd Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 18 Nov 2020 13:57:44 +0000 Subject: [PATCH] trivial: Cleanup docs for 'server rebuild' Use consistent help strings and error messages. Change-Id: I42647a6b7e67ce4b8dd5f826e20802ade691c266 Signed-off-by: Stephen Finucane --- openstackclient/compute/v2/server.py | 81 ++++++++++++++++++---------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 996c924b2e..4c177f7c3b 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -2440,47 +2440,57 @@ class RebuildServer(command.ShowOne): parser.add_argument( '--image', metavar='', - help=_('Recreate server from the specified image (name or ID).' - ' Defaults to the currently used one.'), + help=_( + 'Recreate server from the specified image (name or ID).' + 'Defaults to the currently used one.' + ), ) parser.add_argument( '--password', metavar='', - help=_("Set the password on the rebuilt instance"), + help=_('Set a password on the rebuilt server'), ) parser.add_argument( '--property', metavar='', action=parseractions.KeyValueAction, - help=_('Set a property on the rebuilt instance ' - '(repeat option to set multiple values)'), + help=_( + 'Set a new property on the rebuilt server ' + '(repeat option to set multiple values)' + ), ) parser.add_argument( '--description', metavar='', - help=_('New description for the server (supported by ' - '--os-compute-api-version 2.19 or above'), - ) - parser.add_argument( - '--wait', - action='store_true', - help=_('Wait for rebuild to complete'), + help=_( + 'Set a new description on the rebuilt server ' + '(supported by --os-compute-api-version 2.19 or above)' + ), ) key_group = parser.add_mutually_exclusive_group() key_group.add_argument( '--key-name', metavar='', - help=_("Set the key name of key pair on the rebuilt instance." - " Cannot be specified with the '--key-unset' option." - " (Supported by API versions '2.54' - '2.latest')"), + help=_( + 'Set the key name of key pair on the rebuilt server. ' + 'Cannot be specified with the --key-unset option. ' + '(supported by --os-compute-api-version 2.54 or above)' + ), ) key_group.add_argument( '--key-unset', action='store_true', default=False, - help=_("Unset the key name of key pair on the rebuilt instance." - " Cannot be specified with the '--key-name' option." - " (Supported by API versions '2.54' - '2.latest')"), + help=_( + 'Unset the key name of key pair on the rebuilt server. ' + 'Cannot be specified with the --key-name option. ' + '(supported by --os-compute-api-version 2.54 or above)' + ), + ) + parser.add_argument( + '--wait', + action='store_true', + help=_('Wait for rebuild to complete'), ) return parser @@ -2506,24 +2516,38 @@ class RebuildServer(command.ShowOne): image = image_client.get_image(image_id) kwargs = {} + if parsed_args.property: kwargs['meta'] = parsed_args.property + if parsed_args.description: if server.api_version < api_versions.APIVersion("2.19"): - msg = _("Description is not supported for " - "--os-compute-api-version less than 2.19") + msg = _( + '--os-compute-api-version 2.19 or greater is required to ' + 'support the --description option' + ) raise exceptions.CommandError(msg) + kwargs['description'] = parsed_args.description - if parsed_args.key_name or parsed_args.key_unset: + if parsed_args.key_name: if compute_client.api_version < api_versions.APIVersion('2.54'): - msg = _('--os-compute-api-version 2.54 or later is required') + msg = _( + '--os-compute-api-version 2.54 or greater is required to ' + 'support the --key-name option' + ) raise exceptions.CommandError(msg) - if parsed_args.key_unset: - kwargs['key_name'] = None - if parsed_args.key_name: kwargs['key_name'] = parsed_args.key_name + elif parsed_args.key_unset: + if compute_client.api_version < api_versions.APIVersion('2.54'): + msg = _( + '--os-compute-api-version 2.54 or greater is required to ' + 'support the --no-key-name option' + ) + raise exceptions.CommandError(msg) + + kwargs['key_name'] = None server = server.rebuild(image, parsed_args.password, **kwargs) if parsed_args.wait: @@ -2534,13 +2558,12 @@ class RebuildServer(command.ShowOne): ): self.app.stdout.write(_('Complete\n')) else: - LOG.error(_('Error rebuilding server: %s'), - server.id) + LOG.error(_('Error rebuilding server: %s'), server.id) self.app.stdout.write(_('Error rebuilding server\n')) raise SystemExit - details = _prep_server_detail(compute_client, image_client, server, - refresh=False) + details = _prep_server_detail( + compute_client, image_client, server, refresh=False) return zip(*sorted(details.items()))