def leader_elected(): if not leader_get("db_user"): user = "******" password = uuid.uuid4().hex leader_set(db_user=user, db_password=password) if not leader_get("rabbitmq_password_int"): password = uuid.uuid4().hex leader_set(rabbitmq_password_int=password) update_northbound_relations() ip_list = json_loads(leader_get("controller_ip_list"), list()) ips = get_controller_ips() if not ip_list: ip_list = ips.values() log("IP_LIST: {} IPS: {}".format(str(ip_list), str(ips))) leader_set(controller_ip_list=json.dumps(ip_list), controller_ips=json.dumps(ips)) # TODO: pass this list to all south/north relations else: current_ip_list = ips.values() dead_ips = set(ip_list).difference(current_ip_list) new_ips = set(current_ip_list).difference(ip_list) if new_ips: log("There are a new controllers that are not in the list: " + str(new_ips), level=ERROR) if dead_ips: log("There are a dead controllers that are in the list: " + str(dead_ips), level=ERROR) update_charm_status()
def leader_elected(): ip = common_utils.get_ip() data_ip = common_utils.get_ip(config_param="data-network", fallback=ip) for var_name in [("ip", "unit-address", ip), ("data_ip", "data-address", data_ip)]: ip_list = common_utils.json_loads( leader_get("controller_{}_list".format(var_name[0])), list()) ips = utils.get_controller_ips(var_name[1], var_name[2]) if not ip_list: ip_list = ips.values() log("{}_LIST: {} {}S: {}".format(var_name[0].upper(), str(ip_list), var_name[0].upper(), str(ips))) settings = { "controller_{}_list".format(var_name[0]): json.dumps(list(ip_list)), "controller_{}s".format(var_name[0]): json.dumps(ips) } leader_set(settings=settings) else: current_ip_list = ips.values() dead_ips = set(ip_list).difference(current_ip_list) new_ips = set(current_ip_list).difference(ip_list) if new_ips: log("There are a new controllers that are not in the list: " + str(new_ips), level=ERROR) if dead_ips: log("There are a dead controllers that are in the list: " + str(dead_ips), level=ERROR) update_northbound_relations() update_southbound_relations() utils.update_charm_status()