|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
import logging
|
|
|
|
|
import random
|
|
|
|
|
|
|
|
|
|
from sqlalchemy import text
|
|
|
|
@ -7,7 +8,7 @@ from website import errors
|
|
|
|
|
from website import settings
|
|
|
|
|
from website.db.enterprise_device.enterprise_device import EnterpriseEntityRepository as EntRepo
|
|
|
|
|
from website.db_mysql import to_json_list, to_json
|
|
|
|
|
from website.handler import APIHandler, authenticated
|
|
|
|
|
from website.handler import APIHandler, authenticated, operation_log
|
|
|
|
|
from website.util import aes
|
|
|
|
|
from website.util import shortuuid
|
|
|
|
|
|
|
|
|
@ -28,6 +29,7 @@ class AddHandler(APIHandler):
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
@authenticated
|
|
|
|
|
@operation_log("企业项目", "服务器管理", "新建", "新建服务器", "")
|
|
|
|
|
def post(self):
|
|
|
|
|
entity_id = self.get_int_argument('entity_id')
|
|
|
|
|
name = self.get_escaped_argument('name', '')
|
|
|
|
@ -66,6 +68,34 @@ class AddHandler(APIHandler):
|
|
|
|
|
self.finish()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EditHandler(APIHandler):
|
|
|
|
|
@authenticated
|
|
|
|
|
@operation_log("企业项目", "服务器管理", "编辑", "编辑服务器", "")
|
|
|
|
|
def post(self):
|
|
|
|
|
server_id = self.get_int_argument("id")
|
|
|
|
|
name = self.get_escaped_argument('name', '')
|
|
|
|
|
ip = self.get_escaped_argument('ip', '')
|
|
|
|
|
port = self.get_int_argument("port", 22)
|
|
|
|
|
username = self.get_escaped_argument('username', '')
|
|
|
|
|
passwd = self.get_escaped_argument('passwd', '')
|
|
|
|
|
with self.app_mysql.connect() as conn:
|
|
|
|
|
conn.execute(
|
|
|
|
|
text(
|
|
|
|
|
"update enterprise_server "
|
|
|
|
|
"set name=:name, ip=:ip, port=:port, username=:username, passwd=:passwd where id=:id"
|
|
|
|
|
), {
|
|
|
|
|
"id": server_id,
|
|
|
|
|
"name": name,
|
|
|
|
|
"ip": ip,
|
|
|
|
|
"port": port,
|
|
|
|
|
"username": username,
|
|
|
|
|
"passwd": aes.encrypt(settings.enterprise_aes_key, passwd)
|
|
|
|
|
})
|
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
|
|
self.finish()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ListHandler(APIHandler):
|
|
|
|
|
"""
|
|
|
|
|
- 描述:服务器列表
|
|
|
|
@ -96,6 +126,7 @@ class ListHandler(APIHandler):
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
@authenticated
|
|
|
|
|
@operation_log("企业项目", "服务器管理", "查询", "查询服务器列表", "")
|
|
|
|
|
def post(self):
|
|
|
|
|
entity_id = self.get_int_argument('entity_id')
|
|
|
|
|
status = self.get_int_argument("status")
|
|
|
|
@ -118,7 +149,12 @@ class ListHandler(APIHandler):
|
|
|
|
|
p.update({"status": status})
|
|
|
|
|
|
|
|
|
|
count = conn.scalar(text(sql_count), p)
|
|
|
|
|
data = conn.execute(text(sql_data), p).limit(pageSize).offset((pageNo - 1) * pageSize)
|
|
|
|
|
|
|
|
|
|
sql_data += " order by id desc limit :pageSize offset :offset"
|
|
|
|
|
p.update({"offset": (pageNo - 1) * pageSize, "pageSize": pageSize})
|
|
|
|
|
|
|
|
|
|
data = conn.execute(text(sql_data), p)
|
|
|
|
|
data = to_json_list(data)
|
|
|
|
|
|
|
|
|
|
status_dic = {1001: 0, 1002: 0}
|
|
|
|
|
sql_status = "select status, count(id) c from enterprise_server where entity_id=:entity_id group by status"
|
|
|
|
@ -126,7 +162,8 @@ class ListHandler(APIHandler):
|
|
|
|
|
status_list = to_json_list(status_cur)
|
|
|
|
|
for item in status_list:
|
|
|
|
|
status_dic[item["status"]] = item["c"]
|
|
|
|
|
|
|
|
|
|
logging.info("####################### ")
|
|
|
|
|
logging.info(data)
|
|
|
|
|
for item in data:
|
|
|
|
|
item.update(
|
|
|
|
|
{"cpu": random.randint(20, 30),
|
|
|
|
@ -134,7 +171,7 @@ class ListHandler(APIHandler):
|
|
|
|
|
"storage": random.randint(20, 30),
|
|
|
|
|
"gpu": random.randint(20, 30), })
|
|
|
|
|
|
|
|
|
|
self.finish({"count": count, "data": to_json_list(data), "status": status_dic})
|
|
|
|
|
self.finish({"count": count, "data": data, "status": status_dic})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InfoHandler(APIHandler):
|
|
|
|
@ -159,6 +196,7 @@ class InfoHandler(APIHandler):
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
@authenticated
|
|
|
|
|
@operation_log("企业项目", "服务器管理", "查询", "查询服务器信息", "")
|
|
|
|
|
def post(self):
|
|
|
|
|
server_id = self.get_int_argument('server_id')
|
|
|
|
|
with self.app_mysql.connect() as conn:
|
|
|
|
@ -177,6 +215,7 @@ class InfoHandler(APIHandler):
|
|
|
|
|
|
|
|
|
|
class DeleteHandler(APIHandler):
|
|
|
|
|
@authenticated
|
|
|
|
|
@operation_log("企业项目", "服务器管理", "删除", "删除服务器", "")
|
|
|
|
|
def post(self):
|
|
|
|
|
server_id = self.get_int_argument('server_id')
|
|
|
|
|
with self.app_mysql.connect() as conn:
|
|
|
|
@ -211,8 +250,11 @@ class LogHandler(APIHandler):
|
|
|
|
|
p.update({"entity_id": entity_id})
|
|
|
|
|
|
|
|
|
|
count = conn.scalar(text(sql_count), p)
|
|
|
|
|
data = conn.execute(text(sql_data), p).order_by(text("id desc")).limit(pageSize).offset(
|
|
|
|
|
(pageNo - 1) * pageSize)
|
|
|
|
|
|
|
|
|
|
sql_data += " order by id desc limit :pageSize offset :offset"
|
|
|
|
|
p.update({"offset": (pageNo - 1) * pageSize, "pageSize": pageSize})
|
|
|
|
|
|
|
|
|
|
data = conn.execute(text(sql_data), p)
|
|
|
|
|
|
|
|
|
|
data = to_json_list(data)
|
|
|
|
|
self.finish({"count": count, "data": data})
|
|
|
|
|