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 kazoo.client import KazooClient
import configure
class Api(ApiTemplate):

    api_name = "获取数据服务器列表"

    def process(self):

        # 返回结果
        res = {}
        res["data"] = []
        try:
            zoo :KazooClient = KazooClient(hosts=configure.zookeeper, timeout=1)
            zoo.start()
            sers = zoo.get_children("/rpc")

            for p in sers:
                bl = str( zoo.get("/rpc/{}".format(p))[0] , encoding = "utf-8")
                res["data"].append({"name": p, "belong": bl})
            zoo.close()
        except Exception as e:
            pass
        res["data"].append({"name": "本地服务器", "belong": ""})
        res["result"] = True
        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()