def create_client(args): """ Create instance of Lava from CLI args """ resource = args.resource if resource == 'shell': args.enable_cli = False apikey = first_exists(args.lava_api_key, os.environ.get('LAVA_API_KEY'), os.environ.get('OS_API_KEY')) token = first_exists(args.token, os.environ.get('LAVA_AUTH_TOKEN'), os.environ.get('AUTH_TOKEN')) user = first_exists(args.user, os.environ.get('LAVA_USERNAME'), os.environ.get('OS_USERNAME'), getpass.getuser()) if not (apikey or token): six.print_('Error: no API key or token', file=sys.stderr) sys.exit(1) try: return Lava( user, api_key=apikey, token=token, tenant_id=first_exists(args.tenant, os.environ.get('LAVA_TENANT_NAME'), os.environ.get('OS_TENANT_NAME')), region=first_exists(args.region, os.environ.get('LAVA_REGION_NAME'), os.environ.get('OS_REGION_NAME')), auth_url=first_exists(args.auth_url, os.environ.get('LAVA_AUTH_URL'), os.environ.get('OS_AUTH_URL')), endpoint=first_exists(args.endpoint, os.environ.get('LAVA2_API_URL'), os.environ.get('LAVA_API_URL')), verify_ssl=args.verify_ssl, timeout=first_exists(args.request_timeout, os.environ.get('LAVA_TIMEOUT')), max_retries=first_exists(args.retries, os.environ.get('LAVA_RETRIES')), retry_backoff=first_exists(args.retry_backoff, os.environ.get('LAVA_RETRY_BACKOFF')), _cli_args=args) except LavaError as exc: six.print_('Error during authentication: {0}'.format(exc), file=sys.stderr) if args.debug: raise sys.exit(1)
def create_client(args): """ Create instance of Lava from CLI args """ apikey = first_exists(args.lava_api_key, os.environ.get('LAVA_API_KEY'), os.environ.get('OS_API_KEY')) token = first_exists(args.token, os.environ.get('LAVA_AUTH_TOKEN'), os.environ.get('AUTH_TOKEN')) user = first_exists(args.user, os.environ.get('LAVA_USERNAME'), os.environ.get('OS_USERNAME'), getpass.getuser()) password = first_exists(args.password, os.environ.get('LAVA_PASSWORD'), os.environ.get('OS_PASSWORD')) if not any((apikey, token, password)): if args.headless: six.print_('Error: no API key, token, or password specified', file=sys.stderr) sys.exit(1) else: password = getpass.getpass('Password for {0}: '.format(user)) try: return Lava( user, api_key=apikey, token=token, password=password, tenant_id=first_exists(args.tenant, os.environ.get('LAVA_TENANT_NAME'), os.environ.get('OS_TENANT_NAME')), region=first_exists(args.region, os.environ.get('LAVA_REGION_NAME'), os.environ.get('OS_REGION_NAME')), auth_url=first_exists(args.auth_url, os.environ.get('LAVA_AUTH_URL'), os.environ.get('OS_AUTH_URL')), endpoint=first_exists(args.endpoint, os.environ.get('LAVA2_API_URL'), os.environ.get('LAVA_API_URL')), verify_ssl=args.verify_ssl, _cli_args=args) except LavaError as exc: six.print_('Error during authentication: {0}'.format(exc), file=sys.stderr) if args.debug: raise sys.exit(1)
def create_client(args): """ Create instance of Lava from CLI args """ resource = args.resource if resource == "shell": args.enable_cli = False apikey = first_exists(args.lava_api_key, os.environ.get("LAVA_API_KEY"), os.environ.get("OS_API_KEY")) token = first_exists(args.token, os.environ.get("LAVA_AUTH_TOKEN"), os.environ.get("AUTH_TOKEN")) user = first_exists(args.user, os.environ.get("LAVA_USERNAME"), os.environ.get("OS_USERNAME"), getpass.getuser()) password = first_exists(args.password, os.environ.get("LAVA_PASSWORD"), os.environ.get("OS_PASSWORD")) if not any((apikey, token, password)): if args.headless: six.print_("Error: no API key, token, or password specified", file=sys.stderr) sys.exit(1) else: password = getpass.getpass("Password for {0}: ".format(user)) try: return Lava( user, api_key=apikey, token=token, password=password, tenant_id=first_exists(args.tenant, os.environ.get("LAVA_TENANT_NAME"), os.environ.get("OS_TENANT_NAME")), region=first_exists(args.region, os.environ.get("LAVA_REGION_NAME"), os.environ.get("OS_REGION_NAME")), auth_url=first_exists(args.auth_url, os.environ.get("LAVA_AUTH_URL"), os.environ.get("OS_AUTH_URL")), endpoint=first_exists(args.endpoint, os.environ.get("LAVA2_API_URL"), os.environ.get("LAVA_API_URL")), verify_ssl=args.verify_ssl, timeout=first_exists(args.request_timeout, os.environ.get("LAVA_TIMEOUT")), max_retries=first_exists(args.retries, os.environ.get("LAVA_RETRIES")), retry_backoff=first_exists(args.retry_backoff, os.environ.get("LAVA_RETRY_BACKOFF")), _cli_args=args, ) except LavaError as exc: six.print_("Error during authentication: {0}".format(exc), file=sys.stderr) if args.debug: raise sys.exit(1)
def create_client(args): """ Create instance of Lava from CLI args """ resource = args.resource if resource == 'shell': args.enable_cli = False apikey = first_exists(args.lava_api_key, os.environ.get('LAVA_API_KEY'), os.environ.get('OS_API_KEY')) token = first_exists(args.token, os.environ.get('LAVA_AUTH_TOKEN'), os.environ.get('AUTH_TOKEN')) user = first_exists(args.user, os.environ.get('LAVA_USERNAME'), os.environ.get('OS_USERNAME'), getpass.getuser()) password = first_exists(args.password, os.environ.get('LAVA_PASSWORD'), os.environ.get('OS_PASSWORD')) if not any((apikey, token, password)): if args.headless: six.print_('Error: no API key, token, or password specified', file=sys.stderr) sys.exit(1) else: password = getpass.getpass('Password for {0}: '.format(user)) try: return Lava(user, api_key=apikey, token=token, password=password, tenant_id=first_exists(args.tenant, os.environ.get('LAVA_TENANT_NAME'), os.environ.get('OS_TENANT_NAME')), region=first_exists(args.region, os.environ.get('LAVA_REGION_NAME'), os.environ.get('OS_REGION_NAME')), auth_url=first_exists(args.auth_url, os.environ.get('LAVA_AUTH_URL'), os.environ.get('OS_AUTH_URL')), endpoint=first_exists(args.endpoint, os.environ.get('LAVA2_API_URL'), os.environ.get('LAVA_API_URL')), verify_ssl=args.verify_ssl, timeout=first_exists(args.request_timeout, os.environ.get('LAVA_TIMEOUT')), max_retries=first_exists(args.retries, os.environ.get('LAVA_RETRIES')), retry_backoff=first_exists( args.retry_backoff, os.environ.get('LAVA_RETRY_BACKOFF')), _cli_args=args) except LavaError as exc: six.print_('Error during authentication: {0}'.format(exc), file=sys.stderr) if args.debug: raise sys.exit(1)