Skip to content

Commit 1ab3867

Browse files
author
Dean Troyer
committed
Make Identity client load like the others
This does a couple of things: * Loads the Identity client module in the same manner as the other 'base' clients (where 'base' == 'included in the OSC repo') * Changes the entry point group name for the base clients to 'openstack.cli.base'. The extension group name remains the same. * Loads the base modules first followed by the extension modules. This load order ensures that the extension module commands are all loaded _after_ the base commands, allowing extensions to now override the base commands. Change-Id: I4b9ca7f1df6eb8bbe8e3f663f3065c2ed80ce20b
1 parent 7a8c9a7 commit 1ab3867

3 files changed

Lines changed: 42 additions & 37 deletions

File tree

‎openstackclient/identity/client.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,27 @@ def make_client(instance):
7070
return client
7171

7272

73+
def build_option_parser(parser):
74+
"""Hook to add global options"""
75+
parser.add_argument(
76+
'--os-identity-api-version',
77+
metavar='<identity-api-version>',
78+
default=utils.env(
79+
'OS_IDENTITY_API_VERSION',
80+
default=DEFAULT_IDENTITY_API_VERSION),
81+
help='Identity API version, default=' +
82+
DEFAULT_IDENTITY_API_VERSION +
83+
' (Env: OS_IDENTITY_API_VERSION)')
84+
parser.add_argument(
85+
'--os-trust-id',
86+
metavar='<trust-id>',
87+
default=utils.env('OS_TRUST_ID'),
88+
help='Trust ID to use when authenticating. '
89+
'This can only be used with Keystone v3 API '
90+
'(Env: OS_TRUST_ID)')
91+
return parser
92+
93+
7394
class IdentityClientv2_0(identity_client_v2_0.Client):
7495
"""Tweak the earlier client class to deal with some changes"""
7596
def __getattr__(self, name):

‎openstackclient/shell.py‎

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from openstackclient.common import restapi
3535
from openstackclient.common import timing
3636
from openstackclient.common import utils
37-
from openstackclient.identity import client as identity_client
3837

3938

4039
KEYRING_SERVICE = 'openstack'
@@ -76,6 +75,8 @@ def __init__(self):
7675
version=openstackclient.__version__,
7776
command_manager=commandmanager.CommandManager('openstack.cli'))
7877

78+
self.api_version = {}
79+
7980
# Until we have command line arguments parsed, dump any stack traces
8081
self.dump_stack_trace = True
8182

@@ -86,10 +87,14 @@ def __init__(self):
8687
# Assume TLS host certificate verification is enabled
8788
self.verify = True
8889

89-
# Get list of extension modules
90+
# Get list of base modules
9091
self.ext_modules = clientmanager.get_extension_modules(
91-
'openstack.cli.extension',
92+
'openstack.cli.base',
9293
)
94+
# Append list of extension modules
95+
self.ext_modules.extend(clientmanager.get_extension_modules(
96+
'openstack.cli.extension',
97+
))
9398

9499
# Loop through extensions to get parser additions
95100
for mod in self.ext_modules:
@@ -312,23 +317,6 @@ def build_option_parser(self, description, version):
312317
help="Print API call timing info",
313318
)
314319

315-
parser.add_argument(
316-
'--os-identity-api-version',
317-
metavar='<identity-api-version>',
318-
default=env(
319-
'OS_IDENTITY_API_VERSION',
320-
default=identity_client.DEFAULT_IDENTITY_API_VERSION),
321-
help='Identity API version, default=' +
322-
identity_client.DEFAULT_IDENTITY_API_VERSION +
323-
' (Env: OS_IDENTITY_API_VERSION)')
324-
parser.add_argument(
325-
'--os-trust-id',
326-
metavar='<trust-id>',
327-
default=utils.env('OS_TRUST_ID'),
328-
help='Trust ID to use when authenticating. '
329-
'This can only be used with Keystone v3 API '
330-
'(Env: OS_TRUST_ID)')
331-
332320
return parser
333321

334322
def authenticate_user(self):
@@ -437,24 +425,19 @@ def initialize_app(self, argv):
437425
# Save default domain
438426
self.default_domain = self.options.os_default_domain
439427

440-
# Stash selected API versions for later
441-
self.api_version = {
442-
'identity': self.options.os_identity_api_version,
443-
}
444428
# Loop through extensions to get API versions
445429
for mod in self.ext_modules:
446-
ver = getattr(self.options, mod.API_VERSION_OPTION, None)
447-
if ver:
448-
self.api_version[mod.API_NAME] = ver
449-
self.log.debug('%(name)s API version %(version)s',
450-
{'name': mod.API_NAME, 'version': ver})
451-
452-
# Add the API version-specific commands
453-
for api in self.api_version.keys():
454-
version = '.v' + self.api_version[api].replace('.', '_')
455-
cmd_group = 'openstack.' + api.replace('-', '_') + version
456-
self.log.debug('command group %s', cmd_group)
457-
self.command_manager.add_command_group(cmd_group)
430+
version_opt = getattr(self.options, mod.API_VERSION_OPTION, None)
431+
if version_opt:
432+
api = mod.API_NAME
433+
self.api_version[api] = version_opt
434+
version = '.v' + version_opt.replace('.', '_')
435+
cmd_group = 'openstack.' + api.replace('-', '_') + version
436+
self.command_manager.add_command_group(cmd_group)
437+
self.log.debug(
438+
'%(name)s API version %(version)s, cmd group %(group)s',
439+
{'name': api, 'version': version_opt, 'group': cmd_group}
440+
)
458441

459442
# Commands that span multiple APIs
460443
self.command_manager.add_command_group(

‎setup.cfg‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ console_scripts =
3030
openstack.cli =
3131
module_list = openstackclient.common.module:ListModule
3232

33-
openstack.cli.extension =
33+
openstack.cli.base =
3434
compute = openstackclient.compute.client
35+
identity = openstackclient.identity.client
3536
image = openstackclient.image.client
3637
network = openstackclient.network.client
3738
object_store = openstackclient.object.client

0 commit comments

Comments
 (0)