diff options
Diffstat (limited to 'create.go')
| -rw-r--r-- | create.go | 27 |
1 files changed, 20 insertions, 7 deletions
@@ -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 |
