From b98db8c8b00c714a630c583834a51e22b6599a8b Mon Sep 17 00:00:00 2001 From: bixiaoyan Date: Fri, 14 Feb 2025 11:04:01 +0800 Subject: [PATCH] fix is_cluster_exist route function --- controllers/cluster.go | 4 ++-- models/manage_clusters.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/controllers/cluster.go b/controllers/cluster.go index 9aca517..ceb93e9 100644 --- a/controllers/cluster.go +++ b/controllers/cluster.go @@ -1,6 +1,6 @@ /* * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. - * ha-api licensed under the Mulan Permissive Software License, Version 2. + * ha-api licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. * Author: Jason011125 * Date: Mon Aug 14 13:38:45 2023 +0800 @@ -153,7 +153,7 @@ func (lci *LocalClusterInfoController) Get() { func (ice *IsClusterExistController) Get() { logs.Debug("handle get request in IsClusterExistController.") - result := models.IsClusterExist() + result := models.CheckIsClusterExist() ice.Data["json"] = &result ice.ServeJSON() } diff --git a/models/manage_clusters.go b/models/manage_clusters.go index ce939d9..ad4b5e5 100644 --- a/models/manage_clusters.go +++ b/models/manage_clusters.go @@ -345,6 +345,36 @@ func checkOneClusterExist(localConf *ClustersInfo, cluster Cluster, wg *sync.Wai handleExistClusterConf(realNodeNum, confNodeSum, clusterConf, cluster, localConf, cluster.ClusterName) } +func CheckIsClusterExist() map[string]interface{} { + result := map[string]interface{}{} + _, err := os.Stat(settings.CorosyncConfFile) + if err == nil { + cmd := "cat /etc/corosync/corosync.conf | grep \"cluster_name\"" + out, err := utils.RunCommand(cmd) + var clusterName string + if err != nil { + result["action"] = false + result["error"] = "Get cluster name failed" + return result + } else { + clusterName = strings.Split(string(out), ": ")[1] + clusterName = strings.ReplaceAll(clusterName, "\n", "") + + } + + allInfo := GetClusterInfo() + if allInfo["cluster_exist"] == true { + clusterInfo := clusterInfoParse(allInfo) + result["action"] = true + result["cluster_name"] = clusterName + result["cluster_conf"] = clusterInfo + return result + + } + } + result["action"] = false + return result +} func handleExistClusterConf(realNodeNum, confNodeSum int, clusterConf Cluster, cluster Cluster, localConf *ClustersInfo, s string) { panic("unimplemented") } -- Gitee