From 450c8223e69135689ecc5cb052bd7b48953dee98 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Thu, 25 Feb 2016 10:09:22 -0800 Subject: [PATCH 1/3] Add pause command to ctr Signed-off-by: Kenfe-Mickael Laventure --- ctr/container.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ctr/container.go b/ctr/container.go index 4e2bf98..70acd0e 100644 --- a/ctr/container.go +++ b/ctr/container.go @@ -48,6 +48,7 @@ var containersCommand = cli.Command{ execCommand, killCommand, listCommand, + pauseCommand, startCommand, statsCommand, }, @@ -269,6 +270,26 @@ func attachStdio(s stdio) error { return nil } +var pauseCommand = cli.Command{ + Name: "pause", + Usage: "pause a container", + Action: func(context *cli.Context) { + id := context.Args().First() + if id == "" { + fatal("container id cannot be empty", 1) + } + c := getClient(context) + _, err := c.UpdateContainer(netcontext.Background(), &types.UpdateContainerRequest{ + Id: id, + Pid: "init", + Status: "paused", + }) + if err != nil { + fatal(err.Error(), 1) + } + }, +} + var killCommand = cli.Command{ Name: "kill", Usage: "send a signal to a container or its processes", From d0ab28570443ca39b2cb942822b32364f4ddfa17 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Thu, 25 Feb 2016 10:10:05 -0800 Subject: [PATCH 2/3] Add resume command to ctr Signed-off-by: Kenfe-Mickael Laventure --- ctr/container.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ctr/container.go b/ctr/container.go index 70acd0e..b6900af 100644 --- a/ctr/container.go +++ b/ctr/container.go @@ -49,6 +49,7 @@ var containersCommand = cli.Command{ killCommand, listCommand, pauseCommand, + resumeCommand, startCommand, statsCommand, }, @@ -290,6 +291,26 @@ var pauseCommand = cli.Command{ }, } +var resumeCommand = cli.Command{ + Name: "resume", + Usage: "resume a paused container", + Action: func(context *cli.Context) { + id := context.Args().First() + if id == "" { + fatal("container id cannot be empty", 1) + } + c := getClient(context) + _, err := c.UpdateContainer(netcontext.Background(), &types.UpdateContainerRequest{ + Id: id, + Pid: "init", + Status: "running", + }) + if err != nil { + fatal(err.Error(), 1) + } + }, +} + var killCommand = cli.Command{ Name: "kill", Usage: "send a signal to a container or its processes", From d8412061d283a32291be4d7dc10d53677128c79f Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Thu, 25 Feb 2016 10:10:22 -0800 Subject: [PATCH 3/3] Add watch command to ctr This command dump events matching a given container id or all events if no id is provided. Signed-off-by: Kenfe-Mickael Laventure --- ctr/container.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/ctr/container.go b/ctr/container.go index b6900af..d489e3b 100644 --- a/ctr/container.go +++ b/ctr/container.go @@ -52,6 +52,7 @@ var containersCommand = cli.Command{ resumeCommand, startCommand, statsCommand, + watchCommand, }, Action: listContainers, } @@ -271,6 +272,44 @@ func attachStdio(s stdio) error { return nil } +var watchCommand = cli.Command{ + Name: "watch", + Usage: "print container events", + Action: func(context *cli.Context) { + c := getClient(context) + id := context.Args().First() + if id != "" { + resp, err := c.State(netcontext.Background(), &types.StateRequest{Id: id}) + if err != nil { + fatal(err.Error(), 1) + } + for _, c := range resp.Containers { + if c.Id == id { + break + } + } + if id == "" { + fatal("Invalid container id", 1) + } + } + events, reqErr := c.Events(netcontext.Background(), &types.EventsRequest{}) + if reqErr != nil { + fatal(reqErr.Error(), 1) + } + + for { + e, err := events.Recv() + if err != nil { + fatal(err.Error(), 1) + } + + if id == "" || e.Id == id { + fmt.Printf("%#v\n", e) + } + } + }, +} + var pauseCommand = cli.Command{ Name: "pause", Usage: "pause a container",