|
|
|
@ -8,9 +8,7 @@ from sqlalchemy import text
|
|
|
|
|
from website import consts
|
|
|
|
|
from website import db_mysql, errors
|
|
|
|
|
from website.db.alg_model.alg_model import ModelRepositry as DB_AlgModel
|
|
|
|
|
from website.db.device_classification import (
|
|
|
|
|
device_classification as DB_DeviceClassification,
|
|
|
|
|
)
|
|
|
|
|
from website.db.device_classification import device_classification as DB_DeviceClassification
|
|
|
|
|
from website.db.enterprise_busi_model import (
|
|
|
|
|
enterprise_busi_model as DB_BusiModel,
|
|
|
|
|
)
|
|
|
|
@ -18,6 +16,7 @@ from website.db.enterprise_busi_model import enterprise_busi_model_node_device a
|
|
|
|
|
from website.db.enterprise_device import enterprise_device as DB_Device
|
|
|
|
|
from website.db.enterprise_node import enterprise_node_base_model_conf as DB_NodeBaseModelConf
|
|
|
|
|
from website.handler import APIHandler, authenticated
|
|
|
|
|
from website.util import date_util
|
|
|
|
|
from website.util import shortuuid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -405,15 +404,15 @@ class DeviceBasemodelListHandler(APIHandler):
|
|
|
|
|
base_model_version = base_model["default_version"]
|
|
|
|
|
db_conf = DB_NodeBaseModelConf.EnterpriseNodeDeviceBMCusConfRepository()
|
|
|
|
|
conf = db_conf.get_busi_model_custom_config(busi_model_id=busi_model_id, device_id=device_id,
|
|
|
|
|
node_id=item["node_id"])
|
|
|
|
|
node_id=item["node_id"])
|
|
|
|
|
base_model_hub_image = ""
|
|
|
|
|
if conf:
|
|
|
|
|
base_model_hub_image = conf.model_hub_image
|
|
|
|
|
base_models.append({
|
|
|
|
|
"model_id": base_model_id,
|
|
|
|
|
"model_name": base_model_name,
|
|
|
|
|
"model_version": base_model_version,
|
|
|
|
|
"model_hub_image": base_model_hub_image,
|
|
|
|
|
"model_id": base_model_id,
|
|
|
|
|
"model_name": base_model_name,
|
|
|
|
|
"model_version": base_model_version,
|
|
|
|
|
"model_hub_image": base_model_hub_image,
|
|
|
|
|
})
|
|
|
|
|
res.append({
|
|
|
|
|
"busi_model_id": busi_model_id,
|
|
|
|
@ -541,8 +540,8 @@ class StatusListHandler(APIHandler):
|
|
|
|
|
db_device = DB_Device.EnterpriseDeviceRepository()
|
|
|
|
|
res = db_device.list_entity_devices(
|
|
|
|
|
entity_id=entity_id,
|
|
|
|
|
pageNo=pageNo,
|
|
|
|
|
pageSize=pageSize,
|
|
|
|
|
pageno=pageNo,
|
|
|
|
|
pagesize=pageSize,
|
|
|
|
|
classification=classification,
|
|
|
|
|
status=status,
|
|
|
|
|
)
|
|
|
|
@ -550,7 +549,8 @@ class StatusListHandler(APIHandler):
|
|
|
|
|
count = res["count"]
|
|
|
|
|
devices = res["devices"]
|
|
|
|
|
data = []
|
|
|
|
|
for item in devices:
|
|
|
|
|
for item, _ in devices:
|
|
|
|
|
logging.info(item)
|
|
|
|
|
data.append(
|
|
|
|
|
{
|
|
|
|
|
"id": item.id,
|
|
|
|
@ -563,7 +563,17 @@ class StatusListHandler(APIHandler):
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.finish({"count": count, "data": data})
|
|
|
|
|
status_dic = {
|
|
|
|
|
consts.device_status_online: 0,
|
|
|
|
|
consts.device_status_offline: 0,
|
|
|
|
|
consts.device_status_ongoing: 0,
|
|
|
|
|
consts.device_status_error: 0,
|
|
|
|
|
}
|
|
|
|
|
status_count = db_device.status_count(entity_id=entity_id, classification=classification)
|
|
|
|
|
for key in status_count:
|
|
|
|
|
status_dic.update({key: status_count[key]})
|
|
|
|
|
|
|
|
|
|
self.finish({"count": count, "data": data, "status_count": status_dic})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StatusInfoHandler(APIHandler):
|
|
|
|
@ -575,22 +585,112 @@ class StatusInfoHandler(APIHandler):
|
|
|
|
|
if not device_id:
|
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "设备id不能为空")
|
|
|
|
|
|
|
|
|
|
# 查询设备信息
|
|
|
|
|
db_device = DB_Device.EnterpriseDeviceRepository()
|
|
|
|
|
res = db_device.get_devices(device_ids=[device_id])
|
|
|
|
|
if not res:
|
|
|
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "设备不存在")
|
|
|
|
|
res = res[0]
|
|
|
|
|
device_suid = res["suid"]
|
|
|
|
|
device_name = res["name"]
|
|
|
|
|
device_comment = res["comment"]
|
|
|
|
|
classification = res["classification"]
|
|
|
|
|
db_cls = DB_DeviceClassification.DeviceClassificationReporitory()
|
|
|
|
|
row_cls = db_cls.get_row_by_suid(suid=classification)
|
|
|
|
|
device_classification_name = row_cls.name
|
|
|
|
|
|
|
|
|
|
db_busi_model = DB_BusiModelNodeDevice.EnterpriseBusiModelNodeDeviceRepository()
|
|
|
|
|
busi_models, _ = db_busi_model.get_busi_model_by_device(device_id=device_id)
|
|
|
|
|
for busi_model in busi_models:
|
|
|
|
|
base_model_ids = json.loads(busi_model["base_models"])
|
|
|
|
|
|
|
|
|
|
self.finish()
|
|
|
|
|
models = []
|
|
|
|
|
for item in busi_models:
|
|
|
|
|
busi_model_id = item["busi_model_id"]
|
|
|
|
|
busi_model_name = item["name"]
|
|
|
|
|
base_model_list = json.loads(item["base_models"])
|
|
|
|
|
base_models = []
|
|
|
|
|
for base_model in base_model_list:
|
|
|
|
|
base_model_id = base_model["id"]
|
|
|
|
|
base_model_name = base_model["name"]
|
|
|
|
|
db_alg_model = DB_AlgModel()
|
|
|
|
|
base_model = db_alg_model.get_model_dict_by_id(base_model_id)
|
|
|
|
|
base_model_version = base_model["default_version"]
|
|
|
|
|
db_conf = DB_NodeBaseModelConf.EnterpriseNodeDeviceBMCusConfRepository()
|
|
|
|
|
conf = db_conf.get_busi_model_custom_config(busi_model_id=busi_model_id, device_id=device_id,
|
|
|
|
|
node_id=item["node_id"])
|
|
|
|
|
base_model_hub_image = ""
|
|
|
|
|
if conf:
|
|
|
|
|
base_model_hub_image = conf.model_hub_image
|
|
|
|
|
base_models.append({
|
|
|
|
|
"model_id": base_model_id,
|
|
|
|
|
"model_name": base_model_name,
|
|
|
|
|
"model_version": base_model_version,
|
|
|
|
|
"model_hub_image": base_model_hub_image,
|
|
|
|
|
})
|
|
|
|
|
models.append({
|
|
|
|
|
"busi_model": busi_model_name,
|
|
|
|
|
"base_models": base_models
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
self.finish({
|
|
|
|
|
"classification": device_classification_name,
|
|
|
|
|
"name": device_name,
|
|
|
|
|
"ID": device_suid,
|
|
|
|
|
"cpu": random.randint(20, 30),
|
|
|
|
|
"mem": random.randint(20, 30),
|
|
|
|
|
"storage": random.randint(20, 30),
|
|
|
|
|
"gpu": random.randint(20, 30),
|
|
|
|
|
"models": models
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StatusLogHandler(APIHandler):
|
|
|
|
|
""" """
|
|
|
|
|
"""
|
|
|
|
|
- 描述:设备状态日志
|
|
|
|
|
- 请求方式:post
|
|
|
|
|
- 请求参数:
|
|
|
|
|
> - entity_id, int, 企业id
|
|
|
|
|
> - pageNo
|
|
|
|
|
> - pageSize
|
|
|
|
|
- 返回值:
|
|
|
|
|
```
|
|
|
|
|
{
|
|
|
|
|
"count": 123,
|
|
|
|
|
"data": [
|
|
|
|
|
{
|
|
|
|
|
"ID": "xxx",
|
|
|
|
|
"name": "xxx",
|
|
|
|
|
"classification": "xxx",
|
|
|
|
|
"IP": "xxx",
|
|
|
|
|
"duration": "xxx",
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
@authenticated
|
|
|
|
|
def post(self):
|
|
|
|
|
self.finish()
|
|
|
|
|
entity_id = self.get_int_argument("entity_id")
|
|
|
|
|
pageNo = self.get_int_argument("pageNo", 1)
|
|
|
|
|
pageSize = self.get_int_argument("pageSize", 10)
|
|
|
|
|
|
|
|
|
|
db_device = DB_Device.EnterpriseDeviceRepository()
|
|
|
|
|
res = db_device.list_entity_devices(entity_id=entity_id, pageno=pageNo, pagesize=pageSize)
|
|
|
|
|
count = res["count"]
|
|
|
|
|
devices = res["devices"]
|
|
|
|
|
|
|
|
|
|
result = []
|
|
|
|
|
for device, classification_name in devices:
|
|
|
|
|
device_name = device.name
|
|
|
|
|
device_suid = device.suid
|
|
|
|
|
device_ip = ""
|
|
|
|
|
duration = date_util.time_diff(str(device.create_time))
|
|
|
|
|
result.append({
|
|
|
|
|
"ID": device_suid,
|
|
|
|
|
"name": device_name,
|
|
|
|
|
"classification": classification_name,
|
|
|
|
|
"IP": device_ip,
|
|
|
|
|
"duration": duration,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
self.finish({"count": count, "data": result})
|
|
|
|
|