diff --git a/main.go b/main.go index e09de05..926d687 100644 --- a/main.go +++ b/main.go @@ -144,7 +144,7 @@ func main() { h.lastpoll = time.Now() me.hmap[pbh] = h - // me.hypers = append(me.hypers, h) + me.hypers = append(me.hypers, h) log.Log(EVENT, "config new hypervisors", h.pb.Hostname) } diff --git a/poll.go b/poll.go index 9b0d62d..778587a 100644 --- a/poll.go +++ b/poll.go @@ -39,36 +39,35 @@ func (h *HyperT) pollHypervisor() { } log.Log(INFO, "ALREADY RECORDED", d.Hostname) - // update the status to ON and the last polled value + // update the status to ON d.CurrentState = pb.DropletState_ON + // set the LastPoll time to now now := time.Now() d.LastPoll = timestamppb.New(now) - var cur *HyperT - // cur := find(d.CurrentHypervisor) - if cur == nil { + if d.CurrentHypervisor == "" { // this means the droplet was in the config file // but this is the first time it's shown up as running // this should mean a droplet is running where the config file says it probably should be running if d.PreferredHypervisor == h.pb.Hostname { - log.Log(EVENT, "new droplet", d.Hostname, "(matches config hypervisor", h.pb.Hostname+")") - cur = h + log.Log(EVENT, "poll shows new droplet", d.Hostname, "(matches config hypervisor", h.pb.Hostname+")") + d.CurrentHypervisor = h.pb.Hostname continue } - log.Log(EVENT, "new droplet", d.Hostname, "on", h.pb.Hostname, "(in config file without preferred hypervisor)") - cur = h + log.Log(EVENT, "poll shows new droplet", d.Hostname, "on", h.pb.Hostname, "(in config file without preferred hypervisor)") + d.CurrentHypervisor = h.pb.Hostname continue } - // this means the droplet is still where it was before - if cur.pb.Hostname != h.pb.Hostname { + // this means the droplet has moved + if d.CurrentHypervisor != h.pb.Hostname { log.Log(EVENT, "droplet", d.Hostname, "moved to", h.pb.Hostname) continue } - cur = h + d.CurrentHypervisor = h.pb.Hostname } continue } @@ -77,13 +76,11 @@ func (h *HyperT) pollHypervisor() { } func findDroplet(name string) *pb.Droplet { - /* - for _, d := range me.droplets { - if d.Hostname == name { - return d - } + for _, d := range me.cluster.Droplets { + if d.Hostname == name { + return d } - */ + } return nil }