diff --git a/app/app.go b/app/app.go index 0da2b82..a0a71ef 100644 --- a/app/app.go +++ b/app/app.go @@ -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) diff --git a/app/model.go b/app/model.go index f25c617..c4d172d 100644 --- a/app/model.go +++ b/app/model.go @@ -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()) } } diff --git a/app/types.go b/app/types.go index 5e6c62d..59aecd4 100644 --- a/app/types.go +++ b/app/types.go @@ -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 +}