2024-10-12 10:59:11 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"go.wit.com/lib/gui/shell"
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (h HyperT) pollHypervisor() {
|
|
|
|
url := "http://" + h.Hostname + ":2520/vms"
|
2024-10-12 11:54:01 -05:00
|
|
|
log.Log(INFO, "wget url =", url)
|
2024-10-12 10:59:11 -05:00
|
|
|
s := shell.Wget(url)
|
|
|
|
if s == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var bytesSplice []byte
|
|
|
|
bytesSplice = s.Bytes()
|
|
|
|
// fmt.Fprintln(w, string(bytesSplice))
|
|
|
|
for _, line := range strings.Split(string(bytesSplice), "\n") {
|
|
|
|
if line == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fields := strings.Fields(line)
|
|
|
|
if len(fields) < 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
state := fields[0]
|
|
|
|
name := fields[1]
|
|
|
|
if state == "ON" {
|
2024-10-12 11:54:01 -05:00
|
|
|
log.Log(POLL, h.Hostname, "STATE:", state, "HOST:", name, "rest:", fields[2:])
|
2024-10-12 10:59:11 -05:00
|
|
|
var found = false
|
|
|
|
for _, d := range me.droplets {
|
|
|
|
if d.Hostname == name {
|
2024-10-12 11:54:01 -05:00
|
|
|
log.Log(INFO, "ALREADY RECORDED", d.Hostname)
|
2024-10-12 10:59:11 -05:00
|
|
|
found = true
|
|
|
|
d.lastpoll = time.Now()
|
2024-10-12 11:54:01 -05:00
|
|
|
// log.Info("ALREADY RECORDED", d.Hostname, d.lastpoll)
|
2024-10-12 10:59:11 -05:00
|
|
|
if d.hname != h.Hostname {
|
2024-10-12 11:54:01 -05:00
|
|
|
log.Log(EVENT, "DROPLET", d.Hostname, "MOVED FROM", d.hname, "TO", d.Hostname)
|
2024-10-12 10:59:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
d.hname = h.Hostname
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if found {
|
|
|
|
continue
|
|
|
|
}
|
2024-10-12 11:54:01 -05:00
|
|
|
var d = new(DropletT)
|
2024-10-12 10:59:11 -05:00
|
|
|
d.Hostname = name
|
|
|
|
d.hname = h.Hostname
|
2024-10-12 11:54:01 -05:00
|
|
|
d.lastpoll = time.Now()
|
2024-10-12 10:59:11 -05:00
|
|
|
me.droplets = append(me.droplets, d)
|
2024-10-12 11:54:01 -05:00
|
|
|
log.Log(EVENT, name, "IS NEW. ADDED ON", h.Hostname)
|
2024-10-12 10:59:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// log.Info("i, s =", hostname, i, s)
|
|
|
|
}
|