diff --git a/client/client.go b/client/client.go index 9c345d902..b20dcdb68 100644 --- a/client/client.go +++ b/client/client.go @@ -24,13 +24,14 @@ import ( "io/ioutil" "log" "net/http" + "net/url" "os" "strings" "time" ) 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") service = flag.String("service", "http://localhost:8080", "URL for deployment manager") binary = flag.String("binary", "../expandybird/expansion/expansion.py", @@ -69,6 +70,11 @@ func main() { case "update": path := fmt.Sprintf("deployments/%s", 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" } - url := fmt.Sprintf("%s/%s", *service, path) - request, err := http.NewRequest(method, url, reader) + u := fmt.Sprintf("%s/%s", *service, url.QueryEscape(path)) + request, err := http.NewRequest(method, u, reader) request.Header.Add("Content-Type", "application/json") response, err := http.DefaultClient.Do(request) if err != nil { @@ -94,7 +100,7 @@ func callService(path, method, name string, reader io.ReadCloser) { if response.StatusCode < http.StatusOK || 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) } diff --git a/examples/guestbook/README.md b/examples/guestbook/README.md index 0d5283ef5..f3fa5f9a3 100644 --- a/examples/guestbook/README.md +++ b/examples/guestbook/README.md @@ -77,9 +77,10 @@ resources: ### Displaying types -You can also (currently using curl, work in progress) see what types have been deployed to the cluster: +You can also see what types have been deployed to the cluster: ``` -curl http://localhost:8001/api/v1/proxy/namespaces/default/services/manager-service:manager/types +client --action listtypes --service=http://localhost:8001/api/v1/proxy/namespaces/default/services/manager-service:manager + ["Service","ReplicationController","redis.jinja","https://raw.githubusercontent.com/kubernetes/deployment-manager/master/examples/replicatedservice/replicatedservice.py"] ``` @@ -89,8 +90,8 @@ This shows that there are 2 native types that we have deployed (Service and Repl You can also see where the types are being used by getting details on the particular type: ``` - curl 'http://localhost:8001/api/v1/proxy/namespaces/default/services/manager-service:manager/types/redis.jinja/instances' -[{"name":"redis","type":"redis.jinja","deployment":"guestbook","manifest":"manifest-1446584669795839153","path":"$.resources[1]"}] +client -action gettype --service=http://localhost:8001/api/v1/proxy/namespaces/default/services/manager-service:manager -name 'Service' +[{"name":"frontend-service","type":"Service","deployment":"guestbook4","manifest":"manifest-1446682551242763329","path":"$.resources[0].resources[0]"},{"name":"redis-master","type":"Service","deployment":"guestbook4","manifest":"manifest-1446682551242763329","path":"$.resources[1].resources[0].resources[0]"},{"name":"redis-slave","type":"Service","deployment":"guestbook4","manifest":"manifest-1446682551242763329","path":"$.resources[1].resources[1].resources[0]"}] ``` It lists which deployment and manifest as well as JSON path to the type.