From 8c1c265f3f9cd5e4f00d9407ccb3b81e022090b6 Mon Sep 17 00:00:00 2001 From: Pascal Kutscha Date: Fri, 5 May 2023 21:00:16 +0200 Subject: [PATCH 1/2] added HaGroups retrieving --- proxmox/config_hagroup.go | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 proxmox/config_hagroup.go diff --git a/proxmox/config_hagroup.go b/proxmox/config_hagroup.go new file mode 100644 index 00000000..e9f9ad9a --- /dev/null +++ b/proxmox/config_hagroup.go @@ -0,0 +1,53 @@ +package proxmox + +import "strings" + +type HAGroup struct { + Comment string // Description. + Group string // The HA group identifier. + Nodes []string // List of cluster node names with optional priority. LIKE: [:]{,[:]}* + NoFailback bool // The CRM tries to run services on the node with the highest priority. If a node with higher priority comes online, the CRM migrates the service to that node. Enabling nofailback prevents that behavior. + Restricted bool // Resources bound to restricted groups may only run on nodes defined by the group. + Type string // Group type +} + +func (c *Client) GetHAGroupList() (haGroups []HAGroup, err error) { + list, err := c.GetItemList("/cluster/ha/groups") + + if err != nil { + return nil, err + } + + haGroups = []HAGroup{} + + for _, item := range list["data"].([]interface{}) { + itemMap := item.(map[string]interface{}) + + haGroups = append(haGroups, HAGroup{ + Comment: itemMap["comment"].(string), + Group: itemMap["group"].(string), + Nodes: strings.Split(itemMap["nodes"].(string), ","), + NoFailback: itemMap["nofailback"].(float64) == 1, + Restricted: itemMap["restricted"].(float64) == 1, + Type: itemMap["type"].(string), + }) + } + + return haGroups, nil +} + +func (c *Client) GetHAGroupByName(GroupName string) (*HAGroup, error) { + groups, err := c.GetHAGroupList() + + if err != nil { + return nil, err + } + + for _, item := range groups { + if item.Group == GroupName { + return &item, nil + } + } + + return nil, nil +} From 1b31f1aa63faadb731ca0cf39b0962de8aa06931 Mon Sep 17 00:00:00 2001 From: Pascal Kutscha Date: Fri, 5 May 2023 21:02:44 +0200 Subject: [PATCH 2/2] fixing error message when fetching HaGroupByName which does not exists! --- proxmox/config_hagroup.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/proxmox/config_hagroup.go b/proxmox/config_hagroup.go index e9f9ad9a..67adfea1 100644 --- a/proxmox/config_hagroup.go +++ b/proxmox/config_hagroup.go @@ -1,6 +1,9 @@ package proxmox -import "strings" +import ( + "errors" + "strings" +) type HAGroup struct { Comment string // Description. @@ -49,5 +52,5 @@ func (c *Client) GetHAGroupByName(GroupName string) (*HAGroup, error) { } } - return nil, nil + return nil, errors.New("cannot find HaGroup by name " + GroupName) }