diff options
| author | lin-hua-cheng <os.lcheng@gmail.com> | 2014-12-19 18:40:40 -0800 |
|---|---|---|
| committer | lin-hua-cheng <os.lcheng@gmail.com> | 2014-12-30 17:31:29 -0800 |
| commit | 4a07e63e7ea4b99b10e4a3fd9ed06c0cf6ee905f (patch) | |
| tree | 24c6dd6935a88f58ecdf6706d08943a41b590f0e /openstackclient/identity | |
| parent | 3541b0a695af12e31ecae4b4bedbe4235b5c13b4 (diff) | |
| download | python-openstackclient-4a07e63e7ea4b99b10e4a3fd9ed06c0cf6ee905f.tar.gz | |
type should be required for v2.0 service create
Updated the service name to be optional, mostly matching the cli arguments
with v3 service create.
Implemented the following changes on service create:
- if only a single positional is present, it's a <type>.
This is not currently legal so it is considered a new case.
- if --type option is present the positional is handled as <name>;
display deprecation message
- if --name option is present the positional is handled as <type>.
Making --type optional is new, but back-compatible
- Made --name and --type mutually exclusive.
- only '--name <service-name> <type>' shall appear in the help output
Change-Id: I8fd4adba3d8cd00d5a8cacc2c494d99d492c45a3
Closes-Bug: #1404073
Diffstat (limited to 'openstackclient/identity')
| -rw-r--r-- | openstackclient/identity/v2_0/service.py | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/openstackclient/identity/v2_0/service.py b/openstackclient/identity/v2_0/service.py index e8848dde..0b98a903 100644 --- a/openstackclient/identity/v2_0/service.py +++ b/openstackclient/identity/v2_0/service.py @@ -15,6 +15,7 @@ """Service action implementations""" +import argparse import logging import six @@ -36,15 +37,20 @@ class CreateService(show.ShowOne): def get_parser(self, prog_name): parser = super(CreateService, self).get_parser(prog_name) parser.add_argument( - 'name', - metavar='<service-name>', - help=_('New service name'), + 'type_or_name', + metavar='<type>', + help=_('New service type (compute, image, identity, volume, etc)'), ) - parser.add_argument( + type_or_name_group = parser.add_mutually_exclusive_group() + type_or_name_group.add_argument( '--type', metavar='<service-type>', - required=True, - help=_('New service type (compute, image, identity, volume, etc)'), + help=argparse.SUPPRESS, + ) + type_or_name_group.add_argument( + '--name', + metavar='<name>', + help=_('New service name'), ) parser.add_argument( '--description', @@ -57,9 +63,28 @@ class CreateService(show.ShowOne): self.log.debug('take_action(%s)', parsed_args) identity_client = self.app.client_manager.identity + type_or_name = parsed_args.type_or_name + name = parsed_args.name + type = parsed_args.type + + # If only a single positional is present, it's a <type>. + # This is not currently legal so it is considered a new case. + if not type and not name: + type = type_or_name + # If --type option is present then positional is handled as <name>; + # display deprecation message. + elif type: + name = type_or_name + self.log.warning(_('The argument --type is deprecated, use service' + ' create --name <service-name> type instead.')) + # If --name option is present the positional is handled as <type>. + # Making --type optional is new, but back-compatible + elif name: + type = type_or_name + service = identity_client.services.create( - parsed_args.name, - parsed_args.type, + name, + type, parsed_args.description) info = {} |
