virtigo/event.go

59 lines
1.5 KiB
Go
Raw Permalink Normal View History

package main
import (
"fmt"
"time"
"go.wit.com/lib/gui/shell"
pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/log"
)
// restarts the virtigod daemon on a hypervisor via http
func (h *HyperT) RestartVirtigod() {
url := "http://" + h.pb.Hostname + ":2520/kill"
s := shell.Wget(url)
log.Info("EVENT RestartVirtigod", url, s)
h.lastpoll = time.Now()
h.killcount += 1
dur := time.Since(h.lastpoll) // Calculate the elapsed time
log.Info("KILLED DAEMON", h.pb.Hostname, shell.FormatDuration(dur), "curl", url)
me.killcount += 1
// mark the cluster as unstable so droplet starts can be throttled
me.unstable = time.Now()
}
// this must be bool in string because accumulated output is sometimes
// written to STDOUT, sometimes to http
func (h *HyperT) start(d *pb.Droplet) (bool, string) {
ready, result := me.cluster.DropletReady(d)
if !ready {
return false, result
}
url := "http://" + h.pb.Hostname + ":2520/start?start=" + d.Hostname
var msg string
var data []byte
msg = d.FormatJSON()
data = []byte(msg) // Convert the string to []byte
req, err := httpPost(url, data)
if err != nil {
return false, fmt.Sprintln("error:", err)
}
log.Info("http post url:", url)
log.Info("http post data:", msg)
result = "EVENT start droplet url: " + url + "\n"
result += "EVENT start droplet response: " + string(req)
// increment the counter for a start attempt working
d.Current.StartAttempts += 1
// mark the cluster as unstable so droplet starts can be throttled
me.unstable = time.Now()
return true, result
}