def test_set_default_before_init(self): config.set_default('identity_api_version', '4') c = config.OpenStackConfig(config_files=[self.cloud_yaml], vendor_files=[self.vendor_yaml]) cc = c.get_one_cloud(cloud='_test-cloud_', argparse=None) self.assertEqual('4', cc.identity_api_version)
def initialize_app(self, argv): """Global app init bits: * set up API versions * validate authentication info * authenticate against Identity if requested """ # Parent __init__ parses argv into self.options super(OpenStackShell, self).initialize_app(argv) # Set the default plugin to token_endpoint if url and token are given if (self.options.url and self.options.token): # Use service token authentication cloud_config.set_default('auth_type', 'token_endpoint') else: cloud_config.set_default('auth_type', 'osc_password') self.log.debug("options: %s", self.options) project_id = getattr(self.options, 'project_id', None) project_name = getattr(self.options, 'project_name', None) tenant_id = getattr(self.options, 'tenant_id', None) tenant_name = getattr(self.options, 'tenant_name', None) # handle some v2/v3 authentication inconsistencies by just acting like # both the project and tenant information are both present. This can # go away if we stop registering all the argparse options together. if project_id and not tenant_id: self.options.tenant_id = project_id if project_name and not tenant_name: self.options.tenant_name = project_name if tenant_id and not project_id: self.options.project_id = tenant_id if tenant_name and not project_name: self.options.project_name = tenant_name # Do configuration file handling cc = cloud_config.OpenStackConfig() self.log.debug("defaults: %s", cc.defaults) self.cloud = cc.get_one_cloud( cloud=self.options.cloud, argparse=self.options, ) self.log.debug("cloud cfg: %s", self.cloud.config) # Set up client TLS # NOTE(dtroyer): --insecure is the non-default condition that # overrides any verify setting in clouds.yaml # so check it first, then fall back to any verify # setting provided. self.verify = not self.cloud.config.get( 'insecure', not self.cloud.config.get('verify', True), ) # NOTE(dtroyer): Per bug https://bugs.launchpad.net/bugs/1447784 # --insecure now overrides any --os-cacert setting, # where before --insecure was ignored if --os-cacert # was set. if self.verify and self.cloud.cacert: self.verify = self.cloud.cacert # Save default domain self.default_domain = self.options.default_domain # Loop through extensions to get API versions for mod in clientmanager.PLUGIN_MODULES: version_opt = getattr(self.options, mod.API_VERSION_OPTION, None) if version_opt: api = mod.API_NAME self.api_version[api] = version_opt if version_opt not in mod.API_VERSIONS: self.log.warning( "The %s version <%s> is not in supported versions <%s>" % (api, version_opt, ', '.join(mod.API_VERSIONS.keys()))) # Command groups deal only with major versions version = '.v' + version_opt.replace('.', '_').split('_')[0] cmd_group = 'openstack.' + api.replace('-', '_') + version self.command_manager.add_command_group(cmd_group) self.log.debug( '%(name)s API version %(version)s, cmd group %(group)s', {'name': api, 'version': version_opt, 'group': cmd_group} ) # Commands that span multiple APIs self.command_manager.add_command_group( 'openstack.common') # This is the naive extension implementation referred to in # blueprint 'client-extensions' # Extension modules can register their commands in an # 'openstack.extension' entry point group: # entry_points={ # 'openstack.extension': [ # 'list_repo=qaz.github.repo:ListRepo', # 'show_repo=qaz.github.repo:ShowRepo', # ], # } self.command_manager.add_command_group( 'openstack.extension') # call InitializeXxx() here # set up additional clients to stuff in to client_manager?? # Handle deferred help and exit self.print_help_if_requested() self.client_manager = clientmanager.ClientManager( cli_options=self.cloud, verify=self.verify, api_version=self.api_version, pw_func=prompt_for_password, )
def initialize_app(self, argv): """Global app init bits: * set up API versions * validate authentication info * authenticate against Identity if requested """ # Parent __init__ parses argv into self.options super(OpenStackShell, self).initialize_app(argv) # Resolve the verify/insecure exclusive pair here as cloud_config # doesn't know about verify self.options.insecure = ( self.options.insecure and not self.options.verify ) # Set the default plugin to token_endpoint if rl and token are given if (self.options.url and self.options.token): # Use service token authentication cloud_config.set_default('auth_type', 'token_endpoint') else: cloud_config.set_default('auth_type', 'osc_password') self.log.debug("options: %s", self.options) # Do configuration file handling cc = cloud_config.OpenStackConfig() self.log.debug("defaults: %s", cc.defaults) self.cloud = cc.get_one_cloud( cloud=self.options.cloud, argparse=self.options, ) self.log.debug("cloud cfg: %s", self.cloud.config) # Set up client TLS cacert = self.cloud.cacert if cacert: self.verify = cacert else: self.verify = not getattr(self.cloud.config, 'insecure', False) # Neutralize verify option self.options.verify = None # Save default domain self.default_domain = self.options.os_default_domain # Loop through extensions to get API versions for mod in clientmanager.PLUGIN_MODULES: version_opt = getattr(self.options, mod.API_VERSION_OPTION, None) if version_opt: api = mod.API_NAME self.api_version[api] = version_opt if version_opt not in mod.API_VERSIONS: self.log.warning( "The %s version <%s> is not in supported versions <%s>" % (api, version_opt, ', '.join(mod.API_VERSIONS.keys()))) # Command groups deal only with major versions version = '.v' + version_opt.replace('.', '_').split('_')[0] cmd_group = 'openstack.' + api.replace('-', '_') + version self.command_manager.add_command_group(cmd_group) self.log.debug( '%(name)s API version %(version)s, cmd group %(group)s', {'name': api, 'version': version_opt, 'group': cmd_group} ) # Commands that span multiple APIs self.command_manager.add_command_group( 'openstack.common') # This is the naive extension implementation referred to in # blueprint 'client-extensions' # Extension modules can register their commands in an # 'openstack.extension' entry point group: # entry_points={ # 'openstack.extension': [ # 'list_repo=qaz.github.repo:ListRepo', # 'show_repo=qaz.github.repo:ShowRepo', # ], # } self.command_manager.add_command_group( 'openstack.extension') # call InitializeXxx() here # set up additional clients to stuff in to client_manager?? # Handle deferred help and exit self.print_help_if_requested() self.client_manager = clientmanager.ClientManager( cli_options=self.cloud, verify=self.verify, api_version=self.api_version, pw_func=prompt_for_password, )
def initialize_app(self, argv): """Global app init bits: * set up API versions * validate authentication info * authenticate against Identity if requested """ # Parent __init__ parses argv into self.options super(OpenStackShell, self).initialize_app(argv) # Resolve the verify/insecure exclusive pair here as cloud_config # doesn't know about verify self.options.insecure = (self.options.insecure and not self.options.verify) # Set the default plugin to token_endpoint if rl and token are given if (self.options.url and self.options.token): # Use service token authentication cloud_config.set_default('auth_type', 'token_endpoint') else: cloud_config.set_default('auth_type', 'osc_password') self.log.debug("options: %s", self.options) # Do configuration file handling cc = cloud_config.OpenStackConfig() self.log.debug("defaults: %s", cc.defaults) self.cloud = cc.get_one_cloud( cloud=self.options.cloud, argparse=self.options, ) self.log.debug("cloud cfg: %s", self.cloud.config) # Set up client TLS cacert = self.cloud.cacert if cacert: self.verify = cacert else: self.verify = not getattr(self.cloud.config, 'insecure', False) # Neutralize verify option self.options.verify = None # Save default domain self.default_domain = self.options.os_default_domain # Loop through extensions to get API versions for mod in clientmanager.PLUGIN_MODULES: version_opt = getattr(self.options, mod.API_VERSION_OPTION, None) if version_opt: api = mod.API_NAME self.api_version[api] = version_opt if version_opt not in mod.API_VERSIONS: self.log.warning( "The %s version <%s> is not in supported versions <%s>" % (api, version_opt, ', '.join(mod.API_VERSIONS.keys()))) # Command groups deal only with major versions version = '.v' + version_opt.replace('.', '_').split('_')[0] cmd_group = 'openstack.' + api.replace('-', '_') + version self.command_manager.add_command_group(cmd_group) self.log.debug( '%(name)s API version %(version)s, cmd group %(group)s', { 'name': api, 'version': version_opt, 'group': cmd_group }) # Commands that span multiple APIs self.command_manager.add_command_group('openstack.common') # This is the naive extension implementation referred to in # blueprint 'client-extensions' # Extension modules can register their commands in an # 'openstack.extension' entry point group: # entry_points={ # 'openstack.extension': [ # 'list_repo=qaz.github.repo:ListRepo', # 'show_repo=qaz.github.repo:ShowRepo', # ], # } self.command_manager.add_command_group('openstack.extension') # call InitializeXxx() here # set up additional clients to stuff in to client_manager?? # Handle deferred help and exit self.print_help_if_requested() self.client_manager = clientmanager.ClientManager( cli_options=self.cloud, verify=self.verify, api_version=self.api_version, pw_func=prompt_for_password, )
def initialize_app(self, argv): """Global app init bits: * set up API versions * validate authentication info * authenticate against Identity if requested """ # Parent __init__ parses argv into self.options super(OpenStackShell, self).initialize_app(argv) # Set the default plugin to token_endpoint if url and token are given if (self.options.url and self.options.token): # Use service token authentication cloud_config.set_default('auth_type', 'token_endpoint') else: cloud_config.set_default('auth_type', 'osc_password') self.log.debug("options: %s", self.options) project_id = getattr(self.options, 'project_id', None) project_name = getattr(self.options, 'project_name', None) tenant_id = getattr(self.options, 'tenant_id', None) tenant_name = getattr(self.options, 'tenant_name', None) # handle some v2/v3 authentication inconsistencies by just acting like # both the project and tenant information are both present. This can # go away if we stop registering all the argparse options together. if project_id and not tenant_id: self.options.tenant_id = project_id if project_name and not tenant_name: self.options.tenant_name = project_name if tenant_id and not project_id: self.options.project_id = tenant_id if tenant_name and not project_name: self.options.project_name = tenant_name # Do configuration file handling # Ignore the default value of endpoint_type. Only if it is set later # will it be used. cc = cloud_config.OpenStackConfig(override_defaults={ 'endpoint_type': None, }) self.log.debug("defaults: %s", cc.defaults) self.cloud = cc.get_one_cloud( cloud=self.options.cloud, argparse=self.options, ) self.log.debug("cloud cfg: %s", self.cloud.config) # Set up client TLS # NOTE(dtroyer): --insecure is the non-default condition that # overrides any verify setting in clouds.yaml # so check it first, then fall back to any verify # setting provided. self.verify = not self.cloud.config.get( 'insecure', not self.cloud.config.get('verify', True), ) # NOTE(dtroyer): Per bug https://bugs.launchpad.net/bugs/1447784 # --insecure now overrides any --os-cacert setting, # where before --insecure was ignored if --os-cacert # was set. if self.verify and self.cloud.cacert: self.verify = self.cloud.cacert # Save default domain self.default_domain = self.options.default_domain # Loop through extensions to get API versions for mod in clientmanager.PLUGIN_MODULES: version_opt = getattr(self.options, mod.API_VERSION_OPTION, None) if version_opt: api = mod.API_NAME self.api_version[api] = version_opt if version_opt not in mod.API_VERSIONS: self.log.warning( "The %s version <%s> is not in supported versions <%s>" % (api, version_opt, ', '.join(mod.API_VERSIONS.keys()))) # Command groups deal only with major versions version = '.v' + version_opt.replace('.', '_').split('_')[0] cmd_group = 'openstack.' + api.replace('-', '_') + version self.command_manager.add_command_group(cmd_group) self.log.debug( '%(name)s API version %(version)s, cmd group %(group)s', { 'name': api, 'version': version_opt, 'group': cmd_group }) # Commands that span multiple APIs self.command_manager.add_command_group('openstack.common') # This is the naive extension implementation referred to in # blueprint 'client-extensions' # Extension modules can register their commands in an # 'openstack.extension' entry point group: # entry_points={ # 'openstack.extension': [ # 'list_repo=qaz.github.repo:ListRepo', # 'show_repo=qaz.github.repo:ShowRepo', # ], # } self.command_manager.add_command_group('openstack.extension') # call InitializeXxx() here # set up additional clients to stuff in to client_manager?? # Handle deferred help and exit self.print_help_if_requested() self.client_manager = clientmanager.ClientManager( cli_options=self.cloud, verify=self.verify, api_version=self.api_version, pw_func=prompt_for_password, )