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)
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
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()