2016-07-13 21:10:10 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-07-20 01:30:05 +00:00
|
|
|
"encoding/json"
|
2016-07-19 18:37:49 +00:00
|
|
|
"fmt"
|
2016-07-13 21:10:10 +00:00
|
|
|
"log"
|
2016-07-22 20:44:27 +00:00
|
|
|
"net"
|
2016-07-13 21:10:10 +00:00
|
|
|
"os"
|
2016-07-22 20:44:27 +00:00
|
|
|
"time"
|
2016-07-13 21:10:10 +00:00
|
|
|
|
|
|
|
pb "github.com/kubernetes/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
2016-09-15 22:55:39 +00:00
|
|
|
var (
|
|
|
|
unixDomainSocket string
|
|
|
|
)
|
|
|
|
|
2016-07-13 21:10:10 +00:00
|
|
|
const (
|
2016-07-22 20:44:27 +00:00
|
|
|
// TODO: Make configurable
|
|
|
|
timeout = 10 * time.Second
|
2016-07-13 21:10:10 +00:00
|
|
|
)
|
|
|
|
|
2016-07-22 20:44:27 +00:00
|
|
|
func getClientConnection() (*grpc.ClientConn, error) {
|
|
|
|
conn, err := grpc.Dial(unixDomainSocket, grpc.WithInsecure(), grpc.WithTimeout(timeout),
|
|
|
|
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
|
|
|
|
return net.DialTimeout("unix", addr, timeout)
|
|
|
|
}))
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Failed to connect: %v", err)
|
|
|
|
}
|
|
|
|
return conn, nil
|
|
|
|
}
|
|
|
|
|
2016-08-01 17:39:42 +00:00
|
|
|
func openFile(path string) (*os.File, error) {
|
2016-07-20 01:30:05 +00:00
|
|
|
f, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
2016-08-01 17:39:42 +00:00
|
|
|
return nil, fmt.Errorf("config at %s not found", path)
|
2016-07-20 01:30:05 +00:00
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-08-01 17:39:42 +00:00
|
|
|
return f, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadPodSandboxConfig(path string) (*pb.PodSandboxConfig, error) {
|
|
|
|
f, err := openFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-07-20 01:30:05 +00:00
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
var config pb.PodSandboxConfig
|
|
|
|
if err := json.NewDecoder(f).Decode(&config); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &config, nil
|
|
|
|
}
|
|
|
|
|
2016-08-01 17:39:42 +00:00
|
|
|
func loadContainerConfig(path string) (*pb.ContainerConfig, error) {
|
|
|
|
f, err := openFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
var config pb.ContainerConfig
|
|
|
|
if err := json.NewDecoder(f).Decode(&config); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &config, nil
|
|
|
|
}
|
|
|
|
|
2016-07-20 01:30:05 +00:00
|
|
|
// CreatePodSandbox sends a CreatePodSandboxRequest to the server, and parses
|
|
|
|
// the returned CreatePodSandboxResponse.
|
|
|
|
func CreatePodSandbox(client pb.RuntimeServiceClient, path string) error {
|
|
|
|
config, err := loadPodSandboxConfig(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
r, err := client.CreatePodSandbox(context.Background(), &pb.CreatePodSandboxRequest{Config: config})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-08-29 20:28:14 +00:00
|
|
|
fmt.Println(*r.PodSandboxId)
|
2016-07-20 01:30:05 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-15 23:55:34 +00:00
|
|
|
// 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")
|
|
|
|
}
|
2016-08-29 20:28:14 +00:00
|
|
|
_, err := client.StopPodSandbox(context.Background(), &pb.StopPodSandboxRequest{PodSandboxId: &ID})
|
2016-08-15 23:55:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-08-29 20:28:14 +00:00
|
|
|
fmt.Println(ID)
|
2016-08-15 23:55:34 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-16 17:27:36 +00:00
|
|
|
// RemovePodSandbox sends a RemovePodSandboxRequest to the server, and parses
|
|
|
|
// the returned RemovePodSandboxResponse.
|
|
|
|
func RemovePodSandbox(client pb.RuntimeServiceClient, ID string) error {
|
|
|
|
if ID == "" {
|
|
|
|
return fmt.Errorf("ID cannot be empty")
|
|
|
|
}
|
2016-08-29 20:28:14 +00:00
|
|
|
_, err := client.RemovePodSandbox(context.Background(), &pb.RemovePodSandboxRequest{PodSandboxId: &ID})
|
2016-08-16 17:27:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-08-29 20:28:14 +00:00
|
|
|
fmt.Println(ID)
|
2016-08-16 17:27:36 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-31 23:32:32 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2016-08-01 17:39:42 +00:00
|
|
|
// CreateContainer sends a CreateContainerRequest to the server, and parses
|
|
|
|
// the returned CreateContainerResponse.
|
|
|
|
func CreateContainer(client pb.RuntimeServiceClient, sandbox string, path string) error {
|
|
|
|
config, err := loadContainerConfig(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
r, err := client.CreateContainer(context.Background(), &pb.CreateContainerRequest{
|
|
|
|
PodSandboxId: &sandbox,
|
|
|
|
Config: config,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-08-29 20:28:14 +00:00
|
|
|
fmt.Println(*r.ContainerId)
|
2016-08-01 17:39:42 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-18 22:53:20 +00:00
|
|
|
// 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")
|
|
|
|
}
|
2016-08-29 20:28:14 +00:00
|
|
|
_, err := client.StartContainer(context.Background(), &pb.StartContainerRequest{
|
2016-08-18 22:53:20 +00:00
|
|
|
ContainerId: &ID,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-08-29 20:28:14 +00:00
|
|
|
fmt.Println(ID)
|
2016-08-18 22:53:20 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-23 22:28:01 +00:00
|
|
|
// StopContainer sends a StopContainerRequest to the server, and parses
|
|
|
|
// the returned StopContainerResponse.
|
|
|
|
func StopContainer(client pb.RuntimeServiceClient, ID string) error {
|
|
|
|
if ID == "" {
|
|
|
|
return fmt.Errorf("ID cannot be empty")
|
|
|
|
}
|
2016-08-29 20:28:14 +00:00
|
|
|
_, err := client.StopContainer(context.Background(), &pb.StopContainerRequest{
|
2016-08-23 22:28:01 +00:00
|
|
|
ContainerId: &ID,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-08-29 20:28:14 +00:00
|
|
|
fmt.Println(ID)
|
2016-08-23 22:28:01 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-23 22:30:30 +00:00
|
|
|
// 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")
|
|
|
|
}
|
2016-08-29 20:28:14 +00:00
|
|
|
_, err := client.RemoveContainer(context.Background(), &pb.RemoveContainerRequest{
|
2016-08-23 22:30:30 +00:00
|
|
|
ContainerId: &ID,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-08-29 20:28:14 +00:00
|
|
|
fmt.Println(ID)
|
2016-08-23 22:30:30 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-09-12 22:03:26 +00:00
|
|
|
// ContainerStatus sends a ContainerStatusRequest to the server, and parses
|
|
|
|
// the returned ContainerStatusResponse.
|
|
|
|
func ContainerStatus(client pb.RuntimeServiceClient, ID string) error {
|
|
|
|
if ID == "" {
|
|
|
|
return fmt.Errorf("ID cannot be empty")
|
|
|
|
}
|
|
|
|
r, err := client.ContainerStatus(context.Background(), &pb.ContainerStatusRequest{
|
|
|
|
ContainerId: &ID})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(r)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-07-13 21:10:10 +00:00
|
|
|
// 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})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Printf("VersionResponse: Version: %s, RuntimeName: %s, RuntimeVersion: %s, RuntimeApiVersion: %s\n", *r.Version, *r.RuntimeName, *r.RuntimeVersion, *r.RuntimeApiVersion)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := cli.NewApp()
|
2016-07-15 17:48:53 +00:00
|
|
|
app.Name = "ocic"
|
|
|
|
app.Usage = "client for ocid"
|
2016-08-29 19:24:45 +00:00
|
|
|
app.Version = "0.0.1"
|
2016-07-15 21:28:52 +00:00
|
|
|
|
|
|
|
app.Commands = []cli.Command{
|
2016-08-29 19:24:45 +00:00
|
|
|
podSandboxCommand,
|
2016-08-29 20:08:07 +00:00
|
|
|
containerCommand,
|
2016-07-15 21:28:52 +00:00
|
|
|
runtimeVersionCommand,
|
2016-07-20 08:42:55 +00:00
|
|
|
pullImageCommand,
|
2016-07-15 21:28:52 +00:00
|
|
|
}
|
|
|
|
|
2016-09-15 22:55:39 +00:00
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "sock",
|
|
|
|
Value: "/var/run/ocid.sock",
|
|
|
|
Usage: "Socket to connect to",
|
|
|
|
Destination: &unixDomainSocket,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-07-15 21:28:52 +00:00
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
log.Fatal(err)
|
2016-07-13 21:10:10 +00:00
|
|
|
}
|
2016-07-15 21:28:52 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 08:42:55 +00:00
|
|
|
func PullImage(client pb.ImageServiceClient, image string) error {
|
|
|
|
_, err := client.PullImage(context.Background(), &pb.PullImageRequest{Image: &pb.ImageSpec{Image: &image}})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// try this with ./ocic pullimage docker://busybox
|
|
|
|
var pullImageCommand = cli.Command{
|
|
|
|
Name: "pullimage",
|
|
|
|
Usage: "pull an image",
|
|
|
|
Action: func(context *cli.Context) error {
|
|
|
|
// Set up a connection to the server.
|
2016-07-22 20:44:27 +00:00
|
|
|
conn, err := getClientConnection()
|
2016-07-20 08:42:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Failed to connect: %v", err)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
client := pb.NewImageServiceClient(conn)
|
|
|
|
|
|
|
|
err = PullImage(client, context.Args().Get(0))
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("pulling image failed: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-07-15 21:28:52 +00:00
|
|
|
var runtimeVersionCommand = cli.Command{
|
|
|
|
Name: "runtimeversion",
|
|
|
|
Usage: "get runtime version information",
|
|
|
|
Action: func(context *cli.Context) error {
|
2016-07-13 21:10:10 +00:00
|
|
|
// Set up a connection to the server.
|
2016-07-22 20:44:27 +00:00
|
|
|
conn, err := getClientConnection()
|
2016-07-13 21:10:10 +00:00
|
|
|
if err != nil {
|
2016-07-19 18:37:49 +00:00
|
|
|
return fmt.Errorf("Failed to connect: %v", err)
|
2016-07-13 21:10:10 +00:00
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
client := pb.NewRuntimeServiceClient(conn)
|
|
|
|
|
|
|
|
// Test RuntimeServiceClient.Version
|
2016-07-15 21:28:52 +00:00
|
|
|
version := "v1alpha1"
|
|
|
|
err = Version(client, version)
|
2016-07-13 21:10:10 +00:00
|
|
|
if err != nil {
|
2016-07-19 18:37:49 +00:00
|
|
|
return fmt.Errorf("Getting the runtime version failed: %v", err)
|
2016-07-13 21:10:10 +00:00
|
|
|
}
|
|
|
|
return nil
|
2016-07-15 21:28:52 +00:00
|
|
|
},
|
2016-07-13 21:10:10 +00:00
|
|
|
}
|
2016-07-20 01:30:05 +00:00
|
|
|
|
2016-08-29 19:24:45 +00:00
|
|
|
var podSandboxCommand = cli.Command{
|
|
|
|
Name: "pod",
|
|
|
|
Subcommands: []cli.Command{
|
|
|
|
createPodSandboxCommand,
|
|
|
|
stopPodSandboxCommand,
|
|
|
|
removePodSandboxCommand,
|
2016-08-31 23:32:32 +00:00
|
|
|
podSandboxStatusCommand,
|
2016-08-29 19:24:45 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-07-20 01:30:05 +00:00
|
|
|
var createPodSandboxCommand = cli.Command{
|
2016-08-29 19:24:45 +00:00
|
|
|
Name: "create",
|
|
|
|
Usage: "create a pod",
|
2016-07-20 01:30:05 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "config",
|
|
|
|
Value: "config.json",
|
|
|
|
Usage: "the path of a pod sandbox config file",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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)
|
|
|
|
|
|
|
|
// Test RuntimeServiceClient.CreatePodSandbox
|
|
|
|
err = CreatePodSandbox(client, context.String("config"))
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Creating the pod sandbox failed: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
2016-08-15 23:55:34 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var stopPodSandboxCommand = cli.Command{
|
2016-08-29 19:24:45 +00:00
|
|
|
Name: "stop",
|
2016-08-15 23:55:34 +00:00
|
|
|
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
|
2016-08-16 17:27:36 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var removePodSandboxCommand = cli.Command{
|
2016-08-29 19:24:45 +00:00
|
|
|
Name: "remove",
|
2016-08-16 17:27:36 +00:00
|
|
|
Usage: "remove 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 = RemovePodSandbox(client, context.String("id"))
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("removing the pod sandbox failed: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
2016-08-31 23:32:32 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2016-07-20 01:30:05 +00:00
|
|
|
},
|
|
|
|
}
|
2016-08-01 17:39:42 +00:00
|
|
|
|
2016-08-29 20:08:07 +00:00
|
|
|
var containerCommand = cli.Command{
|
|
|
|
Name: "container",
|
|
|
|
Aliases: []string{"ctr"},
|
|
|
|
Subcommands: []cli.Command{
|
|
|
|
createContainerCommand,
|
|
|
|
startContainerCommand,
|
|
|
|
stopContainerCommand,
|
|
|
|
removeContainerCommand,
|
2016-09-12 22:03:26 +00:00
|
|
|
containerStatusCommand,
|
2016-08-29 20:08:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-08-01 17:39:42 +00:00
|
|
|
var createContainerCommand = cli.Command{
|
2016-08-29 20:08:07 +00:00
|
|
|
Name: "create",
|
2016-08-01 17:39:42 +00:00
|
|
|
Usage: "create a container",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
2016-08-29 20:08:07 +00:00
|
|
|
Name: "pod",
|
2016-08-01 17:39:42 +00:00
|
|
|
Usage: "the id of the pod sandbox to which the container belongs",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "config",
|
|
|
|
Value: "config.json",
|
|
|
|
Usage: "the path of a container config file",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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)
|
|
|
|
|
2016-08-29 20:08:07 +00:00
|
|
|
if !context.IsSet("pod") {
|
|
|
|
return fmt.Errorf("Please specify the id of the pod sandbox to which the container belongs via the --pod option")
|
2016-08-01 17:39:42 +00:00
|
|
|
}
|
|
|
|
// Test RuntimeServiceClient.CreateContainer
|
2016-08-29 20:08:07 +00:00
|
|
|
err = CreateContainer(client, context.String("pod"), context.String("config"))
|
2016-08-01 17:39:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Creating the pod sandbox failed: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2016-08-18 22:53:20 +00:00
|
|
|
|
|
|
|
var startContainerCommand = cli.Command{
|
2016-08-29 20:08:07 +00:00
|
|
|
Name: "start",
|
2016-08-18 22:53:20 +00:00
|
|
|
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
|
|
|
|
},
|
|
|
|
}
|
2016-08-23 22:28:01 +00:00
|
|
|
|
|
|
|
var stopContainerCommand = cli.Command{
|
2016-08-29 20:08:07 +00:00
|
|
|
Name: "stop",
|
2016-08-23 22:28:01 +00:00
|
|
|
Usage: "stop 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 = StopContainer(client, context.String("id"))
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Stopping the container failed: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2016-08-23 22:30:30 +00:00
|
|
|
|
|
|
|
var removeContainerCommand = cli.Command{
|
2016-08-29 20:08:07 +00:00
|
|
|
Name: "remove",
|
2016-08-23 22:30:30 +00:00
|
|
|
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
|
|
|
|
},
|
|
|
|
}
|
2016-09-12 22:03:26 +00:00
|
|
|
|
|
|
|
var containerStatusCommand = cli.Command{
|
|
|
|
Name: "status",
|
|
|
|
Usage: "get the status of 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 = ContainerStatus(client, context.String("id"))
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Getting the status of the container failed: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|