Merge pull request #423 from AkihiroSuda/list

ctr: add commands: `list` and `inspect`
This commit is contained in:
Michael Crosby 2017-01-18 10:03:51 -08:00 committed by GitHub
commit e3595680a9
4 changed files with 85 additions and 1 deletions

41
cmd/ctr/inspect.go Normal file
View file

@ -0,0 +1,41 @@
package main
import (
gocontext "context"
"fmt"
"github.com/davecgh/go-spew/spew"
"github.com/docker/containerd/api/execution"
"github.com/urfave/cli"
)
var inspectCommand = cli.Command{
Name: "inspect",
Usage: "inspect a container",
Action: func(context *cli.Context) error {
executionService, err := getExecutionService(context)
if err != nil {
return err
}
id := context.Args().First()
if id == "" {
return fmt.Errorf("container id must be provided")
}
getResponse, err := executionService.Get(gocontext.Background(),
&execution.GetContainerRequest{ID: id})
if err != nil {
return err
}
listProcResponse, err := executionService.ListProcesses(gocontext.Background(),
&execution.ListProcessesRequest{ID: id})
if err != nil {
return err
}
dumper := spew.NewDefaultConfig()
dumper.Indent = "\t"
dumper.DisableMethods = true
dumper.DisablePointerAddresses = true
dumper.Dump(getResponse, listProcResponse)
return nil
},
}

41
cmd/ctr/list.go Normal file
View file

@ -0,0 +1,41 @@
package main
import (
gocontext "context"
"fmt"
"github.com/docker/containerd/api/execution"
"github.com/urfave/cli"
)
var listCommand = cli.Command{
Name: "list",
Usage: "list containers",
Action: func(context *cli.Context) error {
executionService, err := getExecutionService(context)
if err != nil {
return err
}
listResponse, err := executionService.List(gocontext.Background(), &execution.ListContainersRequest{
Owner: []string{},
})
if err != nil {
return err
}
fmt.Printf("ID\tSTATUS\tPROCS\tBUNDLE\n")
for _, c := range listResponse.Containers {
listProcResponse, err := executionService.ListProcesses(gocontext.Background(),
&execution.ListProcessesRequest{ID: c.ID})
if err != nil {
return err
}
fmt.Printf("%s\t%s\t%d\t%s\n",
c.ID,
c.Status,
len(listProcResponse.Processes),
c.BundlePath,
)
}
return nil
},
}

View file

@ -38,6 +38,8 @@ containerd client
execCommand, execCommand,
eventsCommand, eventsCommand,
deleteCommand, deleteCommand,
listCommand,
inspectCommand,
} }
app.Before = func(context *cli.Context) error { app.Before = func(context *cli.Context) error {
if context.GlobalBool("debug") { if context.GlobalBool("debug") {

View file

@ -43,7 +43,7 @@ github.com/Sirupsen/logrus v0.11.0
github.com/stevvooe/go-btrfs 029908fedf190147f3f673b0db7c836f83a6a6be github.com/stevvooe/go-btrfs 029908fedf190147f3f673b0db7c836f83a6a6be
# testify go testing support; latest release as of 12/16/2016 # testify go testing support; latest release as of 12/16/2016
github.com/stretchr/testify v1.1.4 github.com/stretchr/testify v1.1.4
# go-spew (required by testify); latest release as of 1/12/2017 # go-spew (required by testify, and also by ctr); latest release as of 1/12/2017
github.com/davecgh/go-spew v1.1.0 github.com/davecgh/go-spew v1.1.0
# go-difflib (required by testify); latest release as of 1/12/2017 # go-difflib (required by testify); latest release as of 1/12/2017
github.com/pmezard/go-difflib v1.0.0 github.com/pmezard/go-difflib v1.0.0