image_server_list.py 1.4 KB
# 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["data"].append("本地服务器")
            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()