def _token_to_keystone_scoped_project(
        auth_url, token,
        project_name, domain_name="default"):
    """
    Given an auth_url and scoped/unscoped token:
    Create an auth,session and token for a specific project_name and domain_name (Required to access a serviceCatalog for neutron/nova/etc!)
    """
    auth = v3.Token(auth_url=auth_url, token=token, project_name=project_name, project_domain_id=domain_name)
    sess = Session(auth=auth)
    token = sess.get_token()
    return (auth, sess, token)
Beispiel #2
0
def get_heat():
    keystone_auth = V2Password(auth_url=os.environ['OS_AUTH_URL'],
                               username=os.environ['OS_USERNAME'],
                               password=os.environ['OS_PASSWORD'],
                               tenant_name=os.environ['OS_TENANT_NAME'])
    session = KeystoneSession(auth=keystone_auth, verify=False)
    endpoint_url = session.get_endpoint(service_type='orchestration',
                                        endpoint_type='publicURL')
    heat = heatclient.Client(version='1',
                             endpoint=endpoint_url,
                             token=session.get_token())
    return heat
Beispiel #3
0
def _connect_to_keystone_auth_v3(auth_url, auth_token, project_name,
                                 domain_name, **kwargs):
    """
    Give a auth_url and auth_token,
    authenticate with keystone version 3 to get a scoped_token,
    Exchange token to receive an auth, session, token scoped to a sepcific project_name and domain_name.
    """
    token_auth = identity.Token(auth_url=auth_url,
                                token=auth_token,
                                project_domain_id=domain_name,
                                project_name=project_name)
    token_sess = Session(auth=token_auth)
    token_token = token_sess.get_token()
    return (token_auth, token_sess, token_token)
Beispiel #4
0
def _token_to_keystone_scoped_project(auth_url,
                                      token,
                                      project_name,
                                      domain_name="default"):
    """
    Given an auth_url and scoped/unscoped token:
    Create an auth,session and token for a specific project_name and domain_name (Required to access a serviceCatalog for neutron/nova/etc!)
    """
    auth = v3.Token(auth_url=auth_url,
                    token=token,
                    project_name=project_name,
                    project_domain_id=domain_name)
    sess = Session(auth=auth)
    token = sess.get_token()
    return (auth, sess, token)
def _connect_to_keystone_auth_v3(
        auth_url, auth_token, project_name, domain_name, **kwargs):
    """
    Give a auth_url and auth_token,
    authenticate with keystone version 3 to get a scoped_token,
    Exchange token to receive an auth, session, token scoped to a sepcific project_name and domain_name.
    """
    token_auth = identity.Token(
        auth_url=auth_url,
        token=auth_token,
        project_domain_id=domain_name,
        project_name=project_name)
    token_sess = Session(auth=token_auth)
    token_token = token_sess.get_token()
    return (token_auth, token_sess, token_token)
def _connect_to_keystone_password(
        auth_url, username, password,
        project_name, user_domain_name=None, project_domain_name=None, **kwargs):
    """
    Given a username and password,
    authenticate with keystone to get an unscoped token
    Exchange token to receive an auth,session,token scoped to a specific project_name and domain_name.
    """
    password_auth = identity.Password(
        auth_url=auth_url,
        username=username, password=password, project_name=project_name,
        user_domain_name=user_domain_name, project_domain_name=project_domain_name)
    password_sess = Session(auth=password_auth)
    password_token = password_sess.get_token()
    return (password_auth, password_sess, password_token)
Beispiel #7
0
def _connect_to_keystone_password(auth_url,
                                  username,
                                  password,
                                  project_name,
                                  user_domain_name=None,
                                  project_domain_name=None,
                                  **kwargs):
    """
    Given a username and password,
    authenticate with keystone to get an unscoped token
    Exchange token to receive an auth,session,token scoped to a specific project_name and domain_name.
    """
    password_auth = identity.Password(auth_url=auth_url,
                                      username=username,
                                      password=password,
                                      project_name=project_name,
                                      user_domain_name=user_domain_name,
                                      project_domain_name=project_domain_name)
    password_sess = Session(auth=password_auth)
    password_token = password_sess.get_token()
    return (password_auth, password_sess, password_token)
    loader = loading.get_plugin_loader(plugin)
    auth = loader.load_from_options(**auth_args)
    sess = Session(auth=auth)
    ks = client.Client(session=sess)
    # Available projects
    print('Available projects:')
    pprint(ks.auth.projects())
    print('Available domains:')
    domains = ks.auth.domains()
    if domains:
        pprint(domains)
    else:
        resp = sess.get('/auth/domains', endpoint_filter=endpoint_filter)
        print(json.dumps(resp.json(), indent=2))

    token = sess.get_token()
    token_data = ks.tokens.get_token_data(token=token, include_catalog=False)
    print('Token data:')
    print(json.dumps(token_data, indent=2))

    dname = 'dev'
    try:
        domain = ks.domains.get(dname)
        domain_id = None
    except NotFound:
        # Direct API
        resp = sess.get('/domains?name={}'.format(dname),
                        endpoint_filter=endpoint_filter)
        domain = resp.json()
        # For some strange reason, this is array
        domain_id = filter(lambda x: x['name'] == dname,