def create(context, conf, **kwargs): conf.register_opts(trove_client_opts, group=CONFIG_GROUP) client_config = conf[CONFIG_GROUP] url = utils.get_url(SERVICE, context, client_config, append_project_fmt='%(url)s/%(project)s', **kwargs) endpoint = url % {"tenant_id": context.project_id} LOG.debug('Creating trove client with url %s.', endpoint) if kwargs.get('session'): return tc.Client(TROVECLIENT_VERSION, session=kwargs.get('session'), endpoint_override=endpoint) args = { 'input_auth_token': context.auth_token, 'project_id': context.project_id, 'service_catalog_url': endpoint, 'cacert': client_config.trove_ca_cert_file, 'insecure': client_config.trove_auth_insecure, } client = tc.Client(TROVECLIENT_VERSION, **args) client.client.auth_token = context.auth_token client.client.management_url = endpoint return client
def trove(self, service_type="database"): if troveclient is None: return None if self._trove: return self._trove con = self.context endpoint_type = self._get_client_option('trove', 'endpoint_type') args = { 'service_type': service_type, 'auth_url': con.auth_url, 'proxy_token': con.auth_token, 'username': None, 'password': None, 'cacert': self._get_client_option('trove', 'ca_file'), 'insecure': self._get_client_option('trove', 'insecure'), 'endpoint_type': endpoint_type } self._trove = troveclient.Client('1.0', **args) management_url = self.url_for(service_type=service_type, endpoint_type=endpoint_type) self._trove.client.auth_token = con.auth_token self._trove.client.management_url = management_url return self._trove
def _initialize_tests(self): """Perform final initialization before tests get run.""" # Access the sentries for inspecting service units self.trove_sentry = self.d.sentry['trove'][0] self.mysql_sentry = self.d.sentry['mysql'][0] self.keystone_sentry = self.d.sentry['keystone'][0] self.rabbitmq_sentry = self.d.sentry['rabbitmq-server'][0] u.log.debug('openstack release val: {}'.format( self._get_openstack_release())) u.log.debug('openstack release str: {}'.format( self._get_openstack_release_string())) self.trove_svcs = [ 'trove-api', 'trove-taskmanager', 'trove-conductor', ] # Authenticate admin with keystone endpoint self.keystone = u.authenticate_keystone_admin(self.keystone_sentry, user='******', password='******', tenant='admin') # Authenticate admin with trove endpoint trove_ep = self.keystone.service_catalog.url_for( service_type='database', endpoint_type='publicURL') keystone_ep = self.keystone.service_catalog.url_for( service_type='identity', endpoint_type='publicURL') self.trove = trove_client.Client(version='1.0', auth_url=keystone_ep, username="******", password="******", tenant_name="admin", endpoint=trove_ep)
def trove(self, service_type="database"): if troveclient is None: return None if self._trove: return self._trove con = self.context if self.auth_token is None: logger.error(_("Trove connection failed, no auth_token!")) return None args = { 'service_type': service_type, 'auth_url': con.auth_url, 'proxy_token': con.auth_token, 'username': None, 'password': None } self._trove = troveclient.Client('1.0', **args) management_url = self.url_for(service_type=service_type) self._trove.client.auth_token = con.auth_token self._trove.client.management_url = management_url return self._trove
def create_client(self, version=None, service_type=None): """Returns trove client.""" from troveclient import client as trove client = trove.Client(self.choose_version(version), session=self.keystone.get_session()[0], endpoint=self._get_endpoint(service_type)) return client
def create_client(self, version=None): """Returns trove client.""" from troveclient import client as trove client = trove.Client(self.choose_version(version), region_name=self.credential.region_name, timeout=CONF.openstack_client_http_timeout, insecure=self.credential.insecure, **self._get_auth_info(password_key="api_key")) return client
def trove(self, version="1.0"): """Returns trove client.""" from troveclient import client as trove client = trove.Client(version, region_name=self.endpoint.region_name, timeout=CONF.openstack_client_http_timeout, insecure=self.endpoint.insecure, cacert=self.endpoint.cacert, **self._get_auth_info(password_key="api_key")) return client
def trove(self, version="1.0"): """Returns trove client.""" client = trove.Client(version, username=self.endpoint.username, api_key=self.endpoint.password, project_id=self.endpoint.tenant_name, auth_url=self.endpoint.auth_url, region_name=self.endpoint.region_name, timeout=CONF.openstack_client_http_timeout, insecure=CONF.https_insecure, cacert=CONF.https_cacert) return client
def _create(self): con = self.context endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') args = { 'endpoint_type': endpoint_type, 'service_type': self.DATABASE, 'session': con.keystone_session } client = tc.Client('1.0', **args) return client
def _create(self): con = self.context endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') args = { 'endpoint_type': endpoint_type, 'service_type': self.DATABASE, 'session': con.keystone_session, 'retries': cfg.CONF.client_retry_limit, 'region_name': self._get_region_name() } client = tc.Client('1.0', **args) return client
def _create(self): con = self.context endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') args = { 'service_type': self.DATABASE, 'auth_url': con.auth_url or '', 'proxy_token': con.auth_token, 'username': None, 'password': None, 'cacert': self._get_client_option(CLIENT_NAME, 'ca_file'), 'insecure': self._get_client_option(CLIENT_NAME, 'insecure'), 'endpoint_type': endpoint_type } client = tc.Client('1.0', **args) management_url = self.url_for(service_type=self.DATABASE, endpoint_type=endpoint_type) client.client.auth_token = self.auth_token client.client.management_url = management_url return client
def _trove(self): con = self.context endpoint_type = self._get_client_option('trove', 'endpoint_type') args = { 'service_type': 'database', 'auth_url': con.auth_url, 'proxy_token': con.auth_token, 'username': None, 'password': None, 'cacert': self._get_client_option('trove', 'ca_file'), 'insecure': self._get_client_option('trove', 'insecure'), 'endpoint_type': endpoint_type } client = troveclient.Client('1.0', **args) management_url = self.url_for(service_type='database', endpoint_type=endpoint_type) client.client.auth_token = con.auth_token client.client.management_url = management_url return client
def _create(self): service_type = "rax:database" con = self.context endpoint_type = self._get_client_option('trove', 'endpoint_type') args = { 'service_type': service_type, 'auth_url': con.auth_url, 'proxy_token': con.auth_token, 'username': None, 'password': None, 'cacert': self._get_client_option('trove', 'ca_file'), 'insecure': self._get_client_option('trove', 'insecure'), 'endpoint_type': endpoint_type } client = tc.Client('1.0', **args) region = cfg.CONF.region_name_for_services management_url = self.url_for(service_type=service_type, endpoint_type=endpoint_type, region_name=region) client.client.auth_token = con.auth_token client.client.management_url = management_url return client
def main(self, argv): # Parse args once to find version and debug settings parser = self.get_base_parser(argv) (options, args) = parser.parse_known_args(argv) self.setup_debugging(options.debug) self.options = options # Discover available auth plugins troveclient.auth_plugin.discover_auth_systems() # build available subcommands based on version self.extensions = self._discover_extensions( options.os_database_api_version) self._run_extension_hooks('__pre_parse_args__') subcommand_parser = self.get_subcommand_parser( options.os_database_api_version, argv) self.parser = subcommand_parser if options.help or not argv: subcommand_parser.print_help() return 0 args = subcommand_parser.parse_args(argv) self._run_extension_hooks('__post_parse_args__', args) # Short-circuit and deal with help right away. if args.func == self.do_help: self.do_help(args) return 0 elif args.func == self.do_bash_completion: self.do_bash_completion(args) return 0 os_username = args.os_username os_password = args.os_password os_project_name = getattr(args, 'os_project_name', getattr(args, 'os_tenant_name', None)) os_auth_url = args.os_auth_url os_region_name = args.os_region_name os_project_id = getattr(args, 'os_project_id', getattr(args, 'os_tenant_id', None)) os_auth_system = args.os_auth_system if "v2.0" not in os_auth_url: if (not args.os_project_domain_id and not args.os_project_domain_name): setattr(args, "os_project_domain_id", "default") if not args.os_user_domain_id and not args.os_user_domain_name: setattr(args, "os_user_domain_id", "default") endpoint_type = args.endpoint_type insecure = args.insecure service_type = args.service_type service_name = args.service_name database_service_name = args.database_service_name cacert = args.os_cacert bypass_url = args.bypass_url if os_auth_system and os_auth_system != "keystone": auth_plugin = troveclient.auth_plugin.load_plugin(os_auth_system) else: auth_plugin = None if not endpoint_type: endpoint_type = DEFAULT_TROVE_ENDPOINT_TYPE if not service_type: service_type = DEFAULT_TROVE_SERVICE_TYPE service_type = utils.get_service_type(args.func) or service_type # FIXME(usrleon): Here should be restrict for project id same as # for os_username or os_password but for compatibility it is not. if not utils.isunauthenticated(args.func): if auth_plugin: auth_plugin.parse_opts(args) if not auth_plugin or not auth_plugin.opts: if not os_username: raise exc.CommandError( _("You must provide a username " "via either --os-username or env[OS_USERNAME]")) if not os_password: os_password = getpass.getpass() if not os_auth_url: if os_auth_system and os_auth_system != 'keystone': os_auth_url = auth_plugin.get_auth_url() # V3 stuff project_info_provided = (self.options.os_project_name or self.options.os_project_id) if (not project_info_provided): raise exc.CommandError( _("You must provide a " "project_id or project_name (with " "project_domain_name or project_domain_id) via " " --os-project-id (env[OS_PROJECT_ID])" " --os-project-name (env[OS_PROJECT_NAME])," " --os-project-domain-id " "(env[OS_PROJECT_DOMAIN_ID])" " --os-project-domain-name " "(env[OS_PROJECT_DOMAIN_NAME])")) if not os_auth_url: raise exc.CommandError( _("You must provide an auth url " "via either --os-auth-url or " "env[OS_AUTH_URL] or specify an " "auth_system which defines a default " "url with --os-auth-system or " "env[OS_AUTH_SYSTEM]")) use_session = True if auth_plugin or bypass_url: use_session = False ks_session = None keystone_auth = None if use_session: project_id = args.os_project_id or args.os_tenant_id project_name = args.os_project_name or args.os_tenant_name ks_session = loading.load_session_from_argparse_arguments(args) keystone_auth = self._get_keystone_auth( ks_session, args.os_auth_url, username=args.os_username, user_id=args.os_user_id, user_domain_id=args.os_user_domain_id, user_domain_name=args.os_user_domain_name, password=args.os_password, auth_token=args.os_auth_token, project_id=project_id, project_name=project_name, project_domain_id=args.os_project_domain_id, project_domain_name=args.os_project_domain_name) profile = osprofiler_profiler and options.profile if profile: osprofiler_profiler.init(options.profile) self.cs = client.Client(options.os_database_api_version, os_username, os_password, os_project_name, os_auth_url, insecure, region_name=os_region_name, tenant_id=os_project_id, endpoint_type=endpoint_type, extensions=self.extensions, service_type=service_type, service_name=service_name, database_service_name=database_service_name, retries=options.retries, http_log_debug=args.debug, cacert=cacert, bypass_url=bypass_url, auth_system=os_auth_system, auth_plugin=auth_plugin, session=ks_session, auth=keystone_auth) try: if not utils.isunauthenticated(args.func): # If Keystone is used, authentication is handled as # part of session. if not use_session: self.cs.authenticate() except exc.Unauthorized: raise exc.CommandError(_("Invalid OpenStack Trove credentials.")) except exc.AuthorizationFailure: raise exc.CommandError(_("Unable to authorize user")) endpoint_api_version = self.cs.get_database_api_version_from_endpoint() if endpoint_api_version != options.os_database_api_version: msg = (_("Database API version is set to %(db_ver)s " "but you are accessing a %(ep_ver)s endpoint. " "Change its value via either --os-database-api-version " "or env[OS_DATABASE_API_VERSION]") % { 'db_ver': options.os_database_api_version, 'ep_ver': endpoint_api_version }) # raise exc.InvalidAPIVersion(msg) raise exc.UnsupportedVersion(msg) # Override printing to json output if args.json: utils.json_output = True else: utils.json_output = False try: args.func(self.cs, args) finally: if profile: trace_id = osprofiler_profiler.get().get_base_id() print(_("Trace ID: %(trace_id)s") % {'trace_id': trace_id}) print( _("To display the trace, use the following command:\n" "osprofiler trace show --html %(trace_id)s") % {'trace_id': trace_id})
def main(self, argv): # Parse args once to find version and debug settings parser = self.get_base_parser() (options, args) = parser.parse_known_args(argv) self.setup_debugging(options.debug) # build available subcommands based on version self.extensions = self._discover_extensions( options.os_database_api_version) self._run_extension_hooks('__pre_parse_args__') subcommand_parser = self.get_subcommand_parser( options.os_database_api_version) self.parser = subcommand_parser if options.help or not argv: subcommand_parser.print_help() return 0 args = subcommand_parser.parse_args(argv) self._run_extension_hooks('__post_parse_args__', args) # Short-circuit and deal with help right away. if args.func == self.do_help: self.do_help(args) return 0 elif args.func == self.do_bash_completion: self.do_bash_completion(args) return 0 (os_username, os_password, os_tenant_name, os_auth_url, os_region_name, os_tenant_id, endpoint_type, insecure, service_type, service_name, database_service_name, cacert, bypass_url) = ( args.os_username, args.os_password, args.os_tenant_name, args.os_auth_url, args.os_region_name, args.os_tenant_id, args.endpoint_type, args.insecure, args.service_type, args.service_name, args.database_service_name, args.os_cacert, args.bypass_url) if not endpoint_type: endpoint_type = DEFAULT_TROVE_ENDPOINT_TYPE if not service_type: service_type = DEFAULT_TROVE_SERVICE_TYPE service_type = utils.get_service_type(args.func) or service_type # FIXME(usrleon): Here should be restrict for project id same as # for os_username or os_password but for compatibility it is not. if not utils.isunauthenticated(args.func): if not os_username: raise exc.CommandError( "You must provide a username " "via either --os-username or env[OS_USERNAME]") if not os_password: raise exc.CommandError("You must provide a password " "via either --os-password or via " "env[OS_PASSWORD]") if not (os_tenant_name or os_tenant_id): raise exc.CommandError("You must provide a tenant_id " "via either --os-tenant-id or " "env[OS_TENANT_ID]") if not os_auth_url: raise exc.CommandError( "You must provide an auth url " "via either --os-auth-url or env[OS_AUTH_URL]") if not (os_tenant_name or os_tenant_id): raise exc.CommandError( "You must provide a tenant_id " "via either --os-tenant-id or env[OS_TENANT_ID]") if not os_auth_url: raise exc.CommandError( "You must provide an auth url " "via either --os-auth-url or env[OS_AUTH_URL]") self.cs = client.Client(options.os_database_api_version, os_username, os_password, os_tenant_name, os_auth_url, insecure, region_name=os_region_name, tenant_id=os_tenant_id, endpoint_type=endpoint_type, extensions=self.extensions, service_type=service_type, service_name=service_name, database_service_name=database_service_name, retries=options.retries, http_log_debug=args.debug, cacert=cacert, bypass_url=bypass_url) try: if not utils.isunauthenticated(args.func): self.cs.authenticate() except exc.Unauthorized: raise exc.CommandError("Invalid OpenStack Trove credentials.") except exc.AuthorizationFailure: raise exc.CommandError("Unable to authorize user") endpoint_api_version = self.cs.get_database_api_version_from_endpoint() if endpoint_api_version != options.os_database_api_version: msg = (("Database API version is set to %s " "but you are accessing a %s endpoint. " "Change its value via either --os-database-api-version " "or env[OS_DATABASE_API_VERSION]") % (options.os_database_api_version, endpoint_api_version)) # raise exc.InvalidAPIVersion(msg) raise exc.UnsupportedVersion(msg) # Override printing to json output if args.json: utils.json_output = True else: utils.json_output = False args.func(self.cs, args)