-
Notifications
You must be signed in to change notification settings - Fork 5
/
keystone_example.py
67 lines (53 loc) · 1.9 KB
/
keystone_example.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
import os
import sys
import argparse
import keystoneclient.v2_0.client as ksclient
# Import code common to all of the examples.
import common
def get_keystone_client(os_username=None,
os_password=None,
os_tenant_name=None,
os_tenant_id=None,
os_auth_url=None
):
'''Returns a keystone client. Other examples that need an
authenticated keystone client can simply:
import common
import keystone_example
parser = common.create_parser()
args = parser.parse_args()
client = get_keystone_client(
os_username=args.os_username,
os_password=args.os_password,
os_tenant_name=args.os_tenant_name,
os_tenant_id=args.os_tenant_id,
os_auth_url=args.os_auth_url
)
'''
return ksclient.Client(username=os_username,
password=os_password,
tenant_name=os_tenant_name,
tenant_id=os_tenant_id,
auth_url=os_auth_url)
def parse_args():
p = common.create_parser()
return p.parse_args()
def main():
args = parse_args()
client = get_keystone_client(
os_username=args.os_username,
os_password=args.os_password,
os_tenant_name=args.os_tenant_name,
os_tenant_id=args.os_tenant_id,
os_auth_url=args.os_auth_url
)
# Iterate through the service catalog and display all endpoint
# URLs for all services.
for endpoint_type, endpoints in client.service_catalog.get_endpoints().items():
print endpoint_type
for i, endpoint in enumerate(endpoints):
for url in ['adminURL', 'internalURL', 'publicURL']:
print ' ', i, url, endpoint[url]
if __name__ == '__main__':
main()