Use unix-socket as communication channel

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

Conflicts:
	ctr/container.go
This commit is contained in:
Alexander Morozov 2015-12-14 15:54:11 -08:00 committed by Michael Crosby
parent e16dfc36a5
commit ca4191ce41
6 changed files with 47 additions and 21 deletions

View file

@ -28,7 +28,7 @@ var ListCheckpointCommand = cli.Command{
func listCheckpoints(context *cli.Context) {
var (
c = getClient()
c = getClient(context)
id = context.Args().First()
)
if id == "" {
@ -82,7 +82,7 @@ var CreateCheckpointCommand = cli.Command{
if name == "" {
fatal("checkpoint name cannot be empty", 1)
}
c := getClient()
c := getClient(context)
if _, err := c.CreateCheckpoint(netcontext.Background(), &types.CreateCheckpointRequest{
Id: containerID,
Checkpoint: &types.Checkpoint{
@ -108,7 +108,7 @@ var DeleteCheckpointCommand = cli.Command{
if name == "" {
fatal("checkpoint name cannot be empty", 1)
}
c := getClient()
c := getClient(context)
if _, err := c.DeleteCheckpoint(netcontext.Background(), &types.DeleteCheckpointRequest{
Id: containerID,
Name: name,

View file

@ -4,10 +4,12 @@ import (
"fmt"
"io"
"io/ioutil"
"net"
"os"
"path/filepath"
"syscall"
"text/tabwriter"
"time"
"github.com/codegangsta/cli"
"github.com/docker/containerd/api/grpc/types"
@ -18,8 +20,14 @@ import (
)
// TODO: parse flags and pass opts
func getClient() types.APIClient {
conn, err := grpc.Dial("localhost:8888", grpc.WithInsecure())
func getClient(ctx *cli.Context) types.APIClient {
dialOpts := []grpc.DialOption{grpc.WithInsecure()}
dialOpts = append(dialOpts,
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
},
))
conn, err := grpc.Dial(ctx.GlobalString("address"), dialOpts...)
if err != nil {
fatal(err.Error(), 1)
}
@ -46,7 +54,7 @@ var ListCommand = cli.Command{
}
func listContainers(context *cli.Context) {
c := getClient()
c := getClient(context)
resp, err := c.State(netcontext.Background(), &types.StateRequest{})
if err != nil {
fatal(err.Error(), 1)
@ -90,7 +98,7 @@ var StartCommand = cli.Command{
if id == "" {
fatal("container id cannot be empty", 1)
}
c := getClient()
c := getClient(context)
events, err := c.Events(netcontext.Background(), &types.EventsRequest{})
if err != nil {
fatal(err.Error(), 1)
@ -223,7 +231,7 @@ var KillCommand = cli.Command{
if id == "" {
fatal("container id cannot be empty", 1)
}
c := getClient()
c := getClient(context)
if _, err := c.Signal(netcontext.Background(), &types.SignalRequest{
Id: id,
Pid: uint32(context.Int("pid")),
@ -276,7 +284,7 @@ var ExecCommand = cli.Command{
Gid: uint32(context.Int("gid")),
},
}
c := getClient()
c := getClient(context)
if _, err := c.AddProcess(netcontext.Background(), p); err != nil {
fatal(err.Error(), 1)
}
@ -290,7 +298,7 @@ var StatsCommand = cli.Command{
req := &types.StatsRequest{
Id: context.Args().First(),
}
c := getClient()
c := getClient(context)
stream, err := c.GetStats(netcontext.Background(), req)
if err != nil {
fatal(err.Error(), 1)

View file

@ -14,7 +14,7 @@ var EventsCommand = cli.Command{
Name: "events",
Usage: "receive events from the containerd daemon",
Action: func(context *cli.Context) {
c := getClient()
c := getClient(context)
events, err := c.Events(netcontext.Background(), &types.EventsRequest{})
if err != nil {
fatal(err.Error(), 1)

View file

@ -28,9 +28,9 @@ func main() {
Usage: "enable debug output in the logs",
},
cli.StringFlag{
Name: "addr",
Value: "http://localhost:8888",
Usage: "address to the containerd api",
Name: "address",
Value: "/run/containerd/containerd.sock",
Usage: "address of GRPC API",
},
}
app.Commands = []cli.Command{