def api(type): l=lib.container(options) u=lib.user(options) d=lib.domain(options) db=lib.database(options) b=lib.backup(options) a=lib.admin(options) if request.method=="GET": if type=="container": return Response(json.dumps(l.list()),mimetype="application/json") elif type=="user": return Response(json.dumps(u.list()),mimetype="application/json") elif type=="domain": return Response(json.dumps(d.list()),mimetype="application/json") elif type=="database": return Response(json.dumps(db.list()),mimetype="application/json") elif type=="backup": return Response(json.dumps(b.list()),mimetype="application/json") elif type=="admin": return Response(json.dumps(a.list()),mimetype="application/json") elif type=="images": return Response(json.dumps(l.images()),mimetype="application/json") else: return Response(json.dumps({'status':'Error','extstatus':'service not defined'}),mimetype="application/json") else: print("not implemented") return json.dumps({})
def apinamedcontainer(name): l=lib.container(options) if request.method=="GET": return Response(json.dumps(l.container(name,details=True)),mimetype="application/json") elif request.method=="DELETE": return Response(json.dumps(l.delete(name)),mimetype="application/json") elif request.method=="POST": if request.form['action']=="backup": return Response(json.dumps(l.backup(name)),mimetype="application/json") elif request.form['action']=="restore": return Response(json.dumps(l.restore(name,request.form)),mimetype="application/json") elif request.form['action']=="start": return Response(json.dumps(l.start(name)),mimetype="application/json") elif request.form['action']=="stop": return Response(json.dumps(l.stop(name)),mimetype="application/json") elif request.method=="PUT": return Response(json.dumps(l.create(name,request.form)),mimetype="application/json") else: print(request.method+" not implemented") return json.dumps({})