diff options
| author | Jeff Carr <[email protected]> | 2024-11-16 05:21:44 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-16 05:21:44 -0600 |
| commit | 70cc9944adfea53e1c5a841d573cac79a5b94ce9 (patch) | |
| tree | 8b980ddd002628c5c7290a94bfdaa0b5a80974e8 | |
| parent | 5ea2e5999bf19c5b0dcd594ce5c646ae2227fcec (diff) | |
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | http.go | 35 | ||||
| -rw-r--r-- | start.go | 2 | ||||
| -rw-r--r-- | validate.go | 12 |
3 files changed, 48 insertions, 1 deletions
@@ -2,10 +2,12 @@ package main import ( "fmt" + "io/ioutil" "net/http" "os" "strings" + "go.wit.com/lib/protobuf/virtbuf" "go.wit.com/lib/virtigolib" "go.wit.com/log" ) @@ -22,6 +24,11 @@ func okHandler(w http.ResponseWriter, r *http.Request) { log.HttpMode(w) defer log.HttpMode(nil) + msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte + if err != nil { + log.Info("ReadAll() error =", err) + return + } if route == "/uptime" { ok, s := uptimeCheck() log.Info(s) @@ -33,6 +40,34 @@ func okHandler(w http.ResponseWriter, r *http.Request) { return } + if route == "/create" { + var d *virtbuf.Droplet + d = new(virtbuf.Droplet) + if err := d.Unmarshal(msg); err != nil { + log.Info("proto.Unmarshal() failed on wire message len", len(msg)) + log.Info("error =", err) + return + } + log.Info("proto.Unmarshal() worked on msg len", len(msg), "hostname =", d.Hostname) + found := me.cluster.FindDropletByName(d.Hostname) + if found != nil { + log.Info("already have hostname ", d.Hostname) + return + } + log.Info("new hostname ", d.Hostname) + if !me.cluster.AddDroplet(d) { + log.Info("new hostname added ok ", d.Hostname) + } else { + log.Info("hostname add failed for ", d.Hostname) + } + if err := me.cluster.ConfigSave(); err != nil { + log.Info("configsave error", err) + os.Exit(-1) + } + log.Info("config file saved") + return + } + if route == "/start" { hostname := r.URL.Query().Get("hostname") if hostname == "" { @@ -11,6 +11,7 @@ import ( "time" pb "go.wit.com/lib/protobuf/virtbuf" + "go.wit.com/log" ) func isClusterStable() (string, error) { @@ -45,6 +46,7 @@ func Start(name string) (string, error) { // validate the droplet if err := ValidateDroplet(d); err != nil { + log.Info("ValidateDroplet() failed", err) result = "ValidateDroplet() failed droplet " + d.Hostname return result, err } diff --git a/validate.go b/validate.go index b6572f5..6ea8aba 100644 --- a/validate.go +++ b/validate.go @@ -198,8 +198,10 @@ func getNewMac() string { return "" } +// consistancy check. run on a regular basis +// // runs on startup. dies if there are duplicates -// the config file must then be edited by hand +// the config file must then be edited by hand for now func ValidateDroplets() (map[string]string, map[string]string, error) { // uuid map to check for duplicates var umap map[string]string @@ -301,6 +303,14 @@ func ValidateDroplet(check *pb.Droplet) error { // check for duplicate mac addresses for _, checkn := range check.Networks { + log.Info("found mac = ", checkn.Mac, check.Hostname) + if checkn.Mac == "" { + checkn.Mac = getNewMac() + if err := me.cluster.ConfigSave(); err != nil { + log.Info("configsave error", err) + os.Exit(-1) + } + } loop := me.cluster.DropletsAll() // get the list of droplets for loop.Scan() { d := loop.Droplet() |
