From 9b34068a3a2c2321ebd86ffee0be442253937063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A0=E7=A3=8A?= Date: Tue, 8 Oct 2024 15:32:56 +0800 Subject: [PATCH 1/2] Include SSH key as an interaction item when configuring parameters --- common/config_helper.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/common/config_helper.py b/common/config_helper.py index 7310653e..c8e0ee9d 100644 --- a/common/config_helper.py +++ b/common/config_helper.py @@ -100,14 +100,20 @@ def build_configuration(self): ob_cluster_name = self.get_cluster_name() self.stdio.print("\033[33mPlease enter the following configuration !!!\033[0m") global_ssh_username = self.input_with_default("oceanbase host ssh username", "") - global_ssh_password = self.input_password_with_default("oceanbase host ssh password", "") + use_password_tag = self.input_choice_default("use password or key file (Y:use password; N :use key file) [Y/N]", "Y") + global_ssh_password = "" + global_ssh_key_file = "" + if use_password_tag: + global_ssh_password = self.input_password_with_default("oceanbase host ssh password", "") + else: + global_ssh_key_file = self.input_with_default("oceanbase host ssh key file", "~/.ssh/id_rsa") global_ssh_port = self.input_with_default("oceanbase host ssh_port", "22") global_home_path = self.input_with_default("oceanbase install home_path", const.OB_INSTALL_DIR_DEFAULT) default_data_dir = os.path.join(global_home_path, "store") global_data_dir = default_data_dir global_redo_dir = default_data_dir tenant_sys_config = {"user": self.sys_tenant_user, "password": self.sys_tenant_password} - global_config = {"ssh_username": global_ssh_username, "ssh_password": global_ssh_password, "ssh_port": global_ssh_port, "ssh_key_file": "", "home_path": global_home_path, "data_dir": global_data_dir, "redo_dir": global_redo_dir} + global_config = {"ssh_username": global_ssh_username, "ssh_password": global_ssh_password, "ssh_port": global_ssh_port, "ssh_key_file": global_ssh_key_file, "home_path": global_home_path, "data_dir": global_data_dir, "redo_dir": global_redo_dir} new_config = {"obcluster": {"ob_cluster_name": ob_cluster_name, "db_host": self.db_host, "db_port": self.db_port, "tenant_sys": tenant_sys_config, "servers": {"nodes": nodes_config, "global": global_config}}} YamlUtils.write_yaml_data(new_config, self.config_path) need_config_obproxy = self.input_choice_default("need config obproxy [y/N]", "N") From c248b22e688829c3cef33b999a6aa136889c2f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A0=E7=A3=8A?= Date: Tue, 8 Oct 2024 20:33:56 +0800 Subject: [PATCH 2/2] update --- common/config_helper.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/common/config_helper.py b/common/config_helper.py index c8e0ee9d..5fca8245 100644 --- a/common/config_helper.py +++ b/common/config_helper.py @@ -100,13 +100,16 @@ def build_configuration(self): ob_cluster_name = self.get_cluster_name() self.stdio.print("\033[33mPlease enter the following configuration !!!\033[0m") global_ssh_username = self.input_with_default("oceanbase host ssh username", "") - use_password_tag = self.input_choice_default("use password or key file (Y:use password; N :use key file) [Y/N]", "Y") + use_password_tag = self.input_choice_by_nu("use password or key file (0:use password; 1:use key file) default: 0", 0) global_ssh_password = "" global_ssh_key_file = "" - if use_password_tag: + if use_password_tag == 0: global_ssh_password = self.input_password_with_default("oceanbase host ssh password", "") - else: + elif use_password_tag == 1: global_ssh_key_file = self.input_with_default("oceanbase host ssh key file", "~/.ssh/id_rsa") + else: + self.stdio.warn("Invalid input, use default: use password") + global_ssh_password = self.input_password_with_default("oceanbase host ssh password", "") global_ssh_port = self.input_with_default("oceanbase host ssh_port", "22") global_home_path = self.input_with_default("oceanbase install home_path", const.OB_INSTALL_DIR_DEFAULT) default_data_dir = os.path.join(global_home_path, "store") @@ -176,3 +179,12 @@ def input_choice_default(self, prompt, default): return True else: return False + + def input_choice_by_nu(self, prompt, default): + value = input("\033[32mEnter your {0}: \033[0m".format(prompt)).strip() + if value == '': + return int(default) + if not value.isdigit(): + self.stdio.error("The number is invalid! Please re-enter.") + return self.input_choice_by_nu(prompt, default) + return int(value)