-
Notifications
You must be signed in to change notification settings - Fork 0
/
ceilometer_events.py
38 lines (30 loc) · 971 Bytes
/
ceilometer_events.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
#!/usr/bin/env python
import requests #http://docs.python-requests.org/en/latest
import json
KEYSTONE_URL = 'http://controller01:5000/v2.0/'
TENANT = 'demo'
USERNAME = 'demo'
PASSWORD = 'secret'
r = requests.post("%s/tokens"% (KEYSTONE_URL,), json={
"auth": {
"tenantName": TENANT,
"passwordCredentials": {
"username": USERNAME,
"password": PASSWORD,
}
}
})
if r.ok:
token = r.json()['access']['token']['id']
else:
raise Exception(r.text)
# Place the token in the X-Auth-Token header
headers = {'X-Auth-Token': token}
# Find the link to the Heat API in the service catalog:
for service in r.json()['access']['serviceCatalog']:
if service['type'] == 'metering':
# There may be more than one endpoint, but we'll take the first
metering_endpoint = service['endpoints'][0]['publicURL']
events = requests.get("%s/v2/events"% (metering_endpoint,), headers=headers)
for e in events.json():
print e['event_type']