def prepare_suppl_pgsinfo(cluster_name, pg_id, pm_name, pm_ip): # Set host host = config.USERNAME + '@' + pm_ip.encode('ascii') env.hosts = [host] # Get port port = PortAllocator(host, config.REMOTE_PGS_DIR, config.PGS_BASE_PORT).next() # Get pgs_id pm = cm.pm_info(pm_name) if pm != None: pgs_id = -1 for cluster in pm['cluster_list']: for name, data in cluster.items(): if name == cluster_name: pgs_id = max(int(x) for x in data['pgs_ID_List']) + 1 print yellow("[%s] Use max pgs_id in cluster. PGS_ID:%d, PM_NAME:%s, PM_IP:%s" % (host, pgs_id, pm_name, pm_ip)) break if pgs_id == -1: pgs_ids = cm.pgs_ls(cluster_name) if pgs_ids == None: return None pgs_id = max(int(x) for x in pgs_ids['data']['list']) pgs_id += 1 print yellow("[%s] Use max pgs_id in cluster. PGS_ID:%d, PM_NAME:%s, PM_IP:%s" % (host, pgs_id, pm_name, pm_ip)) return {"pgs_id" : pgs_id, "smr_base_port" : port, "redis_port" : port + 9}
def prepare_suppl_pgsinfo(cluster_name, pg_id, pm_name, pm_ip): # Set host host = config.USERNAME + '@' + pm_ip.encode('ascii') env.hosts = [host] # Get port port = PortAllocator(host, config.REMOTE_PGS_DIR, config.PGS_BASE_PORT).next() # Get pgs_id pm = cm.pm_info(pm_name) if pm != None: pgs_id = -1 for cluster in pm['cluster_list']: for name, data in cluster.items(): if name == cluster_name: pgs_id = max(int(x) for x in data['pgs_ID_List']) + 1 print yellow( "[%s] Use max pgs_id in cluster. PGS_ID:%d, PM_NAME:%s, PM_IP:%s" % (host, pgs_id, pm_name, pm_ip)) break if pgs_id == -1: pgs_ids = cm.pgs_ls(cluster_name) if pgs_ids == None: return None pgs_id = max(int(x) for x in pgs_ids['data']['list']) pgs_id += 1 print yellow( "[%s] Use max pgs_id in cluster. PGS_ID:%d, PM_NAME:%s, PM_IP:%s" % (host, pgs_id, pm_name, pm_ip)) return {"pgs_id": pgs_id, "smr_base_port": port, "redis_port": port + 9}
def get_all_pgs_info(cluster_name, memlog): # Get cluster information pgs_ls_json = cm.pgs_ls(cluster_name) if pgs_ls_json == None: warn(red("Failed to load list of pgs in %s" % cluster_name)) return None # Get pgs id list pgs_id_list = map(lambda pgs_id: int(pgs_id), pgs_ls_json['data']['list']) if len(pgs_id_list) == 0: return None # Get pgs information pgs_list = get_deployed_pgs_info(cluster_name, pgs_id_list, memlog) if pgs_list == None: return None return sorted(pgs_list, key=lambda x: int(x['pgs_id']))