From a27d6e6ff1022427dff45c163d2b1ed7dee327bd Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Tue, 23 Aug 2016 15:30:30 -0700 Subject: [PATCH] Add client impl for RemoveContainer Signed-off-by: Mrunal Patel --- cmd/client/main.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/cmd/client/main.go b/cmd/client/main.go index d3c9d937..93b18b8c 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -165,6 +165,22 @@ func StopContainer(client pb.RuntimeServiceClient, ID string) error { return nil } +// RemoveContainer sends a RemoveContainerRequest to the server, and parses +// the returned RemoveContainerResponse. +func RemoveContainer(client pb.RuntimeServiceClient, ID string) error { + if ID == "" { + return fmt.Errorf("ID cannot be empty") + } + r, err := client.RemoveContainer(context.Background(), &pb.RemoveContainerRequest{ + ContainerId: &ID, + }) + if err != nil { + return err + } + fmt.Println(r) + return nil +} + // Version sends a VersionRequest to the server, and parses the returned VersionResponse. func Version(client pb.RuntimeServiceClient, version string) error { r, err := client.Version(context.Background(), &pb.VersionRequest{Version: &version}) @@ -188,6 +204,7 @@ func main() { createContainerCommand, startContainerCommand, stopContainerCommand, + removeContainerCommand, pullImageCommand, } @@ -417,3 +434,30 @@ var stopContainerCommand = cli.Command{ return nil }, } + +var removeContainerCommand = cli.Command{ + Name: "removecontainer", + Usage: "remove a container", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "id", + Value: "", + Usage: "id of the container", + }, + }, + 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 = RemoveContainer(client, context.String("id")) + if err != nil { + return fmt.Errorf("Removing the container failed: %v", err) + } + return nil + }, +}