fix bug with incomplete cluster model when node is down,
improve various error messages
This commit is contained in:
@@ -25,7 +25,7 @@ func Run() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
config := GetConfig(*configPath)
|
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)
|
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)
|
client = NewClient(config.PVE.URL, token, config.PVE.Token.Secret)
|
||||||
|
19
app/model.go
19
app/model.go
@@ -2,6 +2,7 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -26,8 +27,9 @@ func (cluster *Cluster) Sync() error {
|
|||||||
for _, hostName := range nodes {
|
for _, hostName := range nodes {
|
||||||
// rebuild node
|
// rebuild node
|
||||||
err := cluster.RebuildHost(hostName)
|
err := cluster.RebuildHost(hostName)
|
||||||
if err != nil {
|
if err != nil { // if an error was encountered, continue and log the error
|
||||||
return err
|
log.Print(err.Error())
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,8 +68,8 @@ func (cluster *Cluster) GetNode(hostName string) (*Node, error) {
|
|||||||
|
|
||||||
func (cluster *Cluster) RebuildHost(hostName string) error {
|
func (cluster *Cluster) RebuildHost(hostName string) error {
|
||||||
host, err := cluster.pve.Node(hostName)
|
host, err := cluster.pve.Node(hostName)
|
||||||
if err != nil {
|
if err != nil { // host is probably down or otherwise unreachable
|
||||||
return err
|
return fmt.Errorf("error retrieving %s: %s, possibly down?", hostName, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// aquire lock on host, release on return
|
// aquire lock on host, release on return
|
||||||
@@ -84,8 +86,9 @@ func (cluster *Cluster) RebuildHost(hostName string) error {
|
|||||||
}
|
}
|
||||||
for _, vmid := range vms {
|
for _, vmid := range vms {
|
||||||
err := host.RebuildInstance(VM, vmid)
|
err := host.RebuildInstance(VM, vmid)
|
||||||
if err != nil {
|
if err != nil { // if an error was encountered, continue and log the error
|
||||||
return err
|
log.Print(err.Error())
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,13 +150,13 @@ func (host *Node) RebuildInstance(instancetype InstanceType, vmid uint) error {
|
|||||||
var err error
|
var err error
|
||||||
instance, err = host.VirtualMachine(vmid)
|
instance, err = host.VirtualMachine(vmid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("error retrieving %d: %s, possibly down?", vmid, err.Error())
|
||||||
}
|
}
|
||||||
} else if instancetype == CT {
|
} else if instancetype == CT {
|
||||||
var err error
|
var err error
|
||||||
instance, err = host.Container(vmid)
|
instance, err = host.Container(vmid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("error retrieving %d: %s, possibly down?", vmid, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
22
app/types.go
22
app/types.go
@@ -1,6 +1,7 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/luthermonson/go-proxmox"
|
"github.com/luthermonson/go-proxmox"
|
||||||
@@ -88,3 +89,24 @@ type Function struct {
|
|||||||
VendorName string `json:"subsystem_vendor_name"`
|
VendorName string `json:"subsystem_vendor_name"`
|
||||||
Reserved bool `json:"reserved"`
|
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
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user