never die in fetchVMs(). Use the domain from the config file

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-29 01:14:07 +00:00
parent 7c5b906f5f
commit 5357cbd7db
1 changed files with 19 additions and 7 deletions

View File

@ -44,7 +44,7 @@ func fetchNetworks(ge *pb.Event) []network {
if err != nil { log.Printf("Can't exec the req to list networks: %s", err) } if err != nil { log.Printf("Can't exec the req to list networks: %s", err) }
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { log.Fatal("can't read resp") } if err != nil { log.Fatal("can't read resp") }
log.Printf("NETWORKS =", body) log.Printf("NETWORKS =", string(body))
if body == nil { if body == nil {
log.Println("networks is nil") log.Println("networks is nil")
} else { } else {
@ -92,15 +92,27 @@ type vm struct {
func fetchVMs(ge *pb.Event, network string) []vm { func fetchVMs(ge *pb.Event, network string) []vm {
var vms []vm var vms []vm
req, err := http.NewRequest("GET", ge.Account.URL + "vms/" + network, nil) req, err := http.NewRequest("GET", ge.Account.URL + "vms/" + network, nil)
if err != nil { log.Fatal("can't make new req") } if err != nil {
log.Println("fetchVMs() can't make new req")
return vms
}
req.Header.Set("X-Wit-Auth", ge.Account.Token) req.Header.Set("X-Wit-Auth", ge.Account.Token)
client := &http.Client{} client := &http.Client{}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { log.Printf("Can't exec the req to fetch vms for %s: %s", network, err) } if err != nil {
log.Printf("fetchVMs() Can't exec the req to fetch vms for %s: %s", network, err)
return vms
}
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { log.Fatal("can't read resp") } if err != nil {
log.Println("fetchVMs() can't read resp")
return vms
}
err = json.Unmarshal(body, &vms) err = json.Unmarshal(body, &vms)
if err != nil { log.Fatal("can't unmarshal resp for fetch vms: ", err, "\n\n", network, string(body)) } if err != nil {
log.Println("fetchVMs() can't unmarshal resp for fetch vms: ", err, "\n\n", network, string(body))
return vms
}
spew.Dump(vms) spew.Dump(vms)
return vms return vms
} }
@ -247,7 +259,7 @@ func processGetEvent(ge *pb.Event) *pb.Event {
evm.Cpus = 1 evm.Cpus = 1
evm.Memory = 512 evm.Memory = 512
evm.Disk = 20 evm.Disk = 20
evm.Hostname = vm.Name + "." + enetwork.Name + ".customers.wprod.wit.com" evm.Hostname = vm.Name + "." + enetwork.Name
e.Vms = append(e.Vms, &evm) e.Vms = append(e.Vms, &evm)
log.Println("\tvm.Name =",vm.Name) log.Println("\tvm.Name =",vm.Name)
@ -299,7 +311,7 @@ func processAddEvent(ge *pb.Event) *pb.Event {
return e return e
} }
url := ge.Account.URL + "vms/jcarr.com?count=1&cpu=2&ram=512&disk=25" url := ge.Account.URL + "vms/" + ge.Account.Domain + "?count=1&cpu=2&ram=512&disk=25"
newVM := string(POSTbody(ge, url)) newVM := string(POSTbody(ge, url))
log.Println("processAddEvent() recieved newVM=", newVM) log.Println("processAddEvent() recieved newVM=", newVM)