diff --git a/models/heartbeat.go b/models/heartbeat.go index cf6855d9a63deb33bcc06fdc7c5f5fbf20dc12ee..742743d3974af9f810770e721f9e391766bc51b1 100644 --- a/models/heartbeat.go +++ b/models/heartbeat.go @@ -228,7 +228,6 @@ type HBInfo struct { // ExtractHbInfo reorganizes heartbeat information format func ExtractHbInfo(hbInfo []map[string]string) ([]map[string]string, []string) { var hbDictList []map[string]string - var ids []string if len(hbInfo) == 0 { return nil, nil @@ -251,7 +250,7 @@ func ExtractHbInfo(hbInfo []map[string]string) ([]map[string]string, []string) { } hbDictList = append(hbDictList, hbDict) } - return hbDictList, ids + return hbDictList, numIds } // get net heartbeat info from corosync conf @@ -470,6 +469,11 @@ func GetConnectedNetLinksId() []string { return ConnectedLinkIds } +func SyncCorosyncConf() error { + _, err := utils.RunCommand(utils.CmdSyncCorosyncConf) + return err +} + func GetCurrentLinkIds() []string { linksInfo, _ := ExtractHbInfoFromConf() ids := make([]string, 0, len(linksInfo)) diff --git a/utils/command.go b/utils/command.go index 81f3505d8e28c658d569b0224b48440da6fe81c4..1cf5d0894c0363f42224ef8f56d52343cc0a94a6 100644 --- a/utils/command.go +++ b/utils/command.go @@ -33,7 +33,7 @@ const ( CmdQueryConstraints = "cibadmin --query --scope constraints" CmdQueryResourcesById = "cibadmin --query --scope resources|grep 'id=\"%s\"'" - CmdStartCluster = "pcs cluster start " + CmdStartCluster = "pcs cluster start --all " CmdStopClusterLocal = "pcs cluster stop " CmdStopCluster = "pcs cluster stop --all" CmdSetupCluster = "pcs cluster setup hacluster" @@ -98,6 +98,7 @@ const ( CmdHbStatusS = "corosync-cfgtool -s" CmdUpdateLink = "pcs cluster link update %s %s" CmdUpdateLinkForce = CmdUpdateLink + " --force" + CmdSyncCorosyncConf = "pcs cluster sync" ) // RunCommand runs the command and get the result diff --git a/utils/host.go b/utils/host.go index c45b4baa36d1cefc003ffdef03ae31bb22209f43..e2aaab0b54ca82544a55f1ba3fe28f00937b7f64 100644 --- a/utils/host.go +++ b/utils/host.go @@ -20,7 +20,7 @@ import ( ) func GetNodeList() ([]map[string]string, error) { - config, err := getCorosyncConfig() + config, err := GetCorosyncConfig() if err != nil { return nil, errors.New("read config from /etc/corosync/corosync.conf failed") } @@ -39,7 +39,7 @@ type CorosyncConfig struct { Logging map[string]interface{} } -func getCorosyncConfig() (CorosyncConfig, error) { +func GetCorosyncConfig() (CorosyncConfig, error) { var result CorosyncConfig f, err := os.Open(settings.CorosyncConfFile) if err != nil { @@ -169,7 +169,7 @@ func getCorosyncConfig() (CorosyncConfig, error) { return result, nil } -func setCorosyncConfig(conf CorosyncConfig, confFile string) error { +func SetCorosyncConfig(conf CorosyncConfig, confFile string) error { var sb strings.Builder // Write totem section sb.WriteString("totem {\n") diff --git a/utils/host_test.go b/utils/host_test.go index cb017e2eaa11f6f07e70c5da02300b560a939d8c..64b710d2bd482268984af03b10a30dbcd673b618 100644 --- a/utils/host_test.go +++ b/utils/host_test.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: yangzhao_kl * Date: Fri Jan 22 17:27:48 2021 +0800 @@ -13,7 +13,7 @@ import ( ) func TestGetCorosyncConfig(t *testing.T) { - result, err := getCorosyncConfig() + result, err := GetCorosyncConfig() if err != nil { fmt.Println(err) return