2017-01-13 06:08:09 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
gocontext "context"
|
|
|
|
"fmt"
|
2017-02-13 18:23:28 +00:00
|
|
|
"os"
|
|
|
|
"text/tabwriter"
|
2017-01-13 06:08:09 +00:00
|
|
|
|
2017-04-03 20:14:15 +00:00
|
|
|
"github.com/containerd/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 {
|
2017-02-13 18:23:28 +00:00
|
|
|
containers, err := getExecutionService(context)
|
2017-01-13 06:08:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-02-13 18:23:28 +00:00
|
|
|
response, err := containers.List(gocontext.Background(), &execution.ListRequest{})
|
2017-01-13 06:08:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-02-13 18:23:28 +00:00
|
|
|
w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0)
|
|
|
|
fmt.Fprintln(w, "ID\tPID\tSTATUS")
|
|
|
|
for _, c := range response.Containers {
|
2017-02-20 05:27:09 +00:00
|
|
|
if _, err := fmt.Fprintf(w, "%s\t%d\t%s\n",
|
2017-02-13 18:23:28 +00:00
|
|
|
c.ID,
|
|
|
|
c.Pid,
|
|
|
|
c.Status.String(),
|
|
|
|
); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := w.Flush(); err != nil {
|
2017-01-13 06:08:09 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|