Add client code for stop pod sandbox

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
Mrunal Patel 2016-08-15 16:55:34 -07:00
parent c0048118a0
commit 2c95c0bb0d

View file

@ -86,6 +86,20 @@ func CreatePodSandbox(client pb.RuntimeServiceClient, path string) error {
return nil
}
// StopPodSandbox sends a StopPodSandboxRequest to the server, and parses
// the returned StopPodSandboxResponse.
func StopPodSandbox(client pb.RuntimeServiceClient, ID string) error {
if ID == "" {
return fmt.Errorf("ID cannot be empty")
}
r, err := client.StopPodSandbox(context.Background(), &pb.StopPodSandboxRequest{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 {
@ -123,6 +137,7 @@ func main() {
app.Commands = []cli.Command{
runtimeVersionCommand,
createPodSandboxCommand,
stopPodSandboxCommand,
createContainerCommand,
pullImageCommand,
}
@ -211,6 +226,33 @@ var createPodSandboxCommand = cli.Command{
},
}
var stopPodSandboxCommand = cli.Command{
Name: "stoppodsandbox",
Usage: "stop a pod sandbox",
Flags: []cli.Flag{
cli.StringFlag{
Name: "id",
Value: "",
Usage: "id of the pod sandbox",
},
},
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 = StopPodSandbox(client, context.String("id"))
if err != nil {
return fmt.Errorf("Stopping the pod sandbox failed: %v", err)
}
return nil
},
}
var createContainerCommand = cli.Command{
Name: "createcontainer",
Usage: "create a container",