def check_node_yml(self, node_yml): """ 校验配置文件,补充必要的字段 :param node_yml:节点配置文件路径 :return: - host: 10.10.8.237 port: 16789 rpcport: 6789 username: juzhen password: Platon123! id: 0afbd5564f886966493c2f4efb25d...df67474ff3bd6ce nodekey: 0b304c9e039b62269be...1adef94e8e114d7d url: http://10.10.8.237:6789 """ collusion_list, nocollusion_list = get_node_list(node_yml) result = {} result_collusion_list = [] result_nocollusion_list = [] update = 0 if len(collusion_list) >= 1: for nodedict in collusion_list: nodedict, update = self.handle_nodedict(nodedict, update) result_collusion_list.append(nodedict) result["collusion"] = result_collusion_list if len(nocollusion_list) >= 1: for nodedict in nocollusion_list: nodedict, update = self.handle_nodedict(nodedict, update) result_nocollusion_list.append(nodedict) result["nocollusion"] = result_nocollusion_list if update == 1: with open(node_yml, encoding="utf-8", mode="w") as f: yaml.dump(result, f, Dumper=yaml.RoundTripDumper)
def booms(self, node_yaml): """ 根据节点配置文件,关闭节点机器所有platon进程,关闭后节点无法重启 :param node_yaml: 节点配置文件路径 :return: """ collusion_list, nocollusion_list = get_node_list(node_yaml) node_list = collusion_list + nocollusion_list self.booms_of_list(node_list)
def kill_of_yaml(self, node_yaml): """ 根据节点配置文件,以kill方式关闭节点,关闭后,节点还能被重启 :param node_yaml: 节点配置文件路径 :return: """ collusion_list, nocollusion_list = get_node_list(node_yaml) node_list = collusion_list + nocollusion_list self.kill_of_list(node_list)
def stop_of_yml(self, node_yml: str): """ 根据配置文件,关闭节点,关闭后节点无法重启,只能重新部署链 :param node_yml: 节点配置文件路径 :return: """ collusion_list, nocollusion_list = get_node_list(node_yml) node_list = collusion_list + nocollusion_list self.stop_of_list(node_list)
def restart_yml(self, node_yml): """ 根据配置文件重启节点 :param node_yml: 节点配置文件 :return: """ self.check_node_yml(node_yml) collusion_list, nocollusion_list = get_node_list(node_yml) node_list = collusion_list + nocollusion_list self.restart_list(node_list)
def deploy_default_yml(self, node_yml): """ 根据节点配置文件,使用默认参数部署节点 :param node_yml: 节点配置文件 :return: """ self.check_node_yml(node_yml) collusion_list, nocollusion_list = get_node_list(node_yml) node_list = collusion_list + nocollusion_list self.deploy_default_list(node_list)
def update_node_yml(self, node_yml): """ 根据节点配置文件,更新节点 :param node_yml: 节点配置文件 :return: """ self.check_node_yml(node_yml) collusion_list, nocollusion_list = get_node_list(node_yml) node_list = collusion_list + nocollusion_list self.update_node_list(node_list)
def monitor(node_file): node_list, _ = get_node_list(node_file) w3_list = [connect_web3(node["url"]) for node in node_list] node_id = [node["id"] for node in node_list] import time z = 1 while True: time.sleep(10) i = 0 for w3 in w3_list: print("节点{},块高:{}".format(node_id[i], w3.eth.blockNumber)) i = +1 print("第{}窗口期共识结束..........".format(z)) z += 1
def start_all_node(self, node_yml, genesis_file=None, static_node_file=None, is_need_init=True, genesis_path=conf.GENESIS_TMP, clean=False): """ 根据节点配置文件,启动节点 :param node_yml: 节点配置文件 :param genesis_file: genesis.json文件路径,is_need_init=True时且genesis_file为空时,会根据共识节点列表生成 :param static_node_file: 共识节点互连文件,为空时会根据共识节点生成 :param is_need_init: 是否需要初始化,初始化会删除原platon部署目录的所有数据 :param genesis_path: 新生成的genesis.json保存路径 :param clean: 是否删除platon部署目录的数据,is_need_init=True时,该参数无效 :return: """ self.check_node_yml(node_yml) collusion_list, nocollusion_list = get_node_list(node_yml) self.start_of_list(collusion_list, nocollusion_list, genesis_file=genesis_file, static_node_file=static_node_file, is_need_init=is_need_init, genesis_path=genesis_path, clean=clean)