summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--http.go35
-rw-r--r--start.go2
-rw-r--r--validate.go12
3 files changed, 48 insertions, 1 deletions
diff --git a/http.go b/http.go
index 9a7a18d..6241d7e 100644
--- a/http.go
+++ b/http.go
@@ -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 == "" {
diff --git a/start.go b/start.go
index 465f7b5..b8d20ae 100644
--- a/start.go
+++ b/start.go
@@ -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()