Skip to content

Commit

Permalink
Merge pull request #262 from PascalKu/master
Browse files Browse the repository at this point in the history
Started with HA Groups
  • Loading branch information
mleone87 authored May 14, 2023
2 parents 23ba4a4 + 1b31f1a commit 2112d12
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions proxmox/config_hagroup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package proxmox

import (
"errors"
"strings"
)

type HAGroup struct {
Comment string // Description.
Group string // The HA group identifier.
Nodes []string // List of cluster node names with optional priority. LIKE: <node>[:<pri>]{,<node>[:<pri>]}*
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, errors.New("cannot find HaGroup by name " + GroupName)
}

0 comments on commit 2112d12

Please sign in to comment.