This repository has been archived by the owner on May 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
generator.py
103 lines (91 loc) · 3.38 KB
/
generator.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import sys
import yaml
import json
def main():
filename=sys.argv[1]
print('Using parameter file: ' + filename)
with open(filename, 'r') as stream:
parameters = yaml.load(stream)
print('Parameters: ' + str(parameters))
serverVersion = parameters['serverVersion']
syncGatewayVersion = parameters['syncGatewayVersion']
cluster = parameters['cluster']
module = generateCluster(serverVersion, syncGatewayVersion, cluster)
file = open('generated.tf', 'w')
file.write(module)
file.close()
def generateCluster(serverVersion, syncGatewayVersion, cluster):
module = ''
rallyGroup=cluster[0]['group']
for group in cluster:
module = module + generateGroup(serverVersion, syncGatewayVersion, group, rallyGroup)
return module
def generateGroup(serverVersion, syncGatewayVersion, group, rallyGroup):
if 'syncGateway' in group['services']:
return generateSyncGateway(syncGatewayVersion, group, rallyGroup)
else:
return generateServer(serverVersion, group, rallyGroup)
def generateSyncGateway(syncGatewayVersion, group, rallyGroup):
groupName = group['group']
nodeCount = group['nodeCount']
nodeType = group['nodeType']
module = '\n\
resource "oci_core_instance" "' + groupName + '" {\n\
display_name = "' + groupName + '"\n\
compartment_id = "${var.compartment_ocid}"\n\
availability_domain = "${lookup(data.oci_identity_availability_domains.availability_domains.availability_domains[0],"name")}"\n\
shape = "' + nodeType +'"\n\
subnet_id = "${oci_core_subnet.subnet.id}"\n\
source_details {\n\
source_id = "${var.images[var.region]}"\n\
source_type = "image"\n\
}\n\
metadata {\n\
ssh_authorized_keys = "${var.ssh_public_key}"\n\
user_data = "${base64encode(format("%s\\n%s\\n%s\\n%s\\n%s\\n",\n\
"#!/bin/bash",\n\
"version=' + syncGatewayVersion + '",\n\
file("../scripts/syncgateway.sh")\n\
))}"\n\
}\n\
count = "' + str(nodeCount) +'"\n\
}\n\
'
return module
def generateServer(serverVersion, group, rallyAutoScalingGroup):
groupName = group['group']
nodeCount = group['nodeCount']
nodeType = group['nodeType']
dataDiskSize = group['dataDiskSize']
services = group['services']
servicesParameter=''
for service in services:
servicesParameter += service + ','
servicesParameter=servicesParameter[:-1]
module = '\
resource "oci_core_instance" "' + groupName + '" {\n\
display_name = "' + groupName + '"\n\
compartment_id = "${var.compartment_ocid}"\n\
availability_domain = "${lookup(data.oci_identity_availability_domains.availability_domains.availability_domains[0],"name")}"\n\
shape = "' + nodeType +'"\n\
subnet_id = "${oci_core_subnet.subnet.id}"\n\
source_details {\n\
source_id = "${var.images[var.region]}"\n\
source_type = "image"\n\
}\n\
metadata {\n\
ssh_authorized_keys = "${var.ssh_public_key}"\n\
user_data = "${base64encode(format("%s\\n%s\\n%s\\n%s\\n%s\\n%s\\n",\n\
"#!/bin/bash",\n\
"version=' + serverVersion + '",\n\
"adminUsername=${var.adminUsername}",\n\
"adminPassword=${var.adminPassword}",\n\
"services=' + servicesParameter + '",\n\
file("../scripts/server.sh")\n\
))}"\n\
}\n\
count = "' + str(nodeCount) +'"\n\
}\n\
'
return module
main()