|
| 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 | +} |
0 commit comments