Skip to content

Commit f258e43

Browse files
haircommanderrh-atomic-bot
authored andcommitted
Add pod pause/unpause
Added Pause() and Unpause() to libpod/pod.go Added man pages, tests and completions Signed-off-by: haircommander <[email protected]> Closes: #1126 Approved by: rhatdan
1 parent 50fea69 commit f258e43

File tree

10 files changed

+504
-9
lines changed

10 files changed

+504
-9
lines changed

cmd/podman/pod.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ Pods are a group of one or more containers sharing the same network, pid and ipc
1212
podSubCommands = []cli.Command{
1313
podCreateCommand,
1414
podKillCommand,
15+
podPauseCommand,
1516
podPsCommand,
1617
podRestartCommand,
1718
podRmCommand,
1819
podStartCommand,
1920
podStopCommand,
21+
podUnpauseCommand,
2022
}
2123
podCommand = cli.Command{
2224
Name: "pod",

cmd/podman/pod_pause.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/pkg/errors"
7+
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
8+
"github.com/sirupsen/logrus"
9+
"github.com/urfave/cli"
10+
)
11+
12+
var (
13+
podPauseFlags = []cli.Flag{
14+
cli.BoolFlag{
15+
Name: "all, a",
16+
Usage: "pause all running pods",
17+
},
18+
LatestPodFlag,
19+
}
20+
podPauseDescription = `
21+
Pauses one or more pods. The pod name or ID can be used.
22+
`
23+
24+
podPauseCommand = cli.Command{
25+
Name: "pause",
26+
Usage: "Pause one or more pods",
27+
Description: podPauseDescription,
28+
Flags: podPauseFlags,
29+
Action: podPauseCmd,
30+
ArgsUsage: "POD-NAME|POD-ID [POD-NAME|POD-ID ...]",
31+
UseShortOptionHandling: true,
32+
}
33+
)
34+
35+
func podPauseCmd(c *cli.Context) error {
36+
if err := checkMutuallyExclusiveFlags(c); err != nil {
37+
return err
38+
}
39+
40+
runtime, err := libpodruntime.GetRuntime(c)
41+
if err != nil {
42+
return errors.Wrapf(err, "error creating libpod runtime")
43+
}
44+
defer runtime.Shutdown(false)
45+
46+
// getPodsFromContext returns an error when a requested pod
47+
// isn't found. The only fatal error scenerio is when there are no pods
48+
// in which case the following loop will be skipped.
49+
pods, lastError := getPodsFromContext(c, runtime)
50+
51+
for _, pod := range pods {
52+
ctr_errs, err := pod.Pause()
53+
if ctr_errs != nil {
54+
for ctr, err := range ctr_errs {
55+
if lastError != nil {
56+
logrus.Errorf("%q", lastError)
57+
}
58+
lastError = errors.Wrapf(err, "unable to pause container %q on pod %q", ctr, pod.ID())
59+
}
60+
continue
61+
}
62+
if err != nil {
63+
if lastError != nil {
64+
logrus.Errorf("%q", lastError)
65+
}
66+
lastError = errors.Wrapf(err, "unable to pause pod %q", pod.ID())
67+
continue
68+
}
69+
fmt.Println(pod.ID())
70+
}
71+
72+
return lastError
73+
}

