-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_server.py
73 lines (57 loc) · 1.95 KB
/
admin_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
import os
import flask
from flask import json, request, jsonify
from flask_cors import CORS
import subprocess
from subprocess import check_output as CO
import time
import datetime
from kubernetes import client, config
from pprint import pprint
from flask_restx import Api, Resource, fields
app = flask.Flask(__name__)
api = Api(app, verion='1.0', title='Upayan-Admin-Api', description="Admin Api for Upayan Loyalty Platform")
ns = api.namespace('admin', description= 'Admin Operations')
CORS(app)
app.config['DEBUG'] = True
response_json = {
"program" : "admin_server",
"version" : "TEST",
}
def populate_response(resp = response_json, status = "No info", code = "100", message = "message was not set", data = {}):
# resp["program"] = "admin_server";
# resp["version"] = "TEST";
resp["datetime"] = datetime.datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
resp["status"] = status
resp["code"] = code
resp["data"] = data
resp["message"] = message
return resp
def read_json(filename):
with open(filename) as f:
data = json.load(f)
return data
# @app.route('/', methods=['GET'])
# def home():
# resp = populate_response(status = "success", code = "200")
# return resp
@ns.route('/hello')
class home(Resource):
def get(self):
resp = populate_response(status = "success", code = "200")
return resp
cluster = api.model("cluster", {"name": fields.String(readonly=True, description='Name of the cluster')})
@ns.route('/cluster')
class cluster(Resource):
@ns.doc('get cluster status')
def get(self):
resp = populate_response(status = "success", code = "200", message = "get cluster")
return resp
@ns.doc('create cluster')
@ns.expect(cluster)
def post(self):
# message = request.form['message']
resp = populate_response(status = "success", code = "200", message = message)
return resp
# @app.route('/cluster', methods=['POST'])
app.run(port=9997)