cmdb_cobar.py 611 Bytes
#!/usr/bin/python
# -*- coding: UTF-8 -*-

"""
  get all cobar servers by query zookeeper:  [/yoho-cobar/front] and [/yoho-cobar/platform]

"""

from kazoo.client import KazooClient


class CobarServers:



  def get_cobar_servers(self):
    zk = KazooClient(self.zk_host, read_only=True)
    zk.start()

    cobars = []

    for path in ["/yoho-cobar/front",  "/yoho-cobar/platform"]:
        children = zk.get_children(path)
        if not children:
            cobars.append(map(lambda x: x.split(":")[0], children))
            print("There are %s children with names %s" % (len(children), children))