parent
fd33d23576
commit
fd1d58921b
@ -0,0 +1,69 @@
|
||||
from flask import Blueprint
|
||||
from flask_restful import reqparse, Resource, Api
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
from units import token_auth,selfrds_manager
|
||||
from werkzeug.datastructures import FileStorage
|
||||
from units import upload
|
||||
|
||||
blueprint = Blueprint('selfrds',__name__)
|
||||
api = Api(blueprint)
|
||||
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument('vendor',type=str)
|
||||
parser.add_argument('account',type=str)
|
||||
parser.add_argument('region',type=str)
|
||||
parser.add_argument('group',type=str)
|
||||
parser.add_argument('name',type=str)
|
||||
parser.add_argument('ip',type=str)
|
||||
parser.add_argument('port',type=str)
|
||||
parser.add_argument('os',type=str)
|
||||
parser.add_argument('del_dict',type=dict)
|
||||
parser.add_argument('up_dict',type=dict)
|
||||
parser.add_argument('file',type=FileStorage, location="files", help="File is wrong.")
|
||||
|
||||
class Upload(Resource):
|
||||
@token_auth.auth.login_required
|
||||
def post(self):
|
||||
file = parser.parse_args().get("file")
|
||||
try:
|
||||
return upload.read_execl(file.read(),'selfrds')
|
||||
except Exception as e:
|
||||
print("【selfrds】导入失败",e,flush=True)
|
||||
return {"code": 50000, "data": f"导入失败!"}
|
||||
|
||||
class GetAllList(Resource):
|
||||
@token_auth.auth.login_required
|
||||
def get(self):
|
||||
args = parser.parse_args()
|
||||
return selfrds_manager.get_all_list(args['vendor'],args['account'],args['region'],args['group'])
|
||||
|
||||
class SelfrdsApi(Resource):
|
||||
decorators = [token_auth.auth.login_required]
|
||||
def get(self):
|
||||
return selfrds_manager.get_service()
|
||||
def post(self):
|
||||
args = parser.parse_args()
|
||||
print('=======\n',args,flush=True)
|
||||
return selfrds_manager.add_service(args['vendor'],args['account'],args['region'],
|
||||
args['group'],args['name'],args['ip'],args['port'],args['os'])
|
||||
def put(self):
|
||||
args = parser.parse_args()
|
||||
del_dict = args['del_dict']
|
||||
up_dict = args['up_dict']
|
||||
resp_del = selfrds_manager.del_service(del_dict['vendor'],del_dict['account'],
|
||||
del_dict['region'],del_dict['group'],del_dict['name'])
|
||||
resp_add = selfrds_manager.add_service(up_dict['vendor'],up_dict['account'],up_dict['region'],
|
||||
up_dict['group'],up_dict['name'],up_dict['ip'],
|
||||
up_dict['port'],up_dict['os'])
|
||||
if resp_del["code"] == 20000 and resp_add["code"] == 20000:
|
||||
return {"code": 20000, "data": f"更新成功!"}
|
||||
else:
|
||||
return {"code": 50000, "data": f"更新失败!"}
|
||||
def delete(self):
|
||||
args = parser.parse_args()
|
||||
return selfrds_manager.del_service(args['vendor'],args['account'],args['region'],args['group'],args['name'])
|
||||
|
||||
api.add_resource(GetAllList,'/api/selfrds/alllist')
|
||||
api.add_resource(SelfrdsApi, '/api/selfrds/service')
|
||||
api.add_resource(Upload,'/api/selfrds/upload')
|
@ -0,0 +1,37 @@
|
||||
import request from '@/utils/request-ops'
|
||||
|
||||
export function getAllList(vendor, account, region, group) {
|
||||
return request({
|
||||
url: '/api/selfrds/alllist',
|
||||
method: 'get',
|
||||
params: { vendor, account, region, group }
|
||||
})
|
||||
}
|
||||
|
||||
export function getAllInfo() {
|
||||
return request({
|
||||
url: '/api/selfrds/service',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
export function addService(data) {
|
||||
return request({
|
||||
url: '/api/selfrds/service',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
export function updateService(del_dict, up_dict) {
|
||||
return request({
|
||||
url: '/api/selfrds/service',
|
||||
method: 'put',
|
||||
data: { del_dict, up_dict }
|
||||
})
|
||||
}
|
||||
export function delService(data) {
|
||||
return request({
|
||||
url: '/api/selfrds/service',
|
||||
method: 'delete',
|
||||
data
|
||||
})
|
||||
}
|
Loading…
Reference in new issue