-
Notifications
You must be signed in to change notification settings - Fork 5
/
gen_inv.py
68 lines (57 loc) · 1.91 KB
/
gen_inv.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
import json
import sys
string = sys.stdin.read()
res = json.loads(string)
def get_name(tags):
for obj in tags:
key = obj["Key"]
if key == "Name":
return obj["Value"]
raise Error("invalid key")
hosts = {}
for reservation in res["Reservations"]:
instances = reservation["Instances"]
for instance in instances:
if (instance["State"]["Name"] != "running"):
continue
name = get_name(instance["Tags"])
print(name)
ip = instance["PrivateIpAddress"]
pub = instance["PublicDnsName"]
hosts[name] = {}
hosts[name]["ip"] = ip
hosts[name]["pub"] = pub
hosts[name]["id"] = instance["InstanceId"]
print (hosts)
with open("awsinv", 'w') as f:
f.write ("[host0]\n")
if (len(hosts["node-0"]["pub"]) > 0):
f.write("ubuntu@")
f.write(hosts["node-0"]["pub"])
f.write ("\n[host1]\n")
if (len(hosts["node-1"]["pub"]) > 0):
f.write("ubuntu@")
f.write(hosts["node-1"]["pub"])
f.write ("\n[host2]\n")
if (len(hosts["node-2"]["pub"]) > 0):
f.write("ubuntu@")
f.write(hosts["node-2"]["pub"])
f.write ("\n[host3]\n")
if (len(hosts["node-3"]["pub"]) > 0):
f.write("ubuntu@")
f.write(hosts["node-3"]["pub"])
f.write ("\n")
with open("config/config_aws_generated.yaml", 'w') as f:
f.write("num_replicas: 4\n\n")
f.write("replica_0:\n sk_seed: 1\n hostname: \"")
f.write(hosts["node-0"]["ip"])
f.write("\"\n\n")
f.write("replica_1:\n sk_seed: 2\n hostname: \"")
f.write(hosts["node-1"]["ip"])
f.write("\"\n\n")
f.write("replica_2:\n sk_seed: 3\n hostname: \"")
f.write(hosts["node-2"]["ip"])
f.write("\"\n\n")
f.write("replica_3:\n sk_seed: 4\n hostname: \"")
f.write(hosts["node-3"]["ip"])
f.write("\"\n\n")