summaryrefslogtreecommitdiff
path: root/create.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-30 18:09:54 -0500
committerJeff Carr <[email protected]>2024-10-30 18:09:54 -0500
commiteacf3b8bef9801126c5693660acc2d03e3664025 (patch)
tree10767cfa7fedabcb77383cb556146fcdfac2db3b /create.go
parentbf52632cb79e91703079765cd8a85fc9f4098e92 (diff)
events is now c.E
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'create.go')
-rw-r--r--create.go27
1 files changed, 20 insertions, 7 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