image_server_list.py
1.3 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
# coding=utf-8
#author: 4N
#createtime: 2021/7/19
#email: nheweijun@sina.com
from app.util.component.ApiTemplate import ApiTemplate
from app import GLOBAL_DIC
from kazoo.client import KazooClient
import configure
class Api(ApiTemplate):
api_name = "获取数据服务器列表"
def process(self):
# 返回结果
res = {}
try:
zoo = GLOBAL_DIC.get("zookeeper")
if zoo is None:
zoo :KazooClient = KazooClient(hosts=configure.zookeeper, timeout=100)
zoo.start()
GLOBAL_DIC["zookeeper"] = zoo
else :
if not zoo.connected:
zoo.start()
res["data"] = zoo.get_children("/rpc")
res["result"] = True
except Exception as e:
raise e
return res
api_doc = {
"tags": ["影像接口"],
"parameters": [
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}
if __name__ == '__main__':
zoo: KazooClient = KazooClient(hosts="172.26.99.168:2181", timeout=100)
zoo.start()
print(zoo.get_children("/rpc"))
zoo.stop()
zoo.close()