-
Notifications
You must be signed in to change notification settings - Fork 1
/
launch_scoreservers.py
executable file
·68 lines (52 loc) · 2.49 KB
/
launch_scoreservers.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
#!/usr/bin/env python
import tutum, sys, time, subprocess
import argparse
# Usage launch_scoreservers.py [num_nodes]
#
# Where num_nodes is how many c3.8xlarge machines you want launched.
# Each will have 32 containers running on it
#
parser = argparse.ArgumentParser(description='Launch a cluster if needed or requested, and some containers, to score games')
parser.add_argument('num_nodes', metavar='num_nodes', type=int,
help='number of actual machines to launch')
parser.add_argument('-f', dest='force', action='store_true')
parser.add_argument('-t', dest='tag', metavar='tag', help='tag to use on this cluster', required=True)
parser.set_defaults(force=False)
args = parser.parse_args()
tag = args.tag
CONTAINERS_PER_NODE = 1
MAX_CONTAINERS_PER_SERVICE = 10
num_nodes = args.num_nodes
# waiting for https://github.com/tutumcloud/api-docs/issues/17
#
#region = tutum.Region.fetch("aws/us-east-1")
#node_type = tutum.NodeType.fetch("aws/t2.micro")
#nodecluster = tutum.NodeCluster.create(name="this", node_type=node_type, region=region)
def msg(str):
print "%s %s" % (time.strftime('%Y%m%d-%H%M%S'), str)
nodecluster = None
nodeclusters = tutum.NodeCluster.list()
nodeclusters = [nc for nc in nodeclusters if nc.state not in ['Terminating', 'Terminated']]
if len(nodeclusters) == 0 or args.force:
msg("Launching cluster")
nodecluster = tutum.NodeCluster.create(name="scoreservers", node_type='/api/v1/nodetype/aws/c3.8xlarge/', region='/api/v1/region/aws/us-east-1/', target_num_nodes=num_nodes, tags=[{'name': tag}])
nodecluster.save()
else:
nodecluster = nodeclusters[0]
msg("Using nodecluster %s, current state %s" % (nodecluster.uuid, nodecluster.state) )
if nodecluster.state == 'Init':
nodecluster.deploy()
# is this next line needed or does deploy() do it for us?
nodecluster.state = 'Deploying'
if nodecluster.state == 'Deploying':
while tutum.NodeCluster.fetch(nodecluster.uuid).state != 'Deployed':
msg("Waiting for cluster %s to come up. State=%s, current_num_nodes=%s" % (nodecluster.uuid, nodecluster.state, nodecluster.current_num_nodes))
time.sleep(5)
num_containers = num_nodes * CONTAINERS_PER_NODE
num_services = num_containers / MAX_CONTAINERS_PER_SERVICE
if False:
services = []
for service_num in range(0, num_services):
msg("Launching service %d" % service_num)
subprocess.Popen(["./launch_ten_scorecontainers.py", str(service_num)])
print "Containers are up. Now launch services. Don't forget to kill someday."