Add client code for starting a container
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
9a034d8993
commit
08c76ed7fb
1 changed files with 44 additions and 0 deletions
|
@ -133,6 +133,22 @@ func CreateContainer(client pb.RuntimeServiceClient, sandbox string, path string
|
|||
return nil
|
||||
}
|
||||
|
||||
// StartContainer sends a StartContainerRequest to the server, and parses
|
||||
// the returned StartContainerResponse.
|
||||
func StartContainer(client pb.RuntimeServiceClient, ID string) error {
|
||||
if ID == "" {
|
||||
return fmt.Errorf("ID cannot be empty")
|
||||
}
|
||||
r, err := client.StartContainer(context.Background(), &pb.StartContainerRequest{
|
||||
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})
|
||||
|
@ -154,6 +170,7 @@ func main() {
|
|||
stopPodSandboxCommand,
|
||||
removePodSandboxCommand,
|
||||
createContainerCommand,
|
||||
startContainerCommand,
|
||||
pullImageCommand,
|
||||
}
|
||||
|
||||
|
@ -329,3 +346,30 @@ var createContainerCommand = cli.Command{
|
|||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var startContainerCommand = cli.Command{
|
||||
Name: "startcontainer",
|
||||
Usage: "start 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 = StartContainer(client, context.String("id"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Starting the container failed: %v", err)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue