From 96c44afee14df08d9ef2916ebbfd6128445f93fe Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 4 Jun 2019 23:15:55 +0000 Subject: [PATCH] fix hostname with domain name and vis-a-vis Signed-off-by: Jeff Carr --- gorilla-server/apiJSON.go | 2 +- gorilla-server/main.go | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/gorilla-server/apiJSON.go b/gorilla-server/apiJSON.go index d104e43..e105826 100644 --- a/gorilla-server/apiJSON.go +++ b/gorilla-server/apiJSON.go @@ -107,7 +107,7 @@ func POSTbody(ge *pb.Event, URL string) string { log.Println("POSTbody() can't make new req") return "" } - + token := ge.Account.Token if (token == "") { token = "POSTbodyEmptyToken" diff --git a/gorilla-server/main.go b/gorilla-server/main.go index f394da5..54f0521 100644 --- a/gorilla-server/main.go +++ b/gorilla-server/main.go @@ -2,6 +2,8 @@ package main import "flag" import "log" +import "fmt" +import "regexp" import "net/http" import "encoding/json" import "io/ioutil" @@ -142,7 +144,8 @@ func processGetEvent(ge *pb.Event) *pb.Event { evm.Cpus = 1 evm.Memory = 512 evm.Disk = 20 - evm.Hostname = vm.Name + "." + enetwork.Name + // TODO: bmath -- let's change the stack-api to remove this hack + evm.Hostname = vm.Name + "." + enetwork.Name + ".customers.wprod.wit.com" e.Vms = append(e.Vms, &evm) log.Println("\tvm.Name =",vm.Name) @@ -194,7 +197,16 @@ func processAddEvent(ge *pb.Event) *pb.Event { return e } - url := ge.Account.URL + "vms/" + ge.Account.Domain + "?count=1&cpu=2&ram=512&disk=25" + a := regexp.MustCompile(`\.`) // split subdomain on . + stuff := a.Split(ge.Account.Domain, -1) + log.Printf("processAddEvent() stuff = %q\n", stuff) + log.Println("processAddEvent() host =", stuff[0]) + log.Println("processAddEvent() memory =", ge.Vms[0].Memory) + + memory := fmt.Sprintf("%d", ge.Vms[0].Memory) + url := ge.Account.URL + "vms/" + stuff[0] + "?count=1&cpu=2&ram=" + memory + "&disk=25" + log.Println("processAddEvent() new URL =", url) + newVM := string(POSTbody(ge, url)) log.Println("processAddEvent() recieved newVM=", newVM)