cmd/podman/pod_unpause.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/pkg/errors"
7+
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
8+
"github.com/sirupsen/logrus"
9+
"github.com/urfave/cli"
10+
)
11+
12+
var (
13+
podUnpauseFlags = []cli.Flag{
14+
cli.BoolFlag{
15+
Name: "all, a",
16+
Usage: "unpause all paused pods",
17+
},
18+
LatestPodFlag,
19+
}
20+
podUnpauseDescription = `
21+
Unpauses one or more pods. The pod name or ID can be used.
22+
`
23+
24+
podUnpauseCommand = cli.Command{
25+
Name: "unpause",
26+
Usage: "Unpause one or more pods",
27+
Description: podUnpauseDescription,
28+
Flags: podUnpauseFlags,
29+
Action: podUnpauseCmd,
30+
ArgsUsage: "POD-NAME|POD-ID [POD-NAME|POD-ID ...]",
31+
UseShortOptionHandling: true,
32+
}
33+
)
34+
35+
func podUnpauseCmd(c *cli.Context) error {
36+
if err := checkMutuallyExclusiveFlags(c); err != nil {
37+
return err
38+
}
39+
40+
runtime, err := libpodruntime.GetRuntime(c)
41+
if err != nil {
42+
return errors.Wrapf(err, "error creating libpod runtime")
43+
}
44+
defer runtime.Shutdown(false)
45+
46+
// getPodsFromContext returns an error when a requested pod
47+
// isn't found. The only fatal error scenerio is when there are no pods
48+
// in which case the following loop will be skipped.
49+
pods, lastError := getPodsFromContext(c, runtime)
50+
51+
for _, pod := range pods {
52+
ctr_errs, err := pod.Unpause()
53+
if ctr_errs != nil {
54+
for ctr, err := range ctr_errs {
55+
if lastError != nil {
56+
logrus.Errorf("%q", lastError)
57+
}
58+
lastError = errors.Wrapf(err, "unable to unpause container %q on pod %q", ctr, pod.ID())
59+
}
60+
continue
61+
}
62+
if err != nil {
63+
if lastError != nil {
64+
logrus.Errorf("%q", lastError)
65+
}
66+
lastError = errors.Wrapf(err, "unable to unpause pod %q", pod.ID())
67+
continue
68+
}
69+
fmt.Println(pod.ID())
70+
}
71+
72+
return lastError
73+
}

commands.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
| [podman-pod-create(1)](/docs/podman-pod-create.1.md) | Create a new pod ||
3434
| [podman-pod-kill(1)](podman-pod-kill.1.md) | Kill the main process of each container in pod. ||
3535
| [podman-pod-ps(1)](/docs/podman-pod-ps.1.md) | List the pods on the system ||
36+
| [podman-pod-pause(1)](podman-pod-pause.1.md) | Pause one or more pods. ||
3637
| [podman-pod-restart](/docs/podman-pod-restart.1.md) | Restart one or more pods ||
3738
| [podman-pod-rm(1)](/docs/podman-pod-rm.1.md) | Remove one or more pods ||
3839
| [podman-pod-start(1)](/docs/podman-pod-start.1.md) | Start one or more pods ||
3940
| [podman-pod-stop(1)](/docs/podman-pod-stop.1.md) | Stop one or more pods ||
41+
| [podman-pod-unpause(1)](podman-pod-unpause.1.md) | Unpause one or more pods. ||
4042
| [podman-port(1)](/docs/podman-port.1.md) | List port mappings for running containers |[![...](/docs/play.png)]()|
4143
| [podman-ps(1)](/docs/podman-ps.1.md) | Prints out information about containers |[![...](/docs/play.png)](https://asciinema.org/a/bbT41kac6CwZ5giESmZLIaTLR)|
4244
| [podman-pull(1)](/docs/podman-pull.1.md) | Pull an image from a registry |[![...](/docs/play.png)](https://asciinema.org/a/lr4zfoynHJOUNu1KaXa1dwG2X)|

completions/bash/podman

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,10 +2193,10 @@ _podman_pod_start() {
21932193
"
21942194

21952195
local boolean_options="
2196-
all
2197-
a
2198-
latest
2199-
l
2196+
--all
2197+
-a
2198+
--latest
2199+
-l
22002200
"
22012201
_complete_ "$options_with_args" "$boolean_options"
22022202
case "$cur" in
@@ -2214,11 +2214,53 @@ _podman_pod_stop() {
22142214
"
22152215

22162216
local boolean_options="
2217-
all
2218-
a
2219-
cleanup
2220-
latest
2221-
l
2217+
--all
2218+
-a
2219+
--cleanup
2220+
--latest
2221+
-l
2222+
"
2223+
_complete_ "$options_with_args" "$boolean_options"
2224+
case "$cur" in
2225+
-*)
2226+
COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
2227+
;;
2228+
*)
2229+
__podman_complete_pod_names
2230+
;;
2231+
esac
2232+
}
2233+
2234+
_podman_pod_pause() {
2235+
local options_with_args="
2236+
"
2237+
2238+
local boolean_options="
2239+
--all
2240+
-a
2241+
--latest
2242+
-l
2243+
"
2244+
_complete_ "$options_with_args" "$boolean_options"
2245+
case "$cur" in
2246+
-*)
2247+
COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur"))
2248+
;;
2249+
*)
2250+
__podman_complete_pod_names
2251+
;;
2252+
esac
2253+
}
2254+
2255+
_podman_pod_unpause() {
2256+
local options_with_args="
2257+
"
2258+
2259+
local boolean_options="
2260+
--all
2261+
-a
2262+
--latest
2263+
-l
22222264
"
22232265
_complete_ "$options_with_args" "$boolean_options"
22242266
case "$cur" in
@@ -2244,6 +2286,8 @@ _podman_pod() {
22442286
rm
22452287
start
22462288
stop
2289+
pause
2290+
unpause
22472291
"
22482292
local aliases="
22492293
list

docs/podman-pod-pause.1.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
% podman-pod-pause "1"
2+
3+
## NAME
4+
podman\-pod\-pause - Pause one or more pods
5+
6+
## SYNOPSIS
7+
**podman pod pause** [*options*] *pod* ...
8+
9+
## DESCRIPTION
10+
Pauses all the running processes in the containers of one or more pods. You may use pod IDs or names as input.
11+
12+
## OPTIONS
13+
14+
**--all, a**
15+
16+
Pause all pods.
17+
18+
**--latest, -l**
19+
20+
Instead of providing the pod name or ID, pause the last created pod.
21+
22+
## EXAMPLE
23+
24+
podman pod pause mywebserverpod
25+
26+
podman pod pause 860a4b23
27+
28+
## SEE ALSO
29+
podman-pod(1), podman-pod-unpause(1), podman-pause(1)
30+
31+
## HISTORY
32+
July 2018, Originally compiled by Peter Hunt <[email protected]>

docs/podman-pod-unpause.1.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
% podman-pod-unpause "1"
2+
3+
## NAME
4+
podman\-pod\-unpause - Unpause one or more pods
5+
6+
## SYNOPSIS
7+
**podman pod unpause** [*options*] *pod* ...
8+
9+
## DESCRIPTION
10+
Unpauses all the paused processes in the containers of one or more pods. You may use pod IDs or names as input.
11+
12+
## OPTIONS
13+
14+
**--all, a**
15+
16+
Unpause all pods.
17+
18+
**--latest, -l**
19+
20+
Instead of providing the pod name or ID, unpause the last created pod.
21+
22+
## EXAMPLE
23+
24+
podman pod unpause mywebserverpod
25+
26+
podman pod unpause 860a4b23
27+
28+
## SEE ALSO
29+
podman-pod(1), podman-pod-pause(1), podman-unpause(1)
30+
31+
## HISTORY
32+
July 2018, Originally compiled by Peter Hunt <[email protected]>

docs/podman-pod.1.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ podman pod is a set of subcommands that manage pods, or groups of containers.
1515
| ------------------------------------------------- | ------------------------------------------------------------------------------ |
1616
| [podman-pod-create(1)](podman-pod-create.1.md) | Create a new pod. |
1717
| [podman-pod-kill(1)](podman-pod-kill.1.md) | Kill the main process of each container in pod. |
18+
| [podman-pod-pause(1)](podman-pod-pause.1.md) | Pause one or more pods. |
1819
| [podman-pod-ps(1)](podman-pod-ps.1.md) | Prints out information about pods. |
1920
| [podman-pod-rm(1)](podman-pod-rm.1.md) | Remove one or more pods. |
2021
| [podman-pod-start(1)](podman-pod-start.1.md) | Start one or more pods. |
2122
| [podman-pod-stop(1)](podman-pod-stop.1.md) | Stop one or more pods. |
23+
| [podman-pod-unpause(1)](podman-pod-unpause.1.md) | Unpause one or more pods. |
2224

2325
## HISTORY
2426
July 2018, Originally compiled by Peter Hunt <[email protected]>

0 commit comments

Comments
 (0)