-
Notifications
You must be signed in to change notification settings - Fork 10
/
cep.py
140 lines (120 loc) · 5.71 KB
/
cep.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
from __future__ import print_function
import sys, subprocess, string,cStringIO, cgi,time,datetime,json
from os import curdir, sep
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from urlparse import urlparse, parse_qs
logfile = open('./cep.log', 'w')
logfile.truncate()
def execute(cmd):
logfile = open('./cep.log', 'w')
popen = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
for stdout_line in iter(popen.stdout.readline, ""):
logfile.write(stdout_line)
yield stdout_line
popen.stdout.close()
logfile.close()
return_code = popen.wait()
if return_code:
raise subprocess.CalledProcessError(return_code, cmd)
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
try:
if self.path.endswith(".html"):
f = open(curdir + sep + self.path)
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
self.wfile.write(f.read())
f.close()
return
if '/getdata' in self.path:
target = open('./data.json', 'r')
self.send_response(200)
self.send_header('Content-type','application/json')
self.end_headers()
query_components = parse_qs(urlparse(target.read()).query)
print(query_components)
self.wfile.write(json.dumps(query_components))
target.close()
return
if '/uninstall' in self.path:
print(self.path)
query_components = parse_qs(urlparse(self.path).query)
if 'NeedLVM' not in query_components:
return
needLvm = query_components["NeedLVM"][0]
lvmVol = ''
if 'LVMVolume' in query_components.keys():
lvmVol = query_components["LVMVolume"][0]
nfsReqd = query_components["NFSReqd"][0]
nfsDir = ''
if 'NFSDir' in query_components.keys():
nfsDir = query_components["NFSDir"][0]
domainName = query_components["DomainName"][0]
cepFolder = query_components["CEPFolder"][0]
gitlab = query_components["InstallGitlab"][0]
cepUi = query_components["CEPUI"][0]
cepMon = query_components["CEPMon"][0]
grayLog = query_components["GrayLog"][0]
cmd='no_proxy=localhost,127.0.0.1,registry.' + domainName + ' ANSIBLE_SCP_IF_SSH=y ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook --flush-cache CEP_Uninstall.yml -i Inventory_CEP --extra-vars "CONFIRM=yes DomainName=' + domainName + ' DirectLVMstorage=' + needLvm + ' setupNFS=' + nfsReqd + ' nfsSharePath=' + nfsDir + ' cepfolder=' + cepFolder + '"'
print(cmd)
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
self.wfile.write("<h1>Time for a coffee! Uninstalling CEP...Check console for progress!</h1>")
self.wfile.write("<h3>Command that will be run:</h3>")
self.wfile.write("<h4>" + cmd + "</h4>")
for path in execute([cmd]):
print(path, end="")
return
if '/install' in self.path:
target = open('./data.json', 'w')
target.truncate()
target.write(self.path)
target.close()
query_components = parse_qs(urlparse(self.path).query)
if 'NeedLVM' not in query_components:
return
needLvm = query_components["NeedLVM"][0]
lvmVol = ''
if 'LVMVolume' in query_components.keys():
lvmVol = query_components["LVMVolume"][0]
nfsReqd = query_components["NFSReqd"][0]
nfsDir = ''
if 'NFSDir' in query_components.keys():
nfsDir = query_components["NFSDir"][0]
domainName = query_components["DomainName"][0]
cepFolder = query_components["CEPFolder"][0]
gitlab = query_components["InstallGitlab"][0]
cepUi = query_components["CEPUI"][0]
cepMon = query_components["CEPMon"][0]
grayLog = query_components["GrayLog"][0]
cmd='no_proxy=localhost,127.0.0.1,registry.' + domainName + ' ANSIBLE_SCP_IF_SSH=y ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook --flush-cache CEP_Install.yml -i Inventory_CEP --extra-vars "DomainName=' + domainName + ' cepfolder=' + cepFolder + ' InstallGitlab=' + gitlab +' cepUI=' + cepUi + ' cepmon=' + cepMon + ' cepGraylog=' + grayLog + ' DirectLVMstorage=' + needLvm + ' setupNFS=' + nfsReqd + ' nfsSharePath=' + nfsDir + ' Docker_storage_devs=' + lvmVol + '"'
print(cmd)
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
self.wfile.write("<h1>Time for a coffee! Setting up CEP...Check console for progress!</h1>")
self.wfile.write("<h3>Command that will be run:</h3>")
self.wfile.write("<h4>" + cmd + "</h4>")
for path in execute([cmd]):
print(path, end="")
return
return
except IOError:
self.send_error(404,'File Not Found: %s' % self.path)
if __name__ == "__main__":
try:
server = HTTPServer(('0.0.0.0', 9090), MyHandler)
print('Started http server.')
print('')
print('For CEP installer UI, go to http://<this_host>:9090/index.html')
print('')
print('')
print('Press ^C to shut down this server.')
print('')
print('')
server.serve_forever()
except KeyboardInterrupt:
print('^C received, shutting down server')
server.socket.close()