From b61f886061ad22bb92f9c14220de7d119878dd94 Mon Sep 17 00:00:00 2001 From: bixiaoyan Date: Mon, 2 Dec 2024 15:57:00 +0800 Subject: [PATCH] fix clusterAdd function --- models/manage_clusters.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/models/manage_clusters.go b/models/manage_clusters.go index 3b31be3..803fdbc 100644 --- a/models/manage_clusters.go +++ b/models/manage_clusters.go @@ -10,7 +10,6 @@ import ( "os" "strings" "time" - "github.com/pkg/errors" "gitee.com/openeuler/ha-api/settings" @@ -72,6 +71,7 @@ type AuthRetA struct { Message string `json:"message,omitempty"` } + // NewClustersInfo creates a new ClustersInfo instance using the provided text data. // If the text data is nil or empty, default values are initialized. func NewClustersInfo(text map[string]interface{}) *ClustersInfo { @@ -343,18 +343,16 @@ func hostAuth(authInfo map[string]interface{}) map[string]interface{} { authFailed := false nodeList := authInfo["node_list"].([]string) passwordList := authInfo["password"].([]string) - + fmt.Println(nodeList,passwordList) for i := 0; i < len(nodeList); i++ { authCmd := fmt.Sprintf(utils.CmdHostAuthNode, nodeList[i], passwordList[i]) - _, err := utils.RunCommand(authCmd) - if err != nil { authFailed = true break } } - + if authFailed { return map[string]interface{}{ "action": false, @@ -395,8 +393,15 @@ func hostAuthWithAddr(authInfo AuthInfo) AuthRetA { // Returns results indicating the success or failure of the operation. func ClusterAdd(nodeInfo map[string]interface{}) map[string]interface{} { authInfo := make(map[string]interface{}) - authInfo["node_list"] = nodeInfo["node_name"].(string) - authInfo["password"] = nodeInfo["password"].(string) + nodeList := make([]string, 0) + passwords := make([]string, 0) + + + nodeList = append(nodeList, nodeInfo["node_name"].(string)) + passwords = append(passwords, nodeInfo["password"].(string)) + + authInfo["node_list"] = nodeList + authInfo["password"] = passwords authRes := hostAuth(authInfo) -- Gitee