diff options
Diffstat (limited to 'poll.go')
| -rw-r--r-- | poll.go | 47 |
1 files changed, 31 insertions, 16 deletions
@@ -32,29 +32,44 @@ func (h *HyperT) pollHypervisor() { if state == "ON" { log.Log(POLL, h.Hostname, "STATE:", state, "HOST:", name, "rest:", fields[2:]) d := findDroplet(name) - if d != nil { - log.Log(INFO, "ALREADY RECORDED", d.Hostname) + if d == nil { + // this is a new unknown droplet (not in the config file) + d = new(DropletT) + d.Hostname = name + d.hname = h.Hostname d.lastpoll = time.Now() d.CurrentState = "ON" - // log.Info("ALREADY RECORDED", d.Hostname, d.lastpoll) - if d.hname == "" { - log.Log(EVENT, "DROPLET", d.Hostname, "PROBABLY WAS NEVER POLLED YET") - } - if d.hname != h.Hostname { - log.Log(EVENT, "DROPLET", d.Hostname, "MOVED FROM", d.hname, "TO", h.Hostname) + me.droplets = append(me.droplets, d) + log.Log(EVENT, name, "IS NEW. ADDED ON", h.Hostname) + } + log.Log(INFO, "ALREADY RECORDED", d.Hostname) + + // update the status to ON and the last polled value + d.CurrentState = "ON" + d.lastpoll = time.Now() + + // this means the droplet is still where it was before + if d.hname == h.Hostname { + continue + } + + if d.hname == "" { + // 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.hyperPreferred == h.Hostname { + log.Log(EVENT, "new droplet", d.Hostname, "(matches config hypervisor", h.Hostname + ")") d.hname = h.Hostname + continue } - continue + + log.Log(EVENT, "new droplet", d.Hostname, "was not in the config file") + log.Log(EVENT, "new droplet", d.Hostname, "moved", d.hname, h.Hostname, "config file hypervisor =", d.hname) } - // this is a new unknown droplet (not in the config file) - d = new(DropletT) - d.Hostname = name d.hname = h.Hostname - d.lastpoll = time.Now() - d.CurrentState = "ON" - me.droplets = append(me.droplets, d) - log.Log(EVENT, name, "IS NEW. ADDED ON", h.Hostname) } + continue } h.lastpoll = time.Now() h.killcount = 0 // poll worked. reset killcount |
