def etcd_fix(self, args): cluster_object_model_k8s, node_list = self.process_args(args) if len(node_list["machine-list"]) > 1: logger.error("etcd-fix can't fix more than one machine everytime. Please fix them one by one!") sys.exit(1) for host in node_list["machine-list"]: etcd_fix_worker = k8s_etcd_fix.etcdfix(cluster_object_model_k8s, host, True) etcd_fix_worker.run() logger.info("Etcd has been fixed.")
def pai_machine(): if len(sys.argv) < 2: pai_machine_info() return option = sys.argv[1] del sys.argv[1] if option not in ["add", "remove", "etcd-fix"]: pai_machine_info() return parser = argparse.ArgumentParser() parser.add_argument('-p', '--config-path', dest="config_path", required=True, help="The path of your configuration directory.") parser.add_argument('-l', '--node-list', dest="node_list", required=True, help="The node-list to be operator") args = parser.parse_args(sys.argv[1:]) config_path = args.config_path node_lists_path = args.node_list cluster_object_model = cluster_object_model_generate_service(config_path) cluster_object_model_k8s = cluster_object_model_generate_k8s(config_path) node_list = file_handler.load_yaml_config(node_lists_path) if kubectl_env_checking(cluster_object_model_k8s) == False: return for host in node_list['machine-list']: if 'nodename' not in host: host['nodename'] = host['hostip'] if option == "add": for host in node_list['machine-list']: add_worker = k8s_add.add(cluster_object_model_k8s, host, True) add_worker.run() if host['k8s-role'] == 'master': logger.info( "Master Node is added, sleep 60s to wait it ready.") time.sleep(60) if option == "remove": for host in node_list['machine-list']: add_worker = k8s_remove.remove(cluster_object_model_k8s, host, True) add_worker.run() if host['k8s-role'] == 'master': logger.info( "master node is removed, sleep 60s for etcd cluster's updating" ) time.sleep(60) if option == "etcd-fix": if len(node_list['machine-list']) > 1: logger.error( "etcd-fix can't fix more than one machine everytime. Please fix them one by one!" ) sys.exit(1) for host in node_list['machine-list']: etcd_fix_worker = k8s_etcd_fix.etcdfix(cluster_object_model_k8s, host, True) etcd_fix_worker.run() logger.info("Etcd has been fixed.")