forked from DSPN/oracle-public-cloud-dse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
299 lines (236 loc) · 10.8 KB
/
main.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
import json
import copy
import nodes
ip_pool = []
ip_address_list = {}
storage_pool = {}
# Open file for reading pre-allocated static IP addresses
with open('cassandra_ip_pool.txt', 'r') as inputFile:
ip_pool = json.load(inputFile)
# Open file for reading DSE cluster deployment template
with open('clusterParameters.json') as inputFile:
clusterParameters = json.load(inputFile)
# Setting deployment variables
locations = clusterParameters['locations']
vmType = clusterParameters['vmType']
nodeCount = clusterParameters['nodeCount']
OPC_USER = clusterParameters['OPC_USER']
OPC_DOMAIN = clusterParameters['OPC_DOMAIN']
networkPrefix = clusterParameters['networkPrefix']
osImage = clusterParameters['osImage']
securityList = clusterParameters['securityList']
securityRules = clusterParameters['securityRules']
sshKey = clusterParameters['sshKey']
bootDriveSizeInBytes = clusterParameters['bootDriveSizeInBytes']
appDataDriveSizeInBytes = clusterParameters['appDataDriveSizeInBytes']
# Retrieve IP addresses from Oracle Cloud and insert them into a dictionary
with open('ipListWithoutHeader.txt', 'r') as inputFile:
for line in inputFile:
splitLine = line.split()
ip_address_list[splitLine[0]] = splitLine[1]
# We will use "dse_secList" as the security list
generatedTemplateForSecurityList = {
"description": "Plan to create security list",
"name": OPC_USER + "/DataStax_Security_Lists_Plan",
"oplans": [
{
"label": "admin-seclists",
"obj_type": "seclist",
"objects": [
{
"name": OPC_USER + "/" + securityList
}
]
}
]
}
# We will use "DSE_Rules" as the security Rules
generatedTemplateForSecurityRules = {
"description": "Plan to create security rules",
"name": OPC_USER + "/DataStax_Security_Rules_Plan",
"oplans": [
{
"label": "DSE_Security_Rules",
"obj_type": "secrule",
"objects": [
{
"name": OPC_USER + "/" + securityRules,
"application": "/oracle/public/all",
"src_list": "seciplist:/oracle/public/public-internet",
"dst_list": "seclist:" + OPC_USER + "/DSE_Seclist",
"action": "PERMIT"
}
]
}
]
}
# Boilerplate orchestration template for static IP address provisioning
generatedTemplateForIPs = {
"description": "Plan to create static IP addresses for DataStax node",
"name": OPC_USER + "/DataStax_IP_Reservation_Plan",
"oplans": [
{
"label": "DSE IP Reservation",
"obj_type": "ip/reservation",
"objects": []
}
]
}
# Boilerplate orchestration template for storage provisioning
generatedTemplateForStorage = {
"description": "Plan to create storage volumnes for DataStax node",
"name": OPC_USER + "/DataStax_Storage_Plan",
"oplans": [
{
"label": "DSE storage volumes",
"obj_type": "storage/volume",
"objects": []
}
]
}
# Boilerplate orchestration template for instance provisioning
generatedTemplateForInstance = {
"description": "Plan to deploy OCC instance for DataStax node",
"name": OPC_USER + "/DataStax_Instance_Plan",
"oplans": [
{
"obj_type": "launchplan",
"ha_policy": "active",
"label": "DataStax_Instance_Plan",
"objects": [{"instances": []}]
}
]
}
# Boilerplate orchestration template for Master orhcestration plan
# This will combine storage and instance provisioning in sequence
generatedTemplateForMaster = {
"description": "Master plan to spin up a DataStax node",
"name": OPC_USER + "/DataStax_Master_Plan",
"relationships": [
{
"to_oplan": "DataStax_Storage_Plan",
"oplan": "DataStax_Instance_Plan",
"type": "depends"
}
],
"oplans": [
{
"label": "DataStax_Storage_Plan",
"obj_type": "orchestration",
"objects": [
{
"name": OPC_USER + "/DataStax_Storage_Plan"
}
]
},
{
"label": "DataStax_Instance_Plan",
"obj_type": "orchestration",
"objects": [
{
"name": OPC_USER + "/DataStax_Instance_Plan"
}
]
}
]
}
# Provision security lists
with open('generatedTemplateForSecurityList.json', 'w') as outputFile:
json.dump(generatedTemplateForSecurityList, outputFile, indent=4, ensure_ascii=False)
# Provision security rules
with open('generatedTemplateForSecurityRules.json', 'w') as outputFile:
json.dump(generatedTemplateForSecurityRules, outputFile, indent=4, ensure_ascii=False)
# Populate storage pool dictionary with item => (location: (boot_vol, app_data_vol))
for location, api_endpoint in locations.items():
for nodeCounter in range(0, nodeCount):
boot_vol_name = location + ".boot_vol." + str(nodeCounter)
app_data_vol_name = location + ".app_data_vol." + str(nodeCounter)
storage_pool[location] = storage_pool.get(location, []) + [[boot_vol_name, app_data_vol_name]]
#### Provision OpsCenter instance
# Provision OpsCenter storage volumes
boot_vol_name = "opscenter.boot_vol"
app_data_vol_name = "opscenter.app_data_vol"
storage_pool['opscenter'] = [[boot_vol_name, app_data_vol_name]]
resources = nodes.generateStorageVols(OPC_USER, osImage, boot_vol_name, app_data_vol_name,
bootDriveSizeInBytes, appDataDriveSizeInBytes)
storageTemplate = copy.deepcopy(generatedTemplateForStorage)
storageTemplate['oplans'][0]['objects'].append(resources[0])
storageTemplate['oplans'][0]['objects'].append(resources[1])
# Provision cloud vm instance for OpsCenter
hostname = "dse.ent.host.opscenter"
opscenter_ip_label = ip_pool.pop()
opscenter_node_ip_addr = ip_address_list[opscenter_ip_label]
# Pick the first IP in ip_pool as the Cassandra seed node IP
seed_node_ip_addr = ip_address_list[ip_pool[0]]
resources = nodes.generateInstanceOpsCenter(OPC_DOMAIN, OPC_USER, sshKey, vmType, securityList, hostname,
storage_pool['opscenter'][0][0], storage_pool['opscenter'][0][1],
opscenter_ip_label, seed_node_ip_addr)
instanceTemplate = copy.deepcopy(generatedTemplateForInstance)
instanceTemplate['oplans'][0]['objects'][0]['instances'].append(resources)
# Set unique orchestration plans name for OpsCenter provisioning
ops_center_storage_plan = OPC_USER + "/DataStax_Storage_Plan_OpsCenter"
ops_center_instance_plan = OPC_USER + "/DataStax_Instance_Plan_OpsCenter"
ops_center_master_plan = OPC_USER + "/DataStax_Master_Plan_OpsCenter"
storageTemplate['name'] = ops_center_storage_plan
instanceTemplate['name'] = ops_center_instance_plan
# Generate storage orchestration plan for OpsCenter
with open('generatedTemplateForStorage_OpsCenter.json', 'w') as outputFile:
json.dump(storageTemplate, outputFile, indent=4, ensure_ascii=False)
# Generate instance orchestration plan for OpsCenter
with open('generatedTemplateForInstance_OpsCenter.json', 'w') as outputFile:
json.dump(instanceTemplate, outputFile, indent=4, ensure_ascii=False)
# Generate master orchestration plan to spin up the DataStax Enterprise OpsCenter
masterTemplate = copy.deepcopy(generatedTemplateForMaster)
masterTemplate['name'] = ops_center_master_plan
masterTemplate['oplans'][0]['objects'][0]['name'] = ops_center_storage_plan
masterTemplate['oplans'][1]['objects'][0]['name'] = ops_center_instance_plan
with open('generatedTemplateForMaster_OpsCenter.json', 'w') as outputFile:
json.dump(masterTemplate, outputFile, indent=4, ensure_ascii=False)
#### Provision DSE nodes
# Provision cloud vm instance for DSE nodes
index = 0
for location, storage_vols in storage_pool.items():
# there is only one opscenter in our environment
storageTemplate = copy.deepcopy(generatedTemplateForStorage)
instanceTemplate = copy.deepcopy(generatedTemplateForInstance)
masterTemplate = copy.deepcopy(generatedTemplateForMaster)
if location != 'opscenter':
for storage_disks in storage_vols:
## Initialize orchestration templates and create unique plans
storageTemplate = copy.deepcopy(generatedTemplateForStorage)
instanceTemplate = copy.deepcopy(generatedTemplateForInstance)
masterTemplate = copy.deepcopy(generatedTemplateForMaster)
storage_plan = OPC_USER + "/DataStax_Storage_Plan_DSE_" + str(index)
instance_plan = OPC_USER + "/DataStax_Instance_Plan_DSE_" + str(index)
master_plan = OPC_USER + "/DataStax_Master_Plan_DSE_" + str(index)
## Generate a hostname
hostname = "dse.ent.host." + location + "." + str(index)
## Create storage orchestration template
boot_vol_name = storage_disks[0]
app_data_vol_name = storage_disks[1]
resources = nodes.generateStorageVols(OPC_USER, osImage, boot_vol_name, app_data_vol_name,
bootDriveSizeInBytes, appDataDriveSizeInBytes)
storageTemplate['oplans'][0]['objects'].append(resources[0])
storageTemplate['oplans'][0]['objects'].append(resources[1])
storageTemplate['name'] = storage_plan
# Generate storage orchestration plan
with open('generatedTemplateForStorage_DSE_' + str(index) + '.json', 'w') as outputFile:
json.dump(storageTemplate, outputFile, indent=4, ensure_ascii=False)
## Create instance orchestratoin template
resources = nodes.generateInstanceNode(OPC_DOMAIN, OPC_USER, location, sshKey, vmType, securityList,
hostname,
storage_disks[0], storage_disks[1], ip_pool.pop(),
seed_node_ip_addr, opscenter_node_ip_addr)
instanceTemplate['oplans'][0]['objects'][0]['instances'].append(resources)
instanceTemplate['name'] = instance_plan
# Generate instance orchestration plan
with open('generatedTemplateForInstance_DSE_' + str(index) + '.json', 'w') as outputFile:
json.dump(instanceTemplate, outputFile, indent=4, ensure_ascii=False)
## Create master orchestration template
masterTemplate['name'] = master_plan
masterTemplate['oplans'][0]['objects'][0]['name'] = storage_plan
masterTemplate['oplans'][1]['objects'][0]['name'] = instance_plan
# Generate master orchestration plan
with open('generatedTemplateForMaster_DSE_' + str(index) + '.json', 'w') as outputFile:
json.dump(masterTemplate, outputFile, indent=4, ensure_ascii=False)
index += 1