summaryrefslogtreecommitdiff
path: root/event.go
diff options
context:
space:
mode:
Diffstat (limited to 'event.go')
-rw-r--r--event.go31
1 files changed, 18 insertions, 13 deletions
diff --git a/event.go b/event.go
index 891908a..fb8dc3b 100644
--- a/event.go
+++ b/event.go
@@ -10,16 +10,11 @@ import (
"go.wit.com/log"
)
-/*
-func (d *pb.Droplet) Start() {
- log.Info("a new virtual machine is running")
-}
-*/
-
-func (h *HyperT) RestartDaemon() {
+// 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 RestartDaemon", url, s)
+ log.Info("EVENT RestartVirtigod", url, s)
h.lastpoll = time.Now()
h.killcount += 1
@@ -56,7 +51,7 @@ func dropletReady(d *pb.Droplet) (bool, string) {
return true, ""
}
-func (h *HyperT) Start(d *pb.Droplet) (bool, string) {
+func (h *HyperT) start(d *pb.Droplet) (bool, string) {
ready, result := clusterReady()
if !ready {
return false, result
@@ -80,17 +75,27 @@ func (h *HyperT) Start(d *pb.Droplet) (bool, string) {
return true, result
}
+func findDroplet(name string) *pb.Droplet {
+ for _, d := range me.cluster.Droplets {
+ if d.Hostname == name {
+ return d
+ }
+ }
+ return nil
+}
+
+
func Start(name string) (bool, string) {
var result string
d := findDroplet(name)
if d == nil {
- result += "can't start unknown droplet"
+ result += "can't start unknown droplet: " + name
return false, result
}
if d.CurrentState == pb.DropletState_ON {
- return false, "EVENT start droplet is already ON"
+ return false, "EVENT start droplet " + d.Hostname + " is already ON"
}
dur := time.Since(me.unstable) // how long has the cluster been stable?
@@ -106,7 +111,7 @@ func Start(name string) (bool, string) {
result += fmt.Sprintln("could start droplet on", name, "on", h.pb.Hostname, h.pb.Active)
if d.PreferredHypervisor == h.pb.Hostname {
// the config file says this droplet should run on this hypervisor
- a, b := h.Start(d)
+ a, b := h.start(d)
return a, result + b
}
@@ -128,6 +133,6 @@ func Start(name string) (bool, string) {
n := a + rand.Intn(b-a)
result += fmt.Sprintln("pool has", len(pool), "members", "rand =", n)
h := pool[n]
- startbool, startresult := h.Start(d)
+ startbool, startresult := h.start(d)
return startbool, result + startresult
}