Ejemplo n.º 1
0
 def __init__(self, ip):
   self.ip = ip
   self.zks = ZookeeperSession(ip + ":9876")
   if not self.zks.wait_for_connection(20):
     log.FATAL("Failed to connect to zookeeper - Check zookeeper config.")
     return False
   if self.zks.stat(EXTERNAL_CLUSTER_PATH) is None:
     self.zks.create(EXTERNAL_CLUSTER_PATH, "Nodata")
Ejemplo n.º 2
0
def enable_cluster_encryption_in_zeus():
    print_info("Setting Cluster encryption in Zeus.")
    zk_session = ZookeeperSession(connection_timeout=60)
    if not zk_session.wait_for_connection(None):
        zk_session = None

    zeus_config = Configuration().initialize(zk_session=zk_session)
    proto = zeus_config.config_proto()
    proto.cluster_encryption_params.encryption_scope = 0
    zeus_config.commit(proto)
Ejemplo n.º 3
0
def get_zeus_config():
    """
  Return the zeus config.
  """
    zk_session = ZookeeperSession(connection_timeout=60)
    if not zk_session.wait_for_connection(None):
        zk_session = None

    zeus_config = Configuration().initialize(zk_session=zk_session)
    proto = zeus_config.config_proto()
    return proto
Ejemplo n.º 4
0
 def get(self):
     bmc_ip = request.args.get("bmc_ip", None)
     with ZookeeperSession() as zks:
         creds = json.loads(zks.get(CRED_STORE_ZK))["credentials"]
         creds_list = [c for c in creds]
         if bmc_ip:
             creds_list = []
             for cred in creds:
                 if cred["bmc_ip"] == bmc_ip:
                     creds_list = [cred]
         return {"credentials": creds_list}
Ejemplo n.º 5
0
 def post(self):
     req = json.loads(request.data)
     required_keys = ["bmc_ip", "username", "password"]
     for key in required_keys:
         if key not in req:
             raise BadRequest("%s is missing" % key)
     creds_list = []
     with ZookeeperSession() as zks:
         creds = json.loads(zks.get(CRED_STORE_ZK))["credentials"]
         updated = False
         for cred in creds:
             if req["bmc_ip"] == cred["bmc_ip"]:
                 creds_list.append(req)
                 updated = True
             else:
                 creds_list.append(cred)
         if not updated:
             creds_list.append(req)
         zks.set(CRED_STORE_ZK, json.dumps({"credentials": creds_list}))
     return {"credentials": creds_list}
Ejemplo n.º 6
0
class ZeusUtil:
    def __init__(self, ip):
        self.ip = ip
        self.zks = ZookeeperSession(ip + ":9876")
        if not self.zks.wait_for_connection(20):
            log.FATAL(
                "Failed to connect to zookeeper - Check zookeeper config.")
            return False
        if self.zks.stat(EXTERNAL_CLUSTER_PATH) is None:
            self.zks.create(EXTERNAL_CLUSTER_PATH, "Nodata")

    def clean_zeus(self):
        timeout_secs = 20
        client = SSHClient(host=self.ip, user="******", password="******")
        for path in [
                EXTERNAL_CLUSTER_PATH, ZEUSCONFIG_CLUSTER_PATH,
                STATE_CLUSTER_PATH
        ]:
            cluster_list = self.zks.list(path)
            if not cluster_list:
                continue
            for cluster in cluster_list:
                cmd = ("source /etc/profile; zkrm %s/%s" % (path, cluster))
                client.execute(cmd, timeout_secs=timeout_secs)

    def create_pe_entry(self, cluster_id, node_id_list=None):
        self.create_external_cluster_entry(cluster_id)
        self.create_zeusconfig_entry(cluster_id, None, node_id_list)
        self.create_clusterdatastate_entry(cluster_id)

    def create_external_cluster_entry(self, cluster_id):
        config = ConfigurationProto()
        config.logical_timestamp = 1
        if self.zks.get(EXTERNAL_CLUSTER_PATH) is None:
            self.zks.create(EXTERNAL_CLUSTER_PATH, "")
        self.zks.create(EXTERNAL_CLUSTER_PATH + '/' + cluster_id,
                        config.SerializeToString())

    def read_external_cluster_entry(self, cluster_id):
        config = ConfigurationProto()
        cluster_ids = []
        if not cluster_id:
            cluster_ids = self.zks.list(EXTERNAL_CLUSTER_PATH)
        else:
            cluster_ids = [cluster_id]

        config_list = {}
        for cluster_id in cluster_ids:
            path = EXTERNAL_CLUSTER_PATH + '/' + cluster_id
            if not self.zks.stat(path):
                log.ERROR('Can not find path %s.' % path)
                config_list.append(None)
                continue
            config_str = self.zks.get(EXTERNAL_CLUSTER_PATH + '/' + cluster_id)
            if not config_str:
                continue
            config.ParseFromString(config_str)
            config_list[cluster_id] = config
        return config_list

    def create_zeusconfig_entry(self,
                                cluster_id,
                                cluster_name=None,
                                node_id_list=None):
        if self.zks.get(ZEUSCONFIG_CLUSTER_PATH) is None:
            self.zks.create(ZEUSCONFIG_CLUSTER_PATH, "")
        path = ZEUSCONFIG_CLUSTER_PATH + '/' + cluster_id
        config = ConfigurationProto()
        text_format.Merge(CONFIG, config)

        config.logical_timestamp = 0
        config.cluster_uuid = cluster_id
        config.cluster_name = (cluster_name or cluster_id or "Unnamed")
        config_str = config.SerializeToString()
        self.zks.create(path, config_str)

    def create_clusterdatastate_entry(self, cluster_id):
        if self.zks.get(STATE_CLUSTER_PATH) is None:
            self.zks.create(STATE_CLUSTER_PATH, "")
        path = STATE_CLUSTER_PATH + '/' + cluster_id
        state_config = ClusterDataState()
        state_config.logical_timestamp = 0
        state_config.cluster_uuid = cluster_id
        config_str = state_config.SerializeToString()
        self.zks.create(path, config_str)

    def read_zeusconfig_entry(self, cluster_uuid):
        config_str = self.zks.get(ZEUSCONFIG_CLUSTER_PATH + "/" + cluster_uuid)
        config = ConfigurationProto()
        config.ParseFromString(config_str)
        return text_format.MessageToString(config)

    def delete(self, cluster_uuid):
        self.zks.delete(EXTERNAL_CLUSTER_PATH + "/" + cluster_uuid)
        self.zks.delete(ZEUSCONFIG_CLUSTER_PATH + "/" + cluster_uuid)
        self.zks.delete(STATE_CLUSTER_PATH + "/" + cluster_uuid)

    def __del__(self):
        self.zks.close()
Ejemplo n.º 7
0
import env

import json

from zeus.zookeeper_session import ZookeeperSession

CRED_STORE_ZK = "/appliance/logical/credstore"

if __name__ == "__main__":
    with ZookeeperSession() as zks:
        zks.delete(CRED_STORE_ZK)
        a = {
            "credentials": [{
                "bmc_ip": "10.2.129.68",
                "username": "******",
                "password": "******"
            }, {
                "bmc_ip": "10.2.129.69",
                "username": "******",
                "password": "******"
            }, {
                "bmc_ip": "10.2.129.70",
                "username": "******",
                "password": "******"
            }, {
                "bmc_ip": "10.2.129.71",
                "username": "******",
                "password": "******"
            }]
        }
        zks.create(CRED_STORE_ZK, json.dumps(a))