This repository was archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstacker.py
More file actions
41 lines (34 loc) · 1.29 KB
/
stacker.py
File metadata and controls
41 lines (34 loc) · 1.29 KB
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
import os
import credentials
import heatclient.client
import resource
class Stacker:
def __init__(self):
if not os.environ.get('OS_HEAT_URL'):
print("ERROR: $OS_HEAT_URL variable not set!")
print("Use this as an example: OS_HEAT_URL=https://compute.datacentred.io:8004/v1/`echo $OS_PROJECT_ID`")
exit(1)
# get a token
creds = credentials.Credentials()
token = creds.get_token()
self.heat = heatclient.client.Client(1,
endpoint=os.environ['OS_HEAT_URL'],
token=token)
def get_stacks(self):
return self.heat.stacks.list()
def get_resources_in_stack(self, stack_id):
# original resources from the stack
stack_resources = self.heat.resources.list(stack_id = stack_id)
# a list of simpler Resource objects
resources = [ resource.Resource(res.physical_resource_id, res.resource_type) for res in stack_resources ]
return resources
def main():
stacker = Stacker()
stacks = stacker.get_stacks()
for stack in stacks:
print( stack )
resources = stacker.get_resources_in_stack(stack.id)
for res in resources:
print res
if __name__ == "__main__":
main()