diff --git a/app/app.go b/app/app.go index 75063ec..2194cb6 100644 --- a/app/app.go +++ b/app/app.go @@ -35,9 +35,12 @@ func Run() { cluster := Cluster{} cluster.Init(client) start := time.Now() - log.Printf("[INFO] starting cluster sync\n") - cluster.Sync() - log.Printf("[INFO] synced cluster in %fs\n", time.Since(start).Seconds()) + err := cluster.Sync() + if err != nil { + log.Printf("[Error] error encountered while syncing cluster: %s", err) + } else { + log.Printf("[INFO] synced cluster in %fs\n", time.Since(start).Seconds()) + } // set repeating update for full rebuilds ticker := time.NewTicker(time.Duration(config.ReloadInterval) * time.Second) @@ -51,8 +54,12 @@ func Run() { case <-ticker.C: start := time.Now() log.Printf("[INFO] starting cluster sync\n") - cluster.Sync() - log.Printf("[INFO] synced cluster in %fs\n", time.Since(start).Seconds()) + err := cluster.Sync() + if err != nil { + log.Printf("[Error] error encountered while syncing cluster: %s", err) + } else { + log.Printf("[INFO] synced cluster in %fs\n", time.Since(start).Seconds()) + } } } }() @@ -188,7 +195,7 @@ func Run() { }) log.Printf("[INFO] starting API listening on 0.0.0.0:%d", config.ListenPort) - err := router.Run("0.0.0.0:" + strconv.Itoa(config.ListenPort)) + err = router.Run("0.0.0.0:" + strconv.Itoa(config.ListenPort)) if err != nil { log.Fatalf("[Err] Error starting router: %s", err.Error()) } diff --git a/app/model.go b/app/model.go index dbec44e..1a7f292 100644 --- a/app/model.go +++ b/app/model.go @@ -249,23 +249,39 @@ func (host *Node) RebuildInstance(instancetype InstanceType, vmid uint) error { host.Instances[instanceID] = instance for volid := range instance.configDisks { - instance.RebuildVolume(host, volid) + err = instance.RebuildVolume(host, volid) + if err != nil { + err_ch <- err + } } for netid := range instance.configNets { - instance.RebuildNet(host, netid) + err = instance.RebuildNet(host, netid) + if err != nil { + err_ch <- err + } } for deviceid := range instance.configHostPCIs { - instance.RebuildDevice(host, deviceid) + err = instance.RebuildDevice(host, deviceid) + if err != nil { + err_ch <- err + } } if instance.Type == VM { - instance.RebuildBoot(host) + err = instance.RebuildBoot(host) + if err != nil { + err_ch <- err + } } // after synchronizing an instance, resync pool membership - host.cluster.ResolvePoolMembership() + err = host.cluster.ResolvePoolMembership() + if err != nil { + err_ch <- err + } + err_ch <- nil }() @@ -302,11 +318,11 @@ func (instance *Instance) RebuildNet(host *Node, netid string) error { return nil } -func (instance *Instance) RebuildDevice(host *Node, deviceid string) { +func (instance *Instance) RebuildDevice(host *Node, deviceid string) error { instanceDevice, ok := instance.configHostPCIs[deviceid] if !ok { // if device does not exist - log.Printf("[WARN] %s not found in devices", deviceid) - return + log.Printf("[WARN] %s not found in devices on node %s", deviceid, host.Name) + return nil } hostDeviceBusID := DeviceID(strings.Split(instanceDevice, ",")[0]) @@ -322,9 +338,11 @@ func (instance *Instance) RebuildDevice(host *Node, deviceid string) { } instance.Devices[DeviceID(instanceDeviceBusID)].Device_ID = DeviceID(deviceid) + + return nil } -func (instance *Instance) RebuildBoot(host *Node) { +func (instance *Instance) RebuildBoot(host *Node) error { instance.Boot = BootOrder{} eligibleBoot := map[string]bool{} @@ -365,4 +383,6 @@ func (instance *Instance) RebuildBoot(host *Node) { log.Printf("[WARN] encountered disabled and non-eligible boot target %s in instance %s\n", bootTarget, instance.Name) } } + + return nil }