From 32a9f23dd24b20450f3fd8a9bcc56df8de411cd5 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Wed, 31 Aug 2016 16:32:32 -0700 Subject: [PATCH] Client changes for getting pod status Signed-off-by: Mrunal Patel --- cmd/client/main.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/cmd/client/main.go b/cmd/client/main.go index 8c97fc6d..4a855c56 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -114,6 +114,20 @@ func RemovePodSandbox(client pb.RuntimeServiceClient, ID string) error { return nil } +// PodSandboxStatus sends a PodSandboxStatusRequest to the server, and parses +// the returned PodSandboxStatusResponse. +func PodSandboxStatus(client pb.RuntimeServiceClient, ID string) error { + if ID == "" { + return fmt.Errorf("ID cannot be empty") + } + r, err := client.PodSandboxStatus(context.Background(), &pb.PodSandboxStatusRequest{PodSandboxId: &ID}) + if err != nil { + return err + } + fmt.Println(r) + return nil +} + // CreateContainer sends a CreateContainerRequest to the server, and parses // the returned CreateContainerResponse. func CreateContainer(client pb.RuntimeServiceClient, sandbox string, path string) error { @@ -266,6 +280,7 @@ var podSandboxCommand = cli.Command{ createPodSandboxCommand, stopPodSandboxCommand, removePodSandboxCommand, + podSandboxStatusCommand, }, } @@ -351,6 +366,33 @@ var removePodSandboxCommand = cli.Command{ }, } +var podSandboxStatusCommand = cli.Command{ + Name: "status", + Usage: "return the status of a pod", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "id", + Value: "", + Usage: "id of the pod", + }, + }, + Action: func(context *cli.Context) error { + // Set up a connection to the server. + conn, err := getClientConnection() + if err != nil { + return fmt.Errorf("failed to connect: %v", err) + } + defer conn.Close() + client := pb.NewRuntimeServiceClient(conn) + + err = PodSandboxStatus(client, context.String("id")) + if err != nil { + return fmt.Errorf("getting the pod sandbox status failed: %v", err) + } + return nil + }, +} + var containerCommand = cli.Command{ Name: "container", Aliases: []string{"ctr"},