add support for listtypes gettype actions, on errors, print the body for more meaningful error messages

pull/11/head
vaikas 9 years ago
parent 57c0b595cb
commit 38f7154d29

@ -24,13 +24,14 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"net/url"
"os" "os"
"strings" "strings"
"time" "time"
) )
var ( var (
action = flag.String("action", "deploy", "expand | deploy | list | get | delete | update") action = flag.String("action", "deploy", "expand | deploy | list | get | delete | update | listtypes | gettype")
name = flag.String("name", "", "Name of template or deployment") name = flag.String("name", "", "Name of template or deployment")
service = flag.String("service", "http://localhost:8080", "URL for deployment manager") service = flag.String("service", "http://localhost:8080", "URL for deployment manager")
binary = flag.String("binary", "../expandybird/expansion/expansion.py", binary = flag.String("binary", "../expandybird/expansion/expansion.py",
@ -69,6 +70,11 @@ func main() {
case "update": case "update":
path := fmt.Sprintf("deployments/%s", name) path := fmt.Sprintf("deployments/%s", name)
callService(path, "PUT", name, readTemplate(name)) callService(path, "PUT", name, readTemplate(name))
case "listtypes":
callService("types", "GET", name, nil)
case "gettype":
path := fmt.Sprintf("types/%s/instances", name)
callService(path, "GET", name, nil)
} }
} }
@ -78,8 +84,8 @@ func callService(path, method, name string, reader io.ReadCloser) {
action = "deploy" action = "deploy"
} }
url := fmt.Sprintf("%s/%s", *service, path) u := fmt.Sprintf("%s/%s", *service, url.QueryEscape(path))
request, err := http.NewRequest(method, url, reader) request, err := http.NewRequest(method, u, reader)
request.Header.Add("Content-Type", "application/json") request.Header.Add("Content-Type", "application/json")
response, err := http.DefaultClient.Do(request) response, err := http.DefaultClient.Do(request)
if err != nil { if err != nil {
@ -94,7 +100,7 @@ func callService(path, method, name string, reader io.ReadCloser) {
if response.StatusCode < http.StatusOK || if response.StatusCode < http.StatusOK ||
response.StatusCode >= http.StatusMultipleChoices { response.StatusCode >= http.StatusMultipleChoices {
message := fmt.Sprintf("status code: %d status: %s", response.StatusCode, response.Status) message := fmt.Sprintf("status code: %d status: %s : %s", response.StatusCode, response.Status, body)
log.Fatalf("cannot %s template named %s: %s\n", action, name, message) log.Fatalf("cannot %s template named %s: %s\n", action, name, message)
} }

Loading…
Cancel
Save