fix bug with incomplete cluster model when node is down,

improve various error messages
This commit is contained in:
2025-04-07 19:25:28 +00:00
parent cc35e38455
commit 2265a8e580
3 changed files with 34 additions and 9 deletions

View File

@@ -25,7 +25,7 @@ func Run() {
flag.Parse()
config := GetConfig(*configPath)
log.Println("Initialized config from " + *configPath)
log.Printf("Initialized config from %s", *configPath)
token := fmt.Sprintf(`%s@%s!%s`, config.PVE.Token.USER, config.PVE.Token.REALM, config.PVE.Token.ID)
client = NewClient(config.PVE.URL, token, config.PVE.Token.Secret)

View File

@@ -2,6 +2,7 @@ package app
import (
"fmt"
"log"
"strconv"
"strings"
)
@@ -26,8 +27,9 @@ func (cluster *Cluster) Sync() error {
for _, hostName := range nodes {
// rebuild node
err := cluster.RebuildHost(hostName)
if err != nil {
return err
if err != nil { // if an error was encountered, continue and log the error
log.Print(err.Error())
continue
}
}
@@ -66,8 +68,8 @@ func (cluster *Cluster) GetNode(hostName string) (*Node, error) {
func (cluster *Cluster) RebuildHost(hostName string) error {
host, err := cluster.pve.Node(hostName)
if err != nil {
return err
if err != nil { // host is probably down or otherwise unreachable
return fmt.Errorf("error retrieving %s: %s, possibly down?", hostName, err.Error())
}
// aquire lock on host, release on return
@@ -84,8 +86,9 @@ func (cluster *Cluster) RebuildHost(hostName string) error {
}
for _, vmid := range vms {
err := host.RebuildInstance(VM, vmid)
if err != nil {
return err
if err != nil { // if an error was encountered, continue and log the error
log.Print(err.Error())
continue
}
}
@@ -147,13 +150,13 @@ func (host *Node) RebuildInstance(instancetype InstanceType, vmid uint) error {
var err error
instance, err = host.VirtualMachine(vmid)
if err != nil {
return err
return fmt.Errorf("error retrieving %d: %s, possibly down?", vmid, err.Error())
}
} else if instancetype == CT {
var err error
instance, err = host.Container(vmid)
if err != nil {
return err
return fmt.Errorf("error retrieving %d: %s, possibly down?", vmid, err.Error())
}
}

View File

@@ -1,6 +1,7 @@
package app
import (
"fmt"
"sync"
"github.com/luthermonson/go-proxmox"
@@ -88,3 +89,24 @@ type Function struct {
VendorName string `json:"subsystem_vendor_name"`
Reserved bool `json:"reserved"`
}
func (cluster *Cluster) String() string {
s := "cluster:\n"
for _, node := range cluster.Nodes {
s += fmt.Sprintf("\t%s", node)
}
return s
}
func (node *Node) String() string {
s := fmt.Sprintf("%s:\n", node.Name)
for vmid, instance := range node.Instances {
s += fmt.Sprintf("\t\t%d:%s\n", vmid, instance)
}
return s
}
func (instance *Instance) String() string {
s := fmt.Sprintf("%s", instance.Name)
return s
}