-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
170 lines (135 loc) · 5.58 KB
/
server.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
import flask
import os
import subprocess
from subprocess import check_output as CO
app = flask.Flask(__name__)
app.config["DEBUG"] = True
@app.route('/', methods=['GET'])
def home():
res = subprocess.check_output(['ls'])
print(res)
return "<h1>"+ str(res) +"</h1><p>This site is a prototype API for distant reading of science fiction novels.</p>"
@app.route('/RBAC_init', methods=['GET'])
def RBAC_init():
try:
res = CO(['kubectl', 'create', '-f', './helm-rbac.yaml'])
except:
print("already initialised")
res = "already initialised"
print(res)
#res1 = CO(['helm', '-init', '--service-account-tiller'])
return res
@app.route('/helm_init', methods=['GET'])
def helm_init():
try:
res = CO(['helm', 'init', '--service-account', 'tiller'])
except:
print("already initialised")
res = "already initialised"
print(res)
#res1 = CO(['helm', '-init', '--service-account-tiller'])
return res
@app.route('/install_argo', methods=['GET'])
def install_argo():
try:
res = CO(['kubectl', 'create', 'namespace', 'argo'])
except Exception:
print("already created namespace argo")
res = Exception
finally:
print("install argo namespace output\n", res)
try:
res = CO(['kubectl', 'apply', '-n', 'argo', '-f', 'https://raw.githubusercontent.com/argoproj/argo/v2.4.3/manifests/install.yaml'])
except Exception:
print("something went wrong installing argo", Exception)
res="something went wrong installing argo"
finally:
print("install argo output\n", res)
#res1 = CO(['helm', '-init', '--service-account-tiller'])
return res
@app.route('/grant_admin_privilages', methods=['GET'])
def grant_admin_privilages():
try:
res = CO(['kubectl', 'create', 'rolebinding', 'default-admin', '--clusterrole=admin', '--serviceaccount=default:default'])
except Exception:
print("rolebinding already exists")
res = Exception
finally:
print("create admin role binding\n", res)
#res1 = CO(['helm', '-init', '--service-account-tiller'])
return res
@app.route('/install_artifact_repo', methods=['GET'])
def install_artifact_repo():
try:
res = subprocess.call(['helm', 'install', 'stable/minio', '-n', 'argo-artifacts', '--set', 'service.type=LoadBalancer', '--set', 'defaultBucket.enabled=true', '--set', 'defaultBucket.name=my-bucket', '--set', 'persistence.enabled=false', '--set', 'fullnameOverride=argo-artifacts'])
except Exception:
print("artifact repo already esists")
res = "Exception"
finally:
print("create admin role binding\n", res)
#res1 = CO(['helm', '-init', '--service-account-tiller'])
return res
@app.route('/update_argo_configmap', methods=['GET'])
def update_aro_configmap():
try:
res = CO(['kubectl', 'replace', 'cm', '-n', 'argo', 'workflow-controller-configmap', '-f', 'temp.yaml'])
except :
print("rolebinding already exists")
res = "Exception"
finally:
print("configmap updated\n", res)
#res1 = CO(['helm', '-init', '--service-account-tiller'])
return res
@app.route('/generate_startup_artifacts', methods=['GET'])
def generate_startup_artifacts():
try:
res = CO(['./init.sh', './samples/simple/', './samples/chaincode/'], cwd = "../PIVT2/PIVT/fabric-kube")
except :
print("rolebinding already exists")
res = "Exception"
finally:
print("startup artifacts generated\n", res)
#res1 = CO(['helm', '-init', '--service-account-tiller'])
return res
@app.route('/bring_up_components', methods=['GET'])
def bring_up_components():
try:
res = subprocess.run(['helm', 'install', './hlf-kube', '--name', 'hlf-kube', '-f', 'samples/simple/network.yaml', '-f', 'samples/simple/crypto-config.yaml'], cwd = "../PIVT2/PIVT/fabric-kube")
except :
print("rolebinding already exists")
res = "Exception"
finally:
print("components up\n", res)
#res1 = CO(['helm', '-init', '--service-account-tiller'])
return str(res)
@app.route('/channel_flow', methods=['GET'])
def channel_flow():
old = os.getcwd()
os.chdir("../PIVT2/PIVT/fabric-kube")
try:
res = os.system(" helm template channel-flow/ -f samples/simple/network.yaml -f samples/simple/crypto-config.yaml | argo submit - --watch")
#res = subprocess.run(['helm', 'template', 'channel-flow/', '-f', 'samples/simple/network.yaml', '-f', 'samples/simple/crypto-config.yaml', '|', 'argo', 'submit', '-', '--watch'], cwd = "../PIVT2/PIVT/fabric-kube")
except :
print("channel-flow-failure")
res = "Exception"
finally:
print("channel-flow-success\n", res)
os.chdir(old)
#res1 = CO(['helm', '-init', '--service-account-tiller'])
return str(res)
@app.route('/chaincode_flow', methods=['GET'])
def chaincode_flow():
old = os.getcwd()
os.chdir("../PIVT2/PIVT/fabric-kube")
try:
res = os.system(" helm template chaincode-flow/ -f samples/simple/network.yaml -f samples/simple/crypto-config.yaml | argo submit - --watch")
#res = subprocess.run(['helm', 'template', 'channel-flow/', '-f', 'samples/simple/network.yaml', '-f', 'samples/simple/crypto-config.yaml', '|', 'argo', 'submit', '-', '--watch'], cwd = "../PIVT2/PIVT/fabric-kube")
except :
print("CHAINCODE-flow-failure")
res = "Exception"
finally:
print("CHAINCODE-flow-success\n", res)
os.chdir(old)
#res1 = CO(['helm', '-init', '--service-account-tiller'])
return str(res)
app.run()