forked from bloomberg/hackathon-aws-cluster
-
Notifications
You must be signed in to change notification settings - Fork 1
/
launch-vpc-student.py
executable file
·85 lines (69 loc) · 3.25 KB
/
launch-vpc-student.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/python
from __future__ import print_function
import sys
import boto3
import concurrent.futures
region = 'eu-west-1'
studentNodeImageId = 'ami-88aef7fb'
controlNodeInstanceType = 'm3.xlarge'
controlNodeDiskSize = '16'
workerNodeInstanceType = 'm3.large'
workerNodeDiskSize = '16'
argc = len(sys.argv) - 1
if argc == 1:
start = int(sys.argv[1])
end = start
elif argc == 2:
start = int(sys.argv[1])
end = int(sys.argv[2])
else:
print("One or two arguments must be supplied.")
sys.exit()
def launch_student(studentNumber):
print('Creating VPC stack for student', studentNumber)
stackName = 'student-' + studentNumber
st = cf.create_stack(StackName = stackName,
TemplateBody = studentTemplate,
Parameters = [
{ "ParameterKey": "KeyName", "ParameterValue": keyName },
{ "ParameterKey": "Bucket", "ParameterValue": bucket },
{ "ParameterKey": "IamProfile", "ParameterValue": iamProfile },
{ "ParameterKey": "ControlInstanceType", "ParameterValue": controlNodeInstanceType },
{ "ParameterKey": "ControlDiskSize", "ParameterValue": controlNodeDiskSize },
{ "ParameterKey": "WorkerInstanceType", "ParameterValue": workerNodeInstanceType },
{ "ParameterKey": "WorkerDiskSize", "ParameterValue": workerNodeDiskSize },
{ "ParameterKey": "ImageId", "ParameterValue": studentNodeImageId },
{ "ParameterKey": "SubnetNumber", "ParameterValue": studentNumber },
{ "ParameterKey": "VpcId", "ParameterValue": vpcId },
{ "ParameterKey": "SecGroupAccess", "ParameterValue": secGroupAccess },
{ "ParameterKey": "RouteTable", "ParameterValue": privateRouteTable }
]
)
stwaiter = cf.get_waiter('stack_create_complete')
return (stackName, stwaiter)
def wait_on_stack(t):
t[1].wait(StackName = t[0])
print("Stack", t[0], "complete")
cf = boto3.client(region_name = region, service_name = 'cloudformation')
st = cf.describe_stacks(StackName = 'jepsen')
outputs = st['Stacks'][0]['Outputs']
for out in outputs:
if out['Description'] == 'PrivateRouteTable':
privateRouteTable = out['OutputValue']
elif out['Description'] == 'VpcId':
vpcId = out['OutputValue']
elif out['Description'] == 'SecGroupAccess':
secGroupAccess = out['OutputValue']
elif out['Description'] == 'KeyName':
keyName = out['OutputValue']
elif out['Description'] == 'Bucket':
bucket = out['OutputValue']
elif out['Description'] == 'IamProfile':
iamProfile = out['OutputValue']
with open('jepsen-vpc-student.json', 'r') as template_file:
studentTemplate = template_file.read()
with concurrent.futures.ThreadPoolExecutor(max_workers = (end - start) + 1) as executor:
fs = { executor.submit(wait_on_stack, launch_student(str(x))) for x in range(start, end + 1) }
print('Waiting for stack creation to be complete...')
concurrent.futures.wait(fs)
print('Stack creation complete')