-
Notifications
You must be signed in to change notification settings - Fork 0
/
orchestration.py
61 lines (53 loc) · 1.4 KB
/
orchestration.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
#!/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'] == 'orchestration':
heat_endpoint = service['endpoints'][0]['publicURL']
stack = requests.post("%s/stacks"% (heat_endpoint,), json={
"stack_name": "new_server",
"template": {
"heat_template_version": "2013-05-23",
"resources": {
"new_server_port": {
"type": "OS::Neutron::Port",
"properties": {
"network": "private"
}
},
"new_server": {
"type": "OS::Nova::Server",
"properties": {
"key_name": "demo",
"flavor": "m1.small",
"image": "cirros",
"networks": [ {
"port": {
"get_resource": "new_server_port"
}
} ]
}
}
}
}
}, headers=headers)