-
Notifications
You must be signed in to change notification settings - Fork 3
/
keystone_auth.py
42 lines (30 loc) · 1.2 KB
/
keystone_auth.py
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
from const import *
from keystoneauth1.identity import v2
from keystoneauth1 import session
from keystoneclient.v2_0 import client
# http://docs.openstack.org/developer/python-keystoneclient/using-api-v2.html
def authenticate():
auth_url = '{PROTO}://{HOST}:{IDENTITY_PORT}/v2.0'.format(**CONNECTION)
auth = v2.Password(auth_url=auth_url,
username=USERNAME,
password=PASSWORD,
tenant_name=TENANT,
)
return session.Session(auth=auth)
if __name__ == '__main__':
session = authenticate()
keystone = client.Client(session=session)
print(' TOKEN: {0}'.format(session.get_token()))
print('-SERVICE CATALOG-')
for service in keystone.services.list():
print('--')
print("NAME: {0}".format(service.name))
print("TYPE: {0}".format(service.type))
# keystone.projects.list()
# glance_service = keystone.services.create(name="glance",
# service_type="image",
# description="OpenStack Image Service")
# tenant = [t for t in keystone.tenants.list() if t.name=='demo'][0]
# new_user = keystone.users.create(name="new_user",
# password="secret",
# tenant_id=tenant.id)