2017-01-13 06:08:09 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
gocontext "context"
|
|
|
|
"fmt"
|
|
|
|
|
2017-02-09 07:31:26 +00:00
|
|
|
"github.com/docker/containerd/api/services/execution"
|
2017-01-13 06:08:09 +00:00
|
|
|
"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
|
|
|
|
}
|
2017-02-02 22:40:23 +00:00
|
|
|
listResponse, err := executionService.ListContainers(gocontext.Background(), &execution.ListContainersRequest{
|
2017-01-13 06:08:09 +00:00
|
|
|
Owner: []string{},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-02-10 04:32:11 +00:00
|
|
|
fmt.Println("ID\tSTATUS\tPROCS\tBUNDLE")
|
2017-01-13 06:08:09 +00:00
|
|
|
for _, c := range listResponse.Containers {
|
|
|
|
listProcResponse, err := executionService.ListProcesses(gocontext.Background(),
|
2017-02-02 23:36:10 +00:00
|
|
|
&execution.ListProcessesRequest{ContainerID: c.ID})
|
2017-01-13 06:08:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Printf("%s\t%s\t%d\t%s\n",
|
|
|
|
c.ID,
|
2017-02-09 07:31:26 +00:00
|
|
|
c.State,
|
2017-01-13 06:08:09 +00:00
|
|
|
len(listProcResponse.Processes),
|
2017-02-01 21:25:28 +00:00
|
|
|
c.Bundle,
|
2017-01-13 06:08:09 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|