-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
55 lines (48 loc) · 1.74 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
from flask import Flask, request, jsonify
import os
app = Flask(__name__)
@app.route('/ping',methods=['GET'])
def ping():
return {"status": "pong"}
@app.route('/version',methods=['GET'])
def version():
return {"version": "v1.0.0"}
@app.route('/create',methods=['POST'])
def create():
posted_data = request.json
APIKEY=posted_data["APIKEY"]
WORKSPACE=posted_data["WORKSPACE"]
GHEKEY=posted_data["GHEKEY"]
COUNTNUMBER=posted_data["COUNTNUMBER"]
REGION=posted_data["REGION"]
os.system("ibmcloud login --apikey {0} -r 'us-south'".format(APIKEY))
os.system('ibmcloud target -g "Default"')
os.system('ibmcloud ce project select -n grant-cluster')
os.system("ibmcloud ce jobrun submit --job vpc-gen2-kubernetes -a {0} -a {1} -a {2} -a {3} -a {4}".format(APIKEY,WORKSPACE,GHEKEY,COUNTNUMBER,REGION))
print("#")
print("#")
print("#")
print(f"Running the command to build {WORKSPACE} in {REGION}.")
print("#")
print("#")
print("#")
return jsonify(posted_data)
@app.route('/delete',methods=['DELETE'])
def delete():
posted_data = request.json
APIKEY=posted_data["APIKEY"]
WORKSPACE=posted_data["WORKSPACE"]
os.system("ibmcloud login --apikey {0} -r 'us-south'".format(APIKEY))
os.system('ibmcloud target -g "Default"')
os.system('ibmcloud plugin install schematics -f')
os.system("ID_WORKSPACE=$(ibmcloud schematics workspace list | grep {0} | cut -d ' ' -f 4) && ibmcloud schematics destroy --id $ID_WORKSPACE -f ".format(WORKSPACE))
print("#")
print("#")
print("#")
print(f"Running the command to delete {WORKSPACE}.")
print("#")
print("#")
print("#")
return jsonify(posted_data)
if __name__ == '__main__':
app.run(port=8080, host='0.0.0.0')