monitor_host_delete.py
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from .models import MonitorHost, db
from sqlalchemy import and_
from app.util.component.ApiTemplate import ApiTemplate
import uuid
class Api(ApiTemplate):
api_name = "注销主机"
def para_check(self):
if not self.para.get("srcid"):
raise Exception("缺乏host参数")
def process(self):
# 返回结果
res = {}
res["data"] = {}
try:
srcid = self.para.get("srcid") # server
monitor_host = MonitorHost.query.filter_by(
srcid=srcid).one_or_none()
if monitor_host:
db.session.delete(monitor_host)
db.session.commit()
res["result"] = True
res["message"] = "删除成功,srcid:{}".format(srcid)
else:
res['message'] = 'host不存在,无法注销'
res["result"] = False
except Exception as e:
db.session.rollback()
raise e
return res
api_doc = {
"tags": ["监控接口"],
"parameters": [
{"name": "srcid",
"in": "formData",
"type": "string",
"description": "srcid值",
"required": "true"}
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}