Port ctr to use client

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-06-05 16:17:37 -07:00
parent bdf9f5f738
commit 4c1af8fdd8
26 changed files with 526 additions and 1179 deletions

View File

@@ -3,11 +3,8 @@ package main
import (
"encoding/json"
gocontext "context"
"fmt"
containersapi "github.com/containerd/containerd/api/services/containers"
"github.com/containerd/containerd/api/services/execution"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
@@ -15,55 +12,29 @@ import (
var infoCommand = cli.Command{
Name: "info",
Usage: "get info about a container",
Flags: []cli.Flag{
cli.StringFlag{
Name: "id",
Usage: "id of the container",
},
},
Action: func(context *cli.Context) error {
var (
id = context.String("id")
ctx, cancel = appContext(context)
id = context.Args().First()
)
defer cancel()
if id == "" {
return errors.New("container id must be provided")
}
containers, err := getContainersService(context)
if err != nil {
return err
}
tasks, err := getTasksService(context)
client, err := newClient(context)
if err != nil {
return err
}
containerResponse, err := containers.Get(ctx, &containersapi.GetContainerRequest{ID: id})
container, err := client.LoadContainer(ctx, id)
if err != nil {
return err
}
// TODO(stevvooe): Just dumping the container and the task, for now. We
// should split this into two separate commands.
cjson, err := json.MarshalIndent(containerResponse, "", " ")
cjson, err := json.MarshalIndent(container, "", " ")
if err != nil {
return err
}
fmt.Println(string(cjson))
response, err := tasks.Info(gocontext.Background(), &execution.InfoRequest{ContainerID: id})
if err != nil {
return err
}
json, err := json.MarshalIndent(response, "", " ")
if err != nil {
return err
}
fmt.Println(string(json))
return nil
},
}