-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
81 lines (67 loc) · 2.81 KB
/
app.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
"""
This script runs the application using a development server.
"""
import bottle
import os
import sys
from bottle import route, run, response, request
import json
import opsCenter
import nodes
bottle.app().catchall = False
@route('/')
def hello():
response.headers['Content-Type'] = 'application/json'
# This python script generates an ARM template that deploys DSE across multiple datacenters.
with open('clusterParameters.json') as inputFile:
clusterParameters = json.load(inputFile)
locations = request.query['locations'].split(",")
vmSize = request.query['vmSize']
nodeCount = int(request.query['nodeCount'])
adminUsername = request.query['adminUsername']
adminPassword = request.query['adminPassword']
# This is the skeleton of the template that we're going to add resources to
generatedTemplate = {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {
"uniqueString": "[uniqueString(resourceGroup().id, deployment().name)]"
},
"resources": [],
"outputs": {
"opsCenterURL": {
"type": "string",
"value": "[concat('http://opscenter', variables('uniqueString'), '.', resourceGroup().location, '.cloudapp.azure.com:8888')]"
}
}
}
# Create DSE nodes in each location
for datacenterIndex in range(0, len(locations)):
location = locations[datacenterIndex]
resources = nodes.generate_template(location, datacenterIndex, vmSize, nodeCount, adminUsername, adminPassword, locations)
generatedTemplate['resources'] += resources
# Create the OpsCenter node
resources = opsCenter.generate_template(locations, nodeCount, adminUsername, adminPassword)
generatedTemplate['resources'] += resources
#return generatedTemplate
return json.dumps(generatedTemplate, sort_keys=True, indent=4, ensure_ascii=False)
#return locations
if '--debug' in sys.argv[1:] or 'SERVER_DEBUG' in os.environ:
# Debug mode will enable more verbose output in the console window.
# It must be set at the beginning of the script.
bottle.debug(True)
def wsgi_app():
"""Returns the application to make available through wfastcgi. This is used
when the site is published to Microsoft Azure."""
return bottle.default_app()
if __name__ == '__main__':
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static').replace('\\', '/')
HOST = os.environ.get('SERVER_HOST', 'localhost')
try:
PORT = int(os.environ.get('SERVER_PORT', '5555'))
except ValueError:
PORT = 5555
# Starts a local test server.
bottle.run(server='wsgiref', host=HOST, port=PORT)