2727
2828LOG = logging .getLogger (__name__ )
2929
30-
3130# Initialize the list of Authentication plugins early in order
3231# to get the command-line options
33- PLUGIN_LIST = stevedore .ExtensionManager (
34- base .PLUGIN_NAMESPACE ,
35- invoke_on_load = False ,
36- propagate_map_exceptions = True ,
37- )
32+ PLUGIN_LIST = None
3833
39- # Get the command line options so the help action has them available
34+ # List of plugin command line options
4035OPTIONS_LIST = {}
41- for plugin in PLUGIN_LIST :
42- for o in plugin .plugin .get_options ():
43- os_name = o .dest .lower ().replace ('_' , '-' )
44- os_env_name = 'OS_' + os_name .upper ().replace ('-' , '_' )
45- OPTIONS_LIST .setdefault (os_name , {'env' : os_env_name , 'help' : '' })
46- # TODO(mhu) simplistic approach, would be better to only add
47- # help texts if they vary from one auth plugin to another
48- # also the text rendering is ugly in the CLI ...
49- OPTIONS_LIST [os_name ]['help' ] += 'With %s: %s\n ' % (
50- plugin .name ,
51- o .help ,
36+
37+
38+ def get_plugin_list ():
39+ """Gather plugin list and cache it"""
40+
41+ global PLUGIN_LIST
42+
43+ if PLUGIN_LIST is None :
44+ PLUGIN_LIST = stevedore .ExtensionManager (
45+ base .PLUGIN_NAMESPACE ,
46+ invoke_on_load = False ,
47+ propagate_map_exceptions = True ,
5248 )
49+ return PLUGIN_LIST
50+
51+
52+ def get_options_list ():
53+ """Gather plugin options so the help action has them available"""
54+
55+ global OPTIONS_LIST
56+
57+ if not OPTIONS_LIST :
58+ for plugin in get_plugin_list ():
59+ for o in plugin .plugin .get_options ():
60+ os_name = o .dest .lower ().replace ('_' , '-' )
61+ os_env_name = 'OS_' + os_name .upper ().replace ('-' , '_' )
62+ OPTIONS_LIST .setdefault (
63+ os_name , {'env' : os_env_name , 'help' : '' },
64+ )
65+ # TODO(mhu) simplistic approach, would be better to only add
66+ # help texts if they vary from one auth plugin to another
67+ # also the text rendering is ugly in the CLI ...
68+ OPTIONS_LIST [os_name ]['help' ] += 'With %s: %s\n ' % (
69+ plugin .name ,
70+ o .help ,
71+ )
72+ return OPTIONS_LIST
5373
5474
5575def select_auth_plugin (options ):
5676 """Pick an auth plugin based on --os-auth-type or other options"""
5777
5878 auth_plugin_name = None
5979
60- if options .os_auth_type in [plugin .name for plugin in PLUGIN_LIST ]:
80+ if options .os_auth_type in [plugin .name for plugin in get_plugin_list () ]:
6181 # A direct plugin name was given, use it
6282 return options .os_auth_type
6383
@@ -113,7 +133,7 @@ def build_auth_params(auth_plugin_name, cmd_options):
113133 else :
114134 LOG .debug ('no auth_type' )
115135 # delay the plugin choice, grab every option
116- plugin_options = set ([o .replace ('-' , '_' ) for o in OPTIONS_LIST ])
136+ plugin_options = set ([o .replace ('-' , '_' ) for o in get_options_list () ])
117137 for option in plugin_options :
118138 option_name = 'os_' + option
119139 LOG .debug ('fetching option %s' % option_name )
@@ -147,7 +167,7 @@ def build_auth_plugins_option_parser(parser):
147167 authentication plugin.
148168
149169 """
150- available_plugins = [plugin .name for plugin in PLUGIN_LIST ]
170+ available_plugins = [plugin .name for plugin in get_plugin_list () ]
151171 parser .add_argument (
152172 '--os-auth-type' ,
153173 metavar = '<auth-type>' ,
@@ -169,7 +189,7 @@ def build_auth_plugins_option_parser(parser):
169189 default = utils .env ('OS_TENANT_ID' )
170190 ),
171191 }
172- for o in OPTIONS_LIST :
192+ for o in get_options_list () :
173193 # remove allusion to tenants from v2.0 API
174194 if 'tenant' not in o :
175195 parser .add_argument (
0 commit comments