summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--create.go27
-rw-r--r--http.go13
-rw-r--r--poll.go3
-rw-r--r--structs.go1
-rw-r--r--validate.go2
5 files changed, 36 insertions, 10 deletions
diff --git a/create.go b/create.go
index f97a575..ab36093 100644
--- a/create.go
+++ b/create.go
@@ -16,18 +16,28 @@ import (
// attempts to create a new virtual machine
-func create(w http.ResponseWriter, r *http.Request) error {
+func create(w http.ResponseWriter, r *http.Request) (string, error) {
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
if err != nil {
- fmt.Fprintln(w, "ReadAll() error =", err)
- return err
+ result := fmt.Sprintf("ReadAll() error =", err)
+ log.Info(result)
+ fmt.Fprintln(w, result)
+ return result, err
}
var d *pb.Droplet
d = new(pb.Droplet)
if err := d.UnmarshalJSON(msg); err != nil {
- return err
+ log.Info("UnmarshalJSON() failed", err)
+ if err := d.Unmarshal(msg); err != nil {
+ log.Info("droplet protobuf.Unmarshal() failed", err)
+ return "", err
+ }
}
+ d.StartState = pb.DropletState_OFF
+ d.CurrentState = pb.DropletState_OFF
+ d.Memory = 2048 * 1024 * 1024
+ d.Cpus = 2
log.Info("Got msg:", string(msg))
log.Info("hostname =", d.Hostname)
@@ -35,8 +45,9 @@ func create(w http.ResponseWriter, r *http.Request) error {
tmpd := findDroplet(name)
if tmpd != nil {
result := "create error: Droplet " + name + " is already defined"
+ log.Info(result)
fmt.Fprintln(w, result)
- return errors.New(result)
+ return result, errors.New(result)
}
if d.Uuid == "" {
@@ -55,13 +66,15 @@ func create(w http.ResponseWriter, r *http.Request) error {
result, err := startDroplet(d)
if err != nil {
+ log.Info(result)
+ log.Info("startDroplet(d) failed:", err)
fmt.Fprintln(w, result)
fmt.Fprintln(w, "startDroplet(d) failed:", err)
- return err
+ return result, err
}
fmt.Fprintln(w, result)
fmt.Fprintln(w, "START=OK")
- return nil
+ return result, nil
}
// for now, because sometimes this should write to stdout and
diff --git a/http.go b/http.go
index a6092a2..971c906 100644
--- a/http.go
+++ b/http.go
@@ -58,7 +58,18 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
if route == "/create" {
- create(w, r)
+ log.Info("virtigo create starts here")
+ fmt.Fprintln(w, "virtigo create starts here")
+ result, err := create(w, r)
+ if err != nil {
+ log.Info("virtigo create failed")
+ log.Info(result)
+ fmt.Fprintln(w, "virtigo create failed")
+ fmt.Fprintln(w, result)
+ return
+ }
+ log.Info("virtigo create ends here")
+ fmt.Fprintln(w, "virtigo create ends here")
return
}
diff --git a/poll.go b/poll.go
index e82fe2e..defb947 100644
--- a/poll.go
+++ b/poll.go
@@ -111,7 +111,8 @@ func (h *HyperT) pollHypervisor() {
if dur > time.Minute*2 {
// what this means is the droplet probably wasn't migrated or the migrate failed
// where should this be checked? the status needs to be changed to OFF
- log.Info("UNKNOWN state for more than one minute remove map entry here?", name)
+ s := shell.FormatDuration(dur)
+ log.Info("UNKNOWN state for more than 2 minutes (clearing out ?)", name, s)
// it might be safe to set the status to OFF here. not really. this poll needs
// to be moved somewhere else. there needs to be a new goroutine not tied to the
diff --git a/structs.go b/structs.go
index 715231a..d8c0823 100644
--- a/structs.go
+++ b/structs.go
@@ -21,6 +21,7 @@ func (b *virtigoT) Enable() {
// this app's variables
type virtigoT struct {
cluster *pb.Cluster // basic cluster settings
+ e *pb.Events // virtbuf events
hmap map[*pb.Hypervisor]*HyperT // map to the local struct
names []string
hypers []*HyperT
diff --git a/validate.go b/validate.go
index 42c9ab6..525f57c 100644
--- a/validate.go
+++ b/validate.go
@@ -330,7 +330,7 @@ func setUniqueSpicePort(check *pb.Droplet) error {
// generate change port event
log.Info("going to try port", start, "on", check.Hostname)
e := check.NewChangeEvent("SpicePort", check.SpicePort, start)
- me.cluster.Events = append(me.cluster.Events, e)
+ me.cluster.E.Events = append(me.cluster.E.Events, e)
// set port to start
check.SpicePort = start