Exemple #1
0
def get_client(host,
               port=None,
               timeout=None,
               use_ssl=False,
               username=None,
               password=None,
               project=None,
               user_domain_id=None,
               project_domain_id=None,
               auth_url=None,
               auth_strategy=None,
               auth_token=None,
               region=None,
               insecure=False):
    """
    Returns a new client Glance client object based on common kwargs.
    If an option isn't specified falls back to common environment variable
    defaults.
    """

    if auth_url or os.getenv('OS_AUTH_URL'):
        force_strategy = 'keystone'
    else:
        force_strategy = None

    creds = {
        'username':
        username or os.getenv('OS_AUTH_USER', os.getenv('OS_USERNAME')),
        'password':
        password or os.getenv('OS_AUTH_KEY', os.getenv('OS_PASSWORD')),
        'project':
        project or os.getenv('OS_AUTH_PROJECT', os.getenv('OS_PROJECT_NAME')),
        'auth_url':
        auth_url or os.getenv('OS_AUTH_URL'),
        'strategy':
        force_strategy or auth_strategy
        or os.getenv('OS_AUTH_STRATEGY', 'noauth'),
        'region':
        region or os.getenv('OS_REGION_NAME'),
        'user_domain_id':
        user_domain_id or os.getenv('OS_USER_DOMAIN_ID', 'default'),
        'project_domain_id':
        project_domain_id or os.getenv('OS_PROJECT_DOMAIN_ID', 'default')
    }

    if creds['strategy'] == 'keystone' and not creds['auth_url']:
        msg = _("--os_auth_url option or OS_AUTH_URL environment variable "
                "required when keystone authentication strategy is enabled\n")
        raise exception.ClientConfigurationError(msg)

    return CacheClient(host=host,
                       port=port,
                       timeout=timeout,
                       use_ssl=use_ssl,
                       auth_token=auth_token or os.getenv('OS_TOKEN'),
                       creds=creds,
                       insecure=insecure,
                       configure_via_auth=False)
Exemple #2
0
def get_client(host,
               port=None,
               timeout=None,
               use_ssl=False,
               username=None,
               password=None,
               tenant=None,
               auth_url=None,
               auth_strategy=None,
               auth_token=None,
               region=None,
               is_silent_upload=False,
               insecure=False):
    """
    Returns a new client Glance client object based on common kwargs.
    If an option isn't specified falls back to common environment variable
    defaults.
    """

    if auth_url or os.getenv('OS_AUTH_URL'):
        force_strategy = 'keystone'
    else:
        force_strategy = None

    creds = dict(
        username=username
        or os.getenv('OS_AUTH_USER', os.getenv('OS_USERNAME')),
        password=password
        or os.getenv('OS_AUTH_KEY', os.getenv('OS_PASSWORD')),
        tenant=tenant
        or os.getenv('OS_AUTH_TENANT', os.getenv('OS_TENANT_NAME')),
        auth_url=auth_url or os.getenv('OS_AUTH_URL'),
        strategy=force_strategy or auth_strategy
        or os.getenv('OS_AUTH_STRATEGY', 'noauth'),
        region=region or os.getenv('OS_REGION_NAME'),
    )

    if creds['strategy'] == 'keystone' and not creds['auth_url']:
        msg = ("--os_auth_url option or OS_AUTH_URL environment variable "
               "required when keystone authentication strategy is enabled\n")
        raise exception.ClientConfigurationError(msg)

    client = (ProgressClient if not is_silent_upload else Client)

    return client(host=host,
                  port=port,
                  timeout=timeout,
                  use_ssl=use_ssl,
                  auth_tok=auth_token or os.getenv('OS_TOKEN'),
                  creds=creds,
                  insecure=insecure)