xsnippet logotype

xsnippet

#362552, Untitled [ Python ]

by Guest
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from keystoneauth1 import discover
from keystoneauth1 import identity
from keystoneauth1 import session

OS_AUTH_URL = 'https://cci06-ostctrl-oc.cloud.internal:35357/v3'
OS_USERNAME = 'admin'
OS_PASSWORD = 'XXXXXXXXXX'
OS_PROJECT_NAME = 'LinuxEng'
OS_REGION_NAME = 'CCI06'
OS_INTERFACE = 'public'
OS_CACERT = '/etc/pki/CA/certs/CA.pem'
OS_USER_DOMAIN_NAME = 'default'
OS_PROJECT_DOMAIN_NAME = 'LinuxEng'

password_args = {
    "auth_url": OS_AUTH_URL,
    "username": OS_USERNAME,
    "password": OS_PASSWORD,
    "tenant_name": OS_PROJECT_NAME
}

# NOTE(rvasilets): If version not specified than we discover
# available version with the smallest number. To be able to
# discover versions we need session
temp_session = session.Session(verify=True, timeout=300)
version = str(discover.Discover(
    temp_session,
    password_args["auth_url"]).version_data()[0]["version"][0])

print("Discovered version: %s" % version)

if "v2.0" not in password_args["auth_url"] and (
        version != "2"):
    password_args.update({
        "user_domain_name": OS_USER_DOMAIN_NAME,
        "domain_name": None,
        "project_domain_name": OS_PROJECT_DOMAIN_NAME,
    })
identity_plugin = identity.Password(**password_args)
sess = session.Session(
    auth=identity_plugin,
    verify=True,
    timeout=300)

auth_ref = identity_plugin.get_access(sess)

print("Roles list of the user: %s" % auth_ref.role_names)