events is now c.E
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
bf52632cb7
commit
eacf3b8bef
27
create.go
27
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
|
||||
|
|
13
http.go
13
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
|
||||
}
|
||||
|
||||
|
|
3
poll.go
3
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue