Add events support in client
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
288b9a0cc3
commit
71ef776082
7 changed files with 70 additions and 20 deletions
34
ctr/events.go
Normal file
34
ctr/events.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/containerd/api/grpc/types"
|
||||
netcontext "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var EventsCommand = cli.Command{
|
||||
Name: "events",
|
||||
Usage: "receive events from the containerd daemon",
|
||||
Action: func(context *cli.Context) {
|
||||
c := getClient()
|
||||
events, err := c.Events(netcontext.Background(), &types.EventsRequest{})
|
||||
if err != nil {
|
||||
fatal(err.Error(), 1)
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
|
||||
fmt.Fprint(w, "TYPE\tID\tPID\tSTATUS\n")
|
||||
w.Flush()
|
||||
for {
|
||||
e, err := events.Recv()
|
||||
if err != nil {
|
||||
fatal(err.Error(), 1)
|
||||
}
|
||||
fmt.Fprintf(w, "%s\t%s\t%d\t%d\n", e.Type, e.Id, e.Pid, e.Status)
|
||||
w.Flush()
|
||||
}
|
||||
},
|
||||
}
|
|
@ -36,6 +36,7 @@ func main() {
|
|||
app.Commands = []cli.Command{
|
||||
ContainersCommand,
|
||||
CheckpointCommand,
|
||||
EventsCommand,
|
||||
}
|
||||
app.Before = func(context *cli.Context) error {
|
||||
if context.GlobalBool("debug") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue