2017-05-08 17:01:57 +08:00
|
|
|
#!/usr/bin/python3
|
2016-03-31 16:03:38 +08:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import getopt
|
|
|
|
|
|
|
|
import sys, inspect
|
2016-06-06 21:35:28 +08:00
|
|
|
|
|
|
|
|
2016-03-31 16:03:38 +08:00
|
|
|
this_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0]))
|
|
|
|
src_folder = os.path.realpath(os.path.abspath(os.path.join(this_folder,"..", "src")))
|
|
|
|
if src_folder not in sys.path:
|
|
|
|
sys.path.insert(0, src_folder)
|
|
|
|
|
|
|
|
# must first init loadenv
|
2018-06-11 00:14:41 +08:00
|
|
|
from utils import tools, env
|
2016-03-31 16:03:38 +08:00
|
|
|
config = env.getenv("CONFIG")
|
|
|
|
tools.loadenv(config)
|
|
|
|
|
|
|
|
from webViews.log import initlogging
|
|
|
|
initlogging("docklet-web")
|
|
|
|
from webViews.log import logger
|
|
|
|
|
|
|
|
from flask import Flask, request, session, render_template, redirect, send_from_directory, make_response, url_for, abort
|
|
|
|
from webViews.dashboard import dashboardView
|
2016-04-18 10:28:26 +08:00
|
|
|
from webViews.user.userlist import userlistView, useraddView, usermodifyView, userdataView, userqueryView
|
2016-06-07 16:21:32 +08:00
|
|
|
from webViews.notification.notification import CreateNotificationView, NotificationView, QuerySelfNotificationsView, \
|
2016-06-07 21:10:43 +08:00
|
|
|
QueryNotificationView, ModifyNotificationView, DeleteNotificationView
|
2016-03-31 16:03:38 +08:00
|
|
|
from webViews.user.userinfo import userinfoView
|
|
|
|
from webViews.user.userActivate import userActivateView
|
2017-06-16 16:01:46 +08:00
|
|
|
from webViews.syslogs import logsView
|
2016-03-31 16:03:38 +08:00
|
|
|
from webViews.user.grouplist import grouplistView, groupqueryView, groupdetailView, groupmodifyView
|
|
|
|
from functools import wraps
|
|
|
|
from webViews.dockletrequest import dockletRequest
|
|
|
|
from webViews.cluster import *
|
|
|
|
from webViews.admin import *
|
|
|
|
from webViews.monitor import *
|
2016-09-12 16:56:45 +08:00
|
|
|
from webViews.beansapplication import *
|
2017-04-07 16:25:57 +08:00
|
|
|
from webViews.cloud import *
|
2018-11-09 18:58:46 +08:00
|
|
|
from webViews.reportbug import *
|
2016-03-31 16:03:38 +08:00
|
|
|
from webViews.authenticate.auth import login_required, administration_required,activated_required
|
|
|
|
from webViews.authenticate.register import registerView
|
|
|
|
from webViews.authenticate.login import loginView, logoutView
|
2018-07-30 12:28:22 +08:00
|
|
|
from webViews.batch import *
|
2016-03-31 16:03:38 +08:00
|
|
|
import webViews.dockletrequest
|
|
|
|
from webViews import cookie_tool
|
2017-04-29 17:00:34 +08:00
|
|
|
import traceback
|
2016-03-31 16:03:38 +08:00
|
|
|
|
2017-02-28 00:19:32 +08:00
|
|
|
from werkzeug.utils import secure_filename
|
2016-03-31 16:03:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
external_login = env.getenv('EXTERNAL_LOGIN')
|
|
|
|
#default config
|
|
|
|
external_login_url = '/external_auth/'
|
|
|
|
external_login_callback_url = '/external_auth_callback/'
|
|
|
|
if (external_login == 'True'):
|
|
|
|
sys.path.insert(0, os.path.realpath(os.path.abspath(os.path.join(this_folder,"../src", "plugin"))))
|
|
|
|
import external_generate
|
|
|
|
from webViews.authenticate.login import external_loginView, external_login_callbackView
|
|
|
|
external_login_url = external_generate.external_login_url
|
|
|
|
external_login_callback_url = external_generate.external_login_callback_url
|
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/", methods=['GET'])
|
|
|
|
def home():
|
|
|
|
return render_template('home.html')
|
|
|
|
|
|
|
|
@app.route("/login/", methods=['GET', 'POST'])
|
|
|
|
def login():
|
2017-06-16 16:01:46 +08:00
|
|
|
loginView.open_registry = os.environ["OPEN_REGISTRY"]
|
2016-03-31 16:03:38 +08:00
|
|
|
return loginView.as_view()
|
|
|
|
|
|
|
|
@app.route(external_login_url, methods=['GET'])
|
|
|
|
def external_login_func():
|
|
|
|
try:
|
|
|
|
return external_loginView.as_view()
|
|
|
|
except:
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
@app.route(external_login_callback_url, methods=['GET'])
|
|
|
|
def external_login_callback():
|
|
|
|
try:
|
|
|
|
return external_login_callbackView.as_view()
|
|
|
|
except:
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
@app.route("/logout/", methods=["GET"])
|
|
|
|
@login_required
|
|
|
|
def logout():
|
|
|
|
return logoutView.as_view()
|
|
|
|
|
|
|
|
@app.route("/register/", methods=['GET', 'POST'])
|
2017-06-05 15:30:27 +08:00
|
|
|
#@administration_required
|
2016-03-31 16:03:38 +08:00
|
|
|
#now forbidden,only used by SEI & PKU Staffs and students.
|
|
|
|
#can be used by admin for testing
|
|
|
|
def register():
|
|
|
|
return registerView.as_view()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/activate/", methods=['GET', 'POST'])
|
|
|
|
@login_required
|
|
|
|
def activate():
|
|
|
|
return userActivateView.as_view()
|
|
|
|
|
|
|
|
@app.route("/dashboard/", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
def dashboard():
|
|
|
|
return dashboardView.as_view()
|
|
|
|
|
|
|
|
@app.route("/document/", methods=['GET'])
|
|
|
|
def redirect_dochome():
|
2018-11-09 18:58:46 +08:00
|
|
|
return redirect("https://unias.github.io/docklet/userguide/")
|
2016-03-31 16:03:38 +08:00
|
|
|
|
|
|
|
@app.route("/config/", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
def config():
|
|
|
|
return configView.as_view()
|
|
|
|
|
2018-11-09 18:58:46 +08:00
|
|
|
@app.route("/bug/report/", methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
def reportBug():
|
|
|
|
reportBugView.bugmessage = request.form['bugmessage']
|
|
|
|
return reportBugView.as_view()
|
2016-03-31 16:03:38 +08:00
|
|
|
|
2018-07-30 12:28:22 +08:00
|
|
|
@app.route("/batch_jobs/", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
def batch_job():
|
|
|
|
return batchJobListView().as_view()
|
|
|
|
|
|
|
|
@app.route("/batch_job/create/", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
def create_batch_job():
|
|
|
|
return createBatchJobView().as_view()
|
|
|
|
|
2018-08-08 17:58:31 +08:00
|
|
|
@app.route("/batch_job/<masterip>/add/", methods=['POST'])
|
2018-07-30 12:28:22 +08:00
|
|
|
@login_required
|
2018-08-08 17:58:31 +08:00
|
|
|
def add_batch_job(masterip):
|
|
|
|
addBatchJobView.masterip = masterip
|
|
|
|
addBatchJobView.job_data = request.form
|
2018-07-30 12:28:22 +08:00
|
|
|
return addBatchJobView().as_view()
|
|
|
|
|
|
|
|
@app.route("/batch_job/state/", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
def state_batch_job():
|
|
|
|
return stateBatchJobView().as_view()
|
2016-03-31 16:03:38 +08:00
|
|
|
|
2018-11-18 01:11:11 +08:00
|
|
|
@app.route("/batch_job/output/<jobid>/<taskid>/<instid>/<issue>/", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
def output_batch_job(jobid, taskid, instid, issue):
|
|
|
|
outputBatchJobView.jobid = jobid
|
|
|
|
outputBatchJobView.taskid = taskid
|
|
|
|
outputBatchJobView.instid = instid
|
|
|
|
outputBatchJobView.issue = issue
|
|
|
|
return outputBatchJobView().as_view()
|
|
|
|
|
2016-03-31 16:03:38 +08:00
|
|
|
@app.route("/workspace/create/", methods=['GET'])
|
2018-09-20 00:16:53 +08:00
|
|
|
#@activated_required
|
2016-03-31 16:03:38 +08:00
|
|
|
def addCluster():
|
|
|
|
return addClusterView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/workspace/<masterip>/list/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-07 16:25:57 +08:00
|
|
|
def listCluster(masterip):
|
|
|
|
listClusterView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
return listClusterView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/workspace/<masterip>/add/", methods=['POST'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-07 16:25:57 +08:00
|
|
|
def createCluster(masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
createClusterView.clustername = request.form["clusterName"]
|
|
|
|
createClusterView.image = request.form["image"]
|
2017-04-07 16:25:57 +08:00
|
|
|
createClusterView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
return createClusterView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/workspace/<masterip>/scaleout/<clustername>/", methods=['POST'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-07 16:25:57 +08:00
|
|
|
def scaleout(clustername,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
scaleoutView.image = request.form["image"]
|
2017-04-07 16:25:57 +08:00
|
|
|
scaleoutView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
scaleoutView.clustername = clustername
|
|
|
|
return scaleoutView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/workspace/<masterip>/scalein/<clustername>/<containername>/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-07 16:25:57 +08:00
|
|
|
def scalein(clustername,containername,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
scaleinView.clustername = clustername
|
|
|
|
scaleinView.containername = containername
|
2017-04-07 16:25:57 +08:00
|
|
|
scaleinView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
return scaleinView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/workspace/<masterip>/start/<clustername>/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-07 16:25:57 +08:00
|
|
|
def startClustet(clustername,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
startClusterView.clustername = clustername
|
2017-04-07 16:25:57 +08:00
|
|
|
startClusterView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
return startClusterView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/workspace/<masterip>/stop/<clustername>/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-07 16:25:57 +08:00
|
|
|
def stopClustet(clustername,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
stopClusterView.clustername = clustername
|
2017-04-07 16:25:57 +08:00
|
|
|
stopClusterView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
return stopClusterView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/workspace/<masterip>/delete/<clustername>/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-07 16:25:57 +08:00
|
|
|
def deleteClustet(clustername,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
deleteClusterView.clustername = clustername
|
2017-04-07 16:25:57 +08:00
|
|
|
deleteClusterView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
return deleteClusterView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/workspace/<masterip>/detail/<clustername>/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-07 16:25:57 +08:00
|
|
|
def detailCluster(clustername,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
detailClusterView.clustername = clustername
|
2017-04-07 16:25:57 +08:00
|
|
|
detailClusterView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
return detailClusterView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/workspace/<masterip>/flush/<clustername>/<containername>/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
|
|
|
def flushCluster(clustername,containername):
|
|
|
|
flushClusterView.clustername = clustername
|
|
|
|
flushClusterView.containername = containername
|
|
|
|
return flushClusterView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/workspace/<masterip>/save/<clustername>/<containername>/", methods=['POST'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-07 16:25:57 +08:00
|
|
|
def saveImage(clustername,containername,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
saveImageView.clustername = clustername
|
|
|
|
saveImageView.containername = containername
|
2017-04-07 16:25:57 +08:00
|
|
|
saveImageView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
saveImageView.isforce = "false"
|
|
|
|
saveImageView.imagename = request.form['ImageName']
|
|
|
|
saveImageView.description = request.form['description']
|
|
|
|
return saveImageView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/workspace/<masterip>/save/<clustername>/<containername>/force/", methods=['POST'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-07 16:25:57 +08:00
|
|
|
def saveImage_force(clustername,containername,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
saveImageView.clustername = clustername
|
|
|
|
saveImageView.containername = containername
|
2017-04-07 16:25:57 +08:00
|
|
|
saveImageView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
saveImageView.isforce = "true"
|
|
|
|
saveImageView.imagename = request.form['ImageName']
|
|
|
|
saveImageView.description = request.form['description']
|
|
|
|
return saveImageView.as_view()
|
|
|
|
|
2017-07-16 12:24:58 +08:00
|
|
|
'''@app.route("/addproxy/<masterip>/<clustername>/", methods=['POST'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-09 18:18:12 +08:00
|
|
|
def addproxy(clustername,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
addproxyView.clustername = clustername
|
2017-04-09 18:18:12 +08:00
|
|
|
addproxyView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
addproxyView.ip = request.form['proxy_ip']
|
|
|
|
addproxyView.port = request.form['proxy_port']
|
2017-07-16 12:24:58 +08:00
|
|
|
return addproxyView.as_view()'''
|
2016-03-31 16:03:38 +08:00
|
|
|
|
2017-07-16 12:24:58 +08:00
|
|
|
'''@app.route("/deleteproxy/<masterip>/<clustername>/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-09 18:18:12 +08:00
|
|
|
def deleteproxy(clustername,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
deleteproxyView.clustername = clustername
|
2017-04-09 18:18:12 +08:00
|
|
|
deleteproxyView.masterip = masterip
|
2017-07-16 12:24:58 +08:00
|
|
|
return deleteproxyView.as_view()'''
|
2016-03-31 16:03:38 +08:00
|
|
|
|
2017-07-10 23:48:06 +08:00
|
|
|
@app.route("/port_mapping/add/<masterip>/", methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
def addPortMapping(masterip):
|
|
|
|
addPortMappingView.masterip = masterip
|
|
|
|
return addPortMappingView.as_view()
|
|
|
|
|
2017-11-19 22:12:56 +08:00
|
|
|
@app.route("/port_mapping/delete/<masterip>/<clustername>/<node_name>/<node_port>/", methods=['GET'])
|
2017-07-10 23:48:06 +08:00
|
|
|
@login_required
|
2017-11-19 22:12:56 +08:00
|
|
|
def delPortMapping(masterip,clustername,node_name,node_port):
|
2017-07-10 23:48:06 +08:00
|
|
|
delPortMappingView.masterip = masterip
|
|
|
|
delPortMappingView.clustername = clustername
|
|
|
|
delPortMappingView.node_name = node_name
|
2017-11-19 22:12:56 +08:00
|
|
|
delPortMappingView.node_port = node_port
|
2017-07-10 23:48:06 +08:00
|
|
|
return delPortMappingView.as_view()
|
|
|
|
|
2017-05-21 16:08:12 +08:00
|
|
|
@app.route("/getmasterdesc/<mastername>/", methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
def getmasterdesc(mastername):
|
|
|
|
return env.getenv(mastername+"_desc")[1:-1]
|
|
|
|
|
|
|
|
@app.route("/masterdesc/<mastername>/", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
def masterdesc(mastername):
|
|
|
|
descriptionMasterView.desc=env.getenv(mastername+"_desc")[1:-1]
|
|
|
|
return descriptionMasterView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/image/<masterip>/list/", methods=['POST'])
|
2017-05-07 15:47:21 +08:00
|
|
|
@login_required
|
|
|
|
def image_list(masterip):
|
|
|
|
data = {
|
|
|
|
"user": session['username']
|
|
|
|
}
|
2017-09-13 14:44:45 +08:00
|
|
|
# path = request.path[:request.path.rfind("/")]
|
|
|
|
# path = path[:path.rfind("/")+1]
|
|
|
|
result = dockletRequest.post("/image/list/", data, masterip)
|
2017-05-07 15:47:21 +08:00
|
|
|
logger.debug("image" + str(type(result)))
|
|
|
|
return json.dumps(result)
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/image/<masterip>/description/<image>/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-07 16:25:57 +08:00
|
|
|
def descriptionImage(image,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
descriptionImageView.image = image
|
2017-04-07 16:25:57 +08:00
|
|
|
descriptionImageView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
return descriptionImageView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/image/<masterip>/share/<image>/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-09 18:18:12 +08:00
|
|
|
def shareImage(image,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
shareImageView.image = image
|
2017-04-09 18:18:12 +08:00
|
|
|
shareImageView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
return shareImageView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/image/<masterip>/unshare/<image>/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-09 18:18:12 +08:00
|
|
|
def unshareImage(image,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
unshareImageView.image = image
|
2017-04-09 18:18:12 +08:00
|
|
|
unshareImageView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
return unshareImageView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/image/<masterip>/delete/<image>/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-09 18:18:12 +08:00
|
|
|
def deleteImage(image,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
deleteImageView.image = image
|
2017-04-09 18:18:12 +08:00
|
|
|
deleteImageView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
return deleteImageView.as_view()
|
|
|
|
|
2018-04-08 15:05:04 +08:00
|
|
|
@app.route("/image/<masterip>/copy/<image>/", methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
def copyImage(image,masterip):
|
|
|
|
copyImageView.image = image
|
|
|
|
copyImageView.masterip = masterip
|
|
|
|
copyImageView.target = request.form['target']
|
|
|
|
return copyImageView.as_view()
|
|
|
|
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/image/<masterip>/updatebase/<image>/", methods=['GET'])
|
2016-07-11 15:19:23 +08:00
|
|
|
@login_required
|
2017-04-09 18:18:12 +08:00
|
|
|
def updatebaseImage(image,masterip):
|
2016-07-11 15:19:23 +08:00
|
|
|
updatebaseImageView.image = image
|
2017-04-09 18:18:12 +08:00
|
|
|
updatebaseImageView.masterip = masterip
|
2016-07-11 15:19:23 +08:00
|
|
|
return updatebaseImageView.as_view()
|
|
|
|
|
2016-03-31 16:03:38 +08:00
|
|
|
@app.route("/hosts/", methods=['GET'])
|
|
|
|
@administration_required
|
|
|
|
def hosts():
|
|
|
|
return hostsView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/hosts/<masterip>/<com_ip>/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@administration_required
|
2017-04-09 18:18:12 +08:00
|
|
|
def hostsRealtime(com_ip,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
hostsRealtimeView.com_ip = com_ip
|
2017-04-09 18:18:12 +08:00
|
|
|
hostsRealtimeView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
return hostsRealtimeView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/hosts/<masterip>/<com_ip>/containers/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@administration_required
|
2017-04-09 18:18:12 +08:00
|
|
|
def hostsConAll(com_ip,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
hostsConAllView.com_ip = com_ip
|
2017-04-09 18:18:12 +08:00
|
|
|
hostsConAllView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
return hostsConAllView.as_view()
|
|
|
|
|
|
|
|
@app.route("/vclusters/", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
def status():
|
|
|
|
return statusView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/vclusters/<masterip>/<vcluster_name>/<node_name>/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-09 18:18:12 +08:00
|
|
|
def statusRealtime(vcluster_name,node_name,masterip):
|
|
|
|
statusRealtimeView.masterip = masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
statusRealtimeView.node_name = node_name
|
|
|
|
return statusRealtimeView.as_view()
|
|
|
|
|
2016-08-07 17:10:18 +08:00
|
|
|
@app.route("/history/", methods=['GET'])
|
|
|
|
#@login_required
|
|
|
|
def history():
|
2016-07-24 13:51:01 +08:00
|
|
|
return historyView.as_view()
|
|
|
|
|
2016-08-07 17:10:18 +08:00
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/history/<masterip>/<vnode_name>/", methods=['GET'])
|
2016-08-07 17:10:18 +08:00
|
|
|
@login_required
|
2017-04-09 18:18:12 +08:00
|
|
|
def historyVNode(vnode_name,masterip):
|
|
|
|
historyVNodeView.masterip = masterip
|
2016-08-07 17:10:18 +08:00
|
|
|
historyVNodeView.vnode_name = vnode_name
|
|
|
|
return historyVNodeView.as_view()
|
|
|
|
|
2017-06-26 18:46:01 +08:00
|
|
|
@app.route("/monitor/<masterip>/hosts/<comid>/<infotype>/", methods=['POST'])
|
|
|
|
@app.route("/monitor/<masterip>/vnodes/<comid>/<infotype>/", methods=['POST'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@login_required
|
2017-04-09 18:18:12 +08:00
|
|
|
def monitor_request(comid,infotype,masterip):
|
2016-03-31 16:03:38 +08:00
|
|
|
data = {
|
|
|
|
"user": session['username']
|
|
|
|
}
|
2017-06-26 18:46:01 +08:00
|
|
|
path = request.path[request.path.find("/")+1:]
|
|
|
|
path = path[path.find("/")+1:]
|
|
|
|
path = path[path.find("/")+1:]
|
2017-04-09 18:18:12 +08:00
|
|
|
logger.debug(path + "_____" + masterip)
|
2017-06-26 18:46:01 +08:00
|
|
|
result = dockletRequest.post("/monitor/"+path, data, masterip)
|
2017-05-07 15:47:21 +08:00
|
|
|
logger.debug("monitor" + str(type(result)))
|
2016-03-31 16:03:38 +08:00
|
|
|
return json.dumps(result)
|
|
|
|
|
2017-12-04 01:40:04 +08:00
|
|
|
@app.route("/monitor/<masterip>/user/<issue>/", methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
def monitor_user_request(issue,masterip):
|
|
|
|
data = {
|
|
|
|
"user": session['username']
|
|
|
|
}
|
|
|
|
path = "/monitor/user/" + str(issue) + "/"
|
|
|
|
logger.debug(path + "_____" + masterip)
|
|
|
|
result = dockletRequest.post(path, data, masterip)
|
|
|
|
logger.debug("monitor" + str(type(result)))
|
|
|
|
return json.dumps(result)
|
|
|
|
|
2016-09-12 16:56:45 +08:00
|
|
|
@app.route("/beans/application/", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
def beansapplication():
|
|
|
|
return beansapplicationView.as_view()
|
|
|
|
|
2016-09-15 18:04:12 +08:00
|
|
|
@app.route("/beans/apply/", methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
def beansapply():
|
|
|
|
return beansapplyView.as_view()
|
|
|
|
|
2018-03-04 15:20:46 +08:00
|
|
|
@app.route("/beans/admin/<username>/<msgid>/<cmd>/", methods=['GET'])
|
2016-09-17 17:50:09 +08:00
|
|
|
@login_required
|
|
|
|
@administration_required
|
2018-03-04 15:20:46 +08:00
|
|
|
def beansadmin(username,msgid,cmd):
|
2016-09-17 17:50:09 +08:00
|
|
|
beansadminView.msgid = msgid
|
2018-03-04 15:20:46 +08:00
|
|
|
beansadminView.username = username
|
2016-09-17 17:50:09 +08:00
|
|
|
if cmd == "agree" or cmd == "reject":
|
|
|
|
beansadminView.cmd = cmd
|
|
|
|
return beansadminView.as_view()
|
|
|
|
else:
|
|
|
|
return redirect("/user/list/")
|
|
|
|
|
2016-04-25 01:00:06 +08:00
|
|
|
'''@app.route("/monitor/User/", methods=['GET'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@administration_required
|
|
|
|
def monitorUserAll():
|
|
|
|
return monitorUserAllView.as_view()
|
2016-04-25 01:00:06 +08:00
|
|
|
'''
|
2016-03-31 16:03:38 +08:00
|
|
|
|
2017-06-16 16:01:46 +08:00
|
|
|
@app.route("/logs/", methods=['GET', 'POST'])
|
2017-02-28 00:19:32 +08:00
|
|
|
@administration_required
|
2017-06-16 16:01:46 +08:00
|
|
|
def logs():
|
|
|
|
return logsView.as_view()
|
2017-02-28 00:19:32 +08:00
|
|
|
|
|
|
|
@app.route("/logs/<filename>/", methods=['GET'])
|
|
|
|
@administration_required
|
|
|
|
def logs_get(filename):
|
|
|
|
data = {
|
|
|
|
"filename": filename
|
|
|
|
}
|
|
|
|
result = dockletRequest.post('/logs/get/', data).get('result', '')
|
|
|
|
response = make_response(result)
|
|
|
|
response.headers["content-type"] = "text/plain"
|
|
|
|
return response
|
|
|
|
|
2016-03-31 16:03:38 +08:00
|
|
|
@app.route("/user/list/", methods=['GET', 'POST'])
|
|
|
|
@administration_required
|
|
|
|
def userlist():
|
|
|
|
return userlistView.as_view()
|
|
|
|
|
|
|
|
@app.route("/group/list/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def grouplist():
|
|
|
|
return grouplistView.as_view()
|
|
|
|
|
|
|
|
@app.route("/group/detail/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def groupdetail():
|
|
|
|
return groupdetailView.as_view()
|
|
|
|
|
|
|
|
@app.route("/group/query/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def groupquery():
|
|
|
|
return groupqueryView.as_view()
|
|
|
|
|
2016-04-12 15:03:00 +08:00
|
|
|
@app.route("/group/modify/<groupname>/", methods=['POST'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@administration_required
|
2016-04-12 15:03:00 +08:00
|
|
|
def groupmodify(groupname):
|
2016-03-31 16:03:38 +08:00
|
|
|
return groupmodifyView.as_view()
|
|
|
|
|
|
|
|
@app.route("/user/data/", methods=['GET', 'POST'])
|
|
|
|
@administration_required
|
|
|
|
def userdata():
|
|
|
|
return userdataView.as_view()
|
|
|
|
|
|
|
|
@app.route("/user/add/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def useradd():
|
|
|
|
return useraddView.as_view()
|
|
|
|
|
|
|
|
@app.route("/user/modify/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def usermodify():
|
|
|
|
return usermodifyView.as_view()
|
|
|
|
|
2016-08-04 21:58:08 +08:00
|
|
|
@app.route("/user/change/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def userchange():
|
|
|
|
return usermodifyView.as_view()
|
|
|
|
|
2016-04-12 15:03:00 +08:00
|
|
|
@app.route("/quota/add/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def quotaadd():
|
|
|
|
return quotaaddView.as_view()
|
|
|
|
|
2016-04-27 16:31:46 +08:00
|
|
|
@app.route("/quota/chdefault/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def chdefault():
|
|
|
|
return chdefaultView.as_view()
|
|
|
|
|
2016-07-21 19:19:53 +08:00
|
|
|
@app.route("/quota/chlxcsetting/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def chlxcsetting():
|
|
|
|
return chlxcsettingView.as_view()
|
|
|
|
|
2016-03-31 16:03:38 +08:00
|
|
|
@app.route("/group/add/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def groupadd():
|
|
|
|
return groupaddView.as_view()
|
|
|
|
|
2016-04-06 14:43:16 +08:00
|
|
|
@app.route("/group/delete/<groupname>/", methods=['POST', 'GET'])
|
|
|
|
@administration_required
|
|
|
|
def groupdel(groupname):
|
|
|
|
groupdelView.groupname = groupname
|
|
|
|
return groupdelView.as_view()
|
|
|
|
|
2016-03-31 16:03:38 +08:00
|
|
|
@app.route("/user/info/", methods=['GET', 'POST'])
|
|
|
|
@login_required
|
|
|
|
def userinfo():
|
|
|
|
return userinfoView.as_view()
|
|
|
|
|
2017-12-05 15:50:32 +08:00
|
|
|
@app.route("/user/selfQuery/", methods=['GET', 'POST'])
|
|
|
|
@login_required
|
|
|
|
def userselfQuery():
|
|
|
|
result = dockletRequest.post('/user/selfQuery/')
|
|
|
|
return json.dumps(result['data'])
|
|
|
|
|
2016-03-31 16:03:38 +08:00
|
|
|
@app.route("/user/query/", methods=['GET', 'POST'])
|
|
|
|
@administration_required
|
|
|
|
def userquery():
|
|
|
|
return userqueryView.as_view()
|
|
|
|
|
2017-04-07 16:25:57 +08:00
|
|
|
@app.route("/cloud/", methods=['GET', 'POST'])
|
|
|
|
@administration_required
|
|
|
|
def cloud():
|
|
|
|
return cloudView.as_view()
|
|
|
|
|
2018-05-20 17:16:56 +08:00
|
|
|
@app.route("/cloud/<masterip>/setting/modify/", methods = ['POST'])
|
2017-04-07 16:25:57 +08:00
|
|
|
@administration_required
|
2018-05-20 17:16:56 +08:00
|
|
|
def cloud_setting_modify(masterip):
|
|
|
|
cloudSettingModifyView.masterip = masterip
|
|
|
|
return cloudSettingModifyView.as_view()
|
2017-04-07 16:25:57 +08:00
|
|
|
|
2018-05-20 16:05:11 +08:00
|
|
|
@app.route("/cloud/<masterip>/node/add/", methods = ['POST', 'GET'])
|
|
|
|
@administration_required
|
|
|
|
def cloud_node_add(masterip):
|
|
|
|
cloudNodeAddView.masterip = masterip
|
|
|
|
return cloudNodeAddView.as_view()
|
|
|
|
|
2016-06-06 18:19:35 +08:00
|
|
|
|
2016-06-06 21:43:03 +08:00
|
|
|
@app.route("/notification/", methods=['GET'])
|
2016-06-06 21:35:28 +08:00
|
|
|
@administration_required
|
2016-06-06 21:58:58 +08:00
|
|
|
def notification_list():
|
2016-06-06 21:35:28 +08:00
|
|
|
return NotificationView.as_view()
|
|
|
|
|
|
|
|
|
2016-06-07 00:59:47 +08:00
|
|
|
@app.route("/notification/create/", methods=['GET', 'POST'])
|
2016-06-06 18:19:35 +08:00
|
|
|
@administration_required
|
|
|
|
def create_notification():
|
|
|
|
return CreateNotificationView.as_view()
|
|
|
|
|
2016-06-06 21:35:28 +08:00
|
|
|
|
2016-06-07 21:10:43 +08:00
|
|
|
@app.route("/notification/modify/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def modify_notification():
|
|
|
|
return ModifyNotificationView.as_view()
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/notification/delete/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def delete_notification():
|
|
|
|
return DeleteNotificationView.as_view()
|
|
|
|
|
|
|
|
|
2016-06-07 02:20:14 +08:00
|
|
|
@app.route("/notification/query_self/", methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
def query_self_notifications():
|
|
|
|
return QuerySelfNotificationsView.as_view()
|
|
|
|
|
2016-06-07 16:21:32 +08:00
|
|
|
|
|
|
|
@app.route("/notification/detail/<notify_id>/", methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
def query_notification_detail(notify_id):
|
|
|
|
return QueryNotificationView.get_by_id(notify_id)
|
|
|
|
|
|
|
|
|
2016-05-15 22:12:06 +08:00
|
|
|
@app.route("/system/modify/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def systemmodify():
|
|
|
|
return systemmodifyView.as_view()
|
|
|
|
|
|
|
|
@app.route("/system/clear_history/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def systemclearhistory():
|
|
|
|
return systemclearView.as_view()
|
|
|
|
|
|
|
|
@app.route("/system/add/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def systemadd():
|
|
|
|
return systemaddView.as_view()
|
|
|
|
|
|
|
|
@app.route("/system/delete/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def systemdelete():
|
|
|
|
return systemdeleteView.as_view()
|
|
|
|
|
|
|
|
@app.route("/system/resetall/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def systemresetall():
|
|
|
|
return systemresetallView.as_view()
|
2016-03-31 16:03:38 +08:00
|
|
|
|
2017-06-16 16:01:46 +08:00
|
|
|
@app.route("/settings/", methods=['GET', 'POST'])
|
2016-03-31 16:03:38 +08:00
|
|
|
@administration_required
|
|
|
|
def adminpage():
|
|
|
|
return adminView.as_view()
|
|
|
|
|
2017-06-16 16:01:46 +08:00
|
|
|
@app.route("/settings/update/", methods=['POST'])
|
|
|
|
@administration_required
|
|
|
|
def updatesettings():
|
|
|
|
return updatesettingsView.as_view()
|
|
|
|
|
2016-03-31 16:03:38 +08:00
|
|
|
@app.route('/index/', methods=['GET'])
|
|
|
|
def jupyter_control():
|
|
|
|
return redirect('/dashboard/')
|
|
|
|
|
|
|
|
# for download basefs.tar.bz
|
|
|
|
# remove, not the function of docklet
|
|
|
|
# should download it from a http server
|
|
|
|
#@app.route('/download/basefs', methods=['GET'])
|
|
|
|
#def download():
|
|
|
|
#fsdir = env.getenv("FS_PREFIX")
|
|
|
|
#return send_from_directory(fsdir+'/local', 'basefs.tar.bz', as_attachment=True)
|
|
|
|
|
|
|
|
# jupyter auth APIs
|
|
|
|
@app.route('/jupyter/', methods=['GET'])
|
|
|
|
def jupyter_prefix():
|
|
|
|
path = request.args.get('next')
|
|
|
|
if path == None:
|
|
|
|
return redirect('/login/')
|
|
|
|
return redirect('/login/'+'?next='+path)
|
|
|
|
|
|
|
|
@app.route('/jupyter/home/', methods=['GET'])
|
|
|
|
def jupyter_home():
|
|
|
|
return redirect('/dashboard/')
|
|
|
|
|
|
|
|
@app.route('/jupyter/login/', methods=['GET', 'POST'])
|
|
|
|
def jupyter_login():
|
|
|
|
return redirect('/login/')
|
|
|
|
|
|
|
|
@app.route('/jupyter/logout/', methods=['GET'])
|
|
|
|
def jupyter_logout():
|
|
|
|
return redirect('/logout/')
|
|
|
|
|
|
|
|
@app.route('/jupyter/authorizations/cookie/<cookie_name>/<cookie_content>/', methods=['GET'])
|
|
|
|
def jupyter_auth(cookie_name, cookie_content):
|
|
|
|
username = cookie_tool.parse_cookie(cookie_content, app.secret_key)
|
|
|
|
if username == None:
|
|
|
|
resp = make_response('cookie auth failed')
|
|
|
|
resp.status_code = 404
|
|
|
|
return resp
|
|
|
|
return json.dumps({'name': username})
|
|
|
|
|
|
|
|
@app.errorhandler(401)
|
|
|
|
def not_authorized(error):
|
|
|
|
if "username" in session:
|
2016-04-18 10:28:26 +08:00
|
|
|
if "401" in session:
|
|
|
|
reason = session['401']
|
|
|
|
session.pop('401', None)
|
|
|
|
if (reason == 'Token Expired'):
|
|
|
|
return redirect('/logout/')
|
2016-03-31 16:03:38 +08:00
|
|
|
return render_template('error/401.html', mysession = session)
|
|
|
|
else:
|
|
|
|
return redirect('/login/')
|
|
|
|
|
|
|
|
@app.errorhandler(500)
|
|
|
|
def internal_server_error(error):
|
2016-08-21 15:30:59 +08:00
|
|
|
logger.error(error)
|
2017-04-29 17:00:34 +08:00
|
|
|
logger.error(traceback.format_exc())
|
2016-03-31 16:03:38 +08:00
|
|
|
if "username" in session:
|
2016-04-18 10:28:26 +08:00
|
|
|
if "500" in session and "500_title" in session:
|
|
|
|
reason = session['500']
|
|
|
|
title = session['500_title']
|
|
|
|
session.pop('500', None)
|
|
|
|
session.pop('500_title', None)
|
|
|
|
else:
|
|
|
|
reason = '''The server encountered something unexpected that didn't allow it to complete the request. We apologize.You can go back to
|
|
|
|
<a href="/dashboard/">dashboard</a> or <a href="/logout">log out</a>'''
|
|
|
|
title = 'Internal Server Error'
|
|
|
|
return render_template('error/500.html', mysession = session, reason = reason, title = title)
|
2016-03-31 16:03:38 +08:00
|
|
|
else:
|
|
|
|
return redirect('/login/')
|
|
|
|
if __name__ == '__main__':
|
|
|
|
'''
|
|
|
|
to generate a secret_key
|
|
|
|
|
|
|
|
from base64 import b64encode
|
|
|
|
from os import urandom
|
|
|
|
|
|
|
|
secret_key = urandom(24)
|
|
|
|
secret_key = b64encode(secret_key).decode('utf-8')
|
|
|
|
|
|
|
|
'''
|
|
|
|
logger.info('Start Flask...:')
|
|
|
|
try:
|
|
|
|
secret_key_file = open(env.getenv('FS_PREFIX') + '/local/web_secret_key.txt')
|
|
|
|
app.secret_key = secret_key_file.read()
|
|
|
|
secret_key_file.close()
|
|
|
|
except:
|
|
|
|
from base64 import b64encode
|
|
|
|
from os import urandom
|
|
|
|
secret_key = urandom(24)
|
|
|
|
secret_key = b64encode(secret_key).decode('utf-8')
|
|
|
|
app.secret_key = secret_key
|
|
|
|
secret_key_file = open(env.getenv('FS_PREFIX') + '/local/web_secret_key.txt', 'w')
|
|
|
|
secret_key_file.write(secret_key)
|
|
|
|
secret_key_file.close()
|
|
|
|
|
2017-06-16 16:01:46 +08:00
|
|
|
try:
|
|
|
|
open_registryfile = open(env.getenv('FS_PREFIX') + '/local/settings.conf')
|
2018-03-01 15:14:53 +08:00
|
|
|
settings = json.loads(open_registryfile.read())
|
2017-06-16 16:01:46 +08:00
|
|
|
open_registryfile.close()
|
|
|
|
os.environ['OPEN_REGISTRY'] = settings.get('OPEN_REGISTRY',"False")
|
|
|
|
except:
|
|
|
|
os.environ['OPEN_REGISTRY'] = "False"
|
|
|
|
|
2016-03-31 16:03:38 +08:00
|
|
|
os.environ['APP_KEY'] = app.secret_key
|
|
|
|
runcmd = sys.argv[0]
|
|
|
|
app.runpath = runcmd.rsplit('/', 1)[0]
|
|
|
|
|
|
|
|
webip = "0.0.0.0"
|
|
|
|
webport = env.getenv("WEB_PORT")
|
|
|
|
|
|
|
|
webViews.dockletrequest.endpoint = 'http://%s:%d' % (env.getenv('MASTER_IP'), env.getenv('MASTER_PORT'))
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "i:p:", ["ip=", "port="])
|
|
|
|
except getopt.GetoptError:
|
|
|
|
print ("%s -i ip -p port" % sys.argv[0])
|
|
|
|
sys.exit(2)
|
|
|
|
for opt, arg in opts:
|
|
|
|
if opt in ("-i", "--ip"):
|
|
|
|
webip = arg
|
|
|
|
elif opt in ("-p", "--port"):
|
|
|
|
webport = int(arg)
|
|
|
|
|
2017-05-21 16:08:12 +08:00
|
|
|
app.run(host = webip, port = webport, debug = True, threaded=True)
|