aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorumohnani8 <umohnani@redhat.com>2017-11-22 15:36:00 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2017-11-24 15:53:17 +0000
commitb1a3b030688e28e6d7473d998cabbf923a8064f9 (patch)
tree7f6bdd607a3472def8601f36cbde64e52aa3065b /libpod
parent195d48d86d871f531d72e0669ea96d315845da35 (diff)
downloadpodman-b1a3b030688e28e6d7473d998cabbf923a8064f9.tar.gz
podman-b1a3b030688e28e6d7473d998cabbf923a8064f9.tar.bz2
podman-b1a3b030688e28e6d7473d998cabbf923a8064f9.zip
Update kpod pause and unpause to use new container state
Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #66 Approved by: mheon
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container.go55
-rw-r--r--libpod/oci.go10
2 files changed, 63 insertions, 2 deletions
diff --git a/libpod/container.go b/libpod/container.go
index f0a6d58eb..8bd1a0abf 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -536,12 +536,63 @@ func (c *Container) Unmount() error {
// Pause pauses a container
func (c *Container) Pause() error {
- return ErrNotImplemented
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
+ if err := c.syncContainer(); err != nil {
+ return err
+ }
+
+ if c.state.State == ContainerStatePaused {
+ return errors.Wrapf(ErrCtrStateInvalid, "%q is already paused", c.ID())
+ }
+ if c.state.State != ContainerStateRunning && c.state.State != ContainerStateCreated {
+ return errors.Wrapf(ErrCtrStateInvalid, "%q is not running/created, can't pause", c.state.State)
+ }
+ if err := c.runtime.ociRuntime.pauseContainer(c); err != nil {
+ return err
+ }
+
+ logrus.Debugf("Paused container %s", c.ID())
+
+ // Update container's state as it should be ContainerStatePaused now
+ if err := c.runtime.ociRuntime.updateContainerStatus(c); err != nil {
+ return err
+ }
+
+ if err := c.runtime.state.SaveContainer(c); err != nil {
+ return errors.Wrapf(err, "error saving container %s state", c.ID())
+ }
+ return nil
}
// Unpause unpauses a container
func (c *Container) Unpause() error {
- return ErrNotImplemented
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
+ if err := c.syncContainer(); err != nil {
+ return err
+ }
+
+ if c.state.State != ContainerStatePaused {
+ return errors.Wrapf(ErrCtrStateInvalid, "%q is not paused, can't unpause", c.ID())
+ }
+ if err := c.runtime.ociRuntime.unpauseContainer(c); err != nil {
+ return err
+ }
+
+ logrus.Debugf("Unpaused container %s", c.ID())
+
+ // Update container's state as it should be ContainerStateRunning now
+ if err := c.runtime.ociRuntime.updateContainerStatus(c); err != nil {
+ return err
+ }
+
+ if err := c.runtime.state.SaveContainer(c); err != nil {
+ return errors.Wrapf(err, "error saving container %s state", c.ID())
+ }
+ return nil
}
// Export exports a container's root filesystem as a tar archive
diff --git a/libpod/oci.go b/libpod/oci.go
index ddbd2f606..eb8bd0d93 100644
--- a/libpod/oci.go
+++ b/libpod/oci.go
@@ -345,3 +345,13 @@ func (r *OCIRuntime) startContainer(ctr *Container) error {
return nil
}
+
+// pauseContainer pauses the given container
+func (r *OCIRuntime) pauseContainer(ctr *Container) error {
+ return utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, r.path, "pause", ctr.ID())
+}
+
+// unpauseContainer unpauses the given container
+func (r *OCIRuntime) unpauseContainer(ctr *Container) error {
+ return utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, r.path, "resume", ctr.ID())
+}