def create(context, **kwargs): endpoint = kwargs.get('endpoint') if not endpoint: endpoint = get_karbor_endpoint() % {"project_id": context.project_id} LOG.debug("Creating karbor client with url %s.", endpoint) sc_cfg = CONF[CONFIG_GROUP] args = { 'version': sc_cfg.version, 'endpoint': endpoint, 'token': context.auth_token, 'cacert': sc_cfg.ca_cert_file, 'insecure': sc_cfg.auth_insecure, } return karbor_client.Client(**args)
def _get_karbor_client(api_version='1'): kwargs = _get_client_args('data-protect') client = karbor_client.Client(api_version, **kwargs) return client
def main(self, argv): # Parse args once to find version parser = self.get_base_parser() (options, args) = parser.parse_known_args(argv) self._setup_logging(options.debug) # build available subcommands based on version api_version = options.karbor_api_version subcommand_parser = self.get_subcommand_parser(api_version) self.parser = subcommand_parser keystone_session = None keystone_auth = None # Handle top-level --help/-h before attempting to parse # a command off the command line. if (not args and options.help) or not argv: self.do_help(options) return 0 # Parse args again and call whatever callback was selected. args = subcommand_parser.parse_args(argv) # Short-circuit and deal with help command 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 if not args.os_username and not args.os_auth_token: raise exc.CommandError("You must provide a username via" " either --os-username or env[OS_USERNAME]" " or a token via --os-auth-token or" " env[OS_AUTH_TOKEN]") if args.os_no_client_auth: if not args.karbor_url: raise exc.CommandError( "If you specify --os-no-client-auth" " you must also specify a Karbor API URL" " via either --karbor-url or env[KARBOR_URL]") else: # Tenant name or ID is needed to make keystoneclient retrieve a # service catalog, it's not required if os_no_client_auth is # specified, neither is the auth URL. if not any([args.os_tenant_name, args.os_tenant_id, args.os_project_id, args.os_project_name]): raise exc.CommandError("You must provide a project name or" " project id via --os-project-name," " --os-project-id, env[OS_PROJECT_ID]" " or env[OS_PROJECT_NAME]. You may" " use os-project and os-tenant" " interchangeably.") if not args.os_auth_url: raise exc.CommandError("You must provide an auth url via" " either --os-auth-url or via" " env[OS_AUTH_URL]") endpoint = args.karbor_url if args.os_no_client_auth: # Authenticate through karbor, don't use session kwargs = { 'username': args.os_username, 'password': args.os_password, 'auth_token': args.os_auth_token, 'auth_url': args.os_auth_url, 'token': args.os_auth_token, 'insecure': args.insecure, 'timeout': args.api_timeout } if args.os_region_name: kwargs['region_name'] = args.os_region_name else: # Create a keystone session and keystone auth keystone_session = ksession.Session.load_from_cli_options(args) project_id = args.os_project_id or args.os_tenant_id project_name = args.os_project_name or args.os_tenant_name keystone_auth = self._get_keystone_auth( keystone_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) endpoint_type = args.os_endpoint_type or 'publicURL' service_type = args.os_service_type or 'data-protect' endpoint = keystone_auth.get_endpoint( keystone_session, service_type=service_type, region_name=args.os_region_name) kwargs = { 'session': keystone_session, 'auth': keystone_auth, 'service_type': service_type, 'endpoint_type': endpoint_type, 'region_name': args.os_region_name, } if args.api_timeout: kwargs['timeout'] = args.api_timeout client = karbor_client.Client(api_version, endpoint, **kwargs) args.func(client, args)