Commit 5d4364d4 authored by vaikas-google's avatar vaikas-google

Merge pull request #11 from vaikas-google/master

Add listtypes, gettype to client. update README.md to use that instead of curl.
parents 57c0b595 7ba16242
...@@ -24,13 +24,14 @@ import ( ...@@ -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() { ...@@ -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) { ...@@ -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) { ...@@ -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)
} }
......
...@@ -77,9 +77,10 @@ resources: ...@@ -77,9 +77,10 @@ resources:
### Displaying types ### 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"] ["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 ...@@ -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: 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' client -action gettype --service=http://localhost:8001/api/v1/proxy/namespaces/default/services/manager-service:manager -name 'Service'
[{"name":"redis","type":"redis.jinja","deployment":"guestbook","manifest":"manifest-1446584669795839153","path":"$.resources[1]"}] [{"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. It lists which deployment and manifest as well as JSON path to the type.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment