events is now c.E

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-30 18:09:54 -05:00
parent bf52632cb7
commit eacf3b8bef
5 changed files with 36 additions and 10 deletions

View File

@ -16,18 +16,28 @@ import (
// attempts to create a new virtual machine // 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 msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
if err != nil { if err != nil {
fmt.Fprintln(w, "ReadAll() error =", err) result := fmt.Sprintf("ReadAll() error =", err)
return err log.Info(result)
fmt.Fprintln(w, result)
return result, err
} }
var d *pb.Droplet var d *pb.Droplet
d = new(pb.Droplet) d = new(pb.Droplet)
if err := d.UnmarshalJSON(msg); err != nil { 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("Got msg:", string(msg))
log.Info("hostname =", d.Hostname) log.Info("hostname =", d.Hostname)
@ -35,8 +45,9 @@ func create(w http.ResponseWriter, r *http.Request) error {
tmpd := findDroplet(name) tmpd := findDroplet(name)
if tmpd != nil { if tmpd != nil {
result := "create error: Droplet " + name + " is already defined" result := "create error: Droplet " + name + " is already defined"
log.Info(result)
fmt.Fprintln(w, result) fmt.Fprintln(w, result)
return errors.New(result) return result, errors.New(result)
} }
if d.Uuid == "" { if d.Uuid == "" {
@ -55,13 +66,15 @@ func create(w http.ResponseWriter, r *http.Request) error {
result, err := startDroplet(d) result, err := startDroplet(d)
if err != nil { if err != nil {
log.Info(result)
log.Info("startDroplet(d) failed:", err)
fmt.Fprintln(w, result) fmt.Fprintln(w, result)
fmt.Fprintln(w, "startDroplet(d) failed:", err) fmt.Fprintln(w, "startDroplet(d) failed:", err)
return err return result, err
} }
fmt.Fprintln(w, result) fmt.Fprintln(w, result)
fmt.Fprintln(w, "START=OK") fmt.Fprintln(w, "START=OK")
return nil return result, nil
} }
// for now, because sometimes this should write to stdout and // for now, because sometimes this should write to stdout and

13
http.go
View File

@ -58,7 +58,18 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
} }
if route == "/create" { 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 return
} }

View File

@ -111,7 +111,8 @@ func (h *HyperT) pollHypervisor() {
if dur > time.Minute*2 { if dur > time.Minute*2 {
// what this means is the droplet probably wasn't migrated or the migrate failed // 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 // 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 // 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 // to be moved somewhere else. there needs to be a new goroutine not tied to the

View File

@ -21,6 +21,7 @@ func (b *virtigoT) Enable() {
// this app's variables // this app's variables
type virtigoT struct { type virtigoT struct {
cluster *pb.Cluster // basic cluster settings cluster *pb.Cluster // basic cluster settings
e *pb.Events // virtbuf events
hmap map[*pb.Hypervisor]*HyperT // map to the local struct hmap map[*pb.Hypervisor]*HyperT // map to the local struct
names []string names []string
hypers []*HyperT hypers []*HyperT

View File

@ -330,7 +330,7 @@ func setUniqueSpicePort(check *pb.Droplet) error {
// generate change port event // generate change port event
log.Info("going to try port", start, "on", check.Hostname) log.Info("going to try port", start, "on", check.Hostname)
e := check.NewChangeEvent("SpicePort", check.SpicePort, start) 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 // set port to start
check.SpicePort = start check.SpicePort = start