summaryrefslogtreecommitdiff
path: root/libpod/adapter/runtime.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-02-05 19:33:06 +0100
committerGitHub <noreply@github.com>2019-02-05 19:33:06 +0100
commit650e242aa90fcb3f161da6e97921c606d3083215 (patch)
tree19a7bae6cd3bc117fa7b2e9dfe44d3534b4f75ed /libpod/adapter/runtime.go
parent3554bfce98bc643bd4724340bf2abbaa6373e70c (diff)
parent64c8fb7c2460eb561c8496f781f26d65443eea59 (diff)
downloadpodman-650e242aa90fcb3f161da6e97921c606d3083215.tar.gz
podman-650e242aa90fcb3f161da6e97921c606d3083215.tar.bz2
podman-650e242aa90fcb3f161da6e97921c606d3083215.zip
Merge pull request #2227 from baude/remoteexport
podman-remote import|export
Diffstat (limited to 'libpod/adapter/runtime.go')
-rw-r--r--libpod/adapter/runtime.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/libpod/adapter/runtime.go b/libpod/adapter/runtime.go
index 007257714..2c408dd2f 100644
--- a/libpod/adapter/runtime.go
+++ b/libpod/adapter/runtime.go
@@ -4,12 +4,17 @@ package adapter
import (
"context"
+ "github.com/pkg/errors"
"io"
+ "io/ioutil"
+ "os"
+ "strconv"
"github.com/containers/image/types"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/image"
+ "github.com/containers/libpod/pkg/rootless"
"github.com/urfave/cli"
)
@@ -104,3 +109,49 @@ func (r *LocalRuntime) LookupContainer(idOrName string) (*Container, error) {
func (r *LocalRuntime) PruneImages(all bool) ([]string, error) {
return r.ImageRuntime().PruneImages(all)
}
+
+// Export is a wrapper to container export to a tarfile
+func (r *LocalRuntime) Export(name string, path string) error {
+ ctr, err := r.Runtime.LookupContainer(name)
+ if err != nil {
+ return errors.Wrapf(err, "error looking up container %q", name)
+ }
+ if os.Geteuid() != 0 {
+ state, err := ctr.State()
+ if err != nil {
+ return errors.Wrapf(err, "cannot read container state %q", ctr.ID())
+ }
+ if state == libpod.ContainerStateRunning || state == libpod.ContainerStatePaused {
+ data, err := ioutil.ReadFile(ctr.Config().ConmonPidFile)
+ if err != nil {
+ return errors.Wrapf(err, "cannot read conmon PID file %q", ctr.Config().ConmonPidFile)
+ }
+ conmonPid, err := strconv.Atoi(string(data))
+ if err != nil {
+ return errors.Wrapf(err, "cannot parse PID %q", data)
+ }
+ became, ret, err := rootless.JoinDirectUserAndMountNS(uint(conmonPid))
+ if err != nil {
+ return err
+ }
+ if became {
+ os.Exit(ret)
+ }
+ } else {
+ became, ret, err := rootless.BecomeRootInUserNS()
+ if err != nil {
+ return err
+ }
+ if became {
+ os.Exit(ret)
+ }
+ }
+ }
+
+ return ctr.Export(path)
+}
+
+// Import is a wrapper to import a container image
+func (r *LocalRuntime) Import(ctx context.Context, source, reference string, changes []string, history string, quiet bool) (string, error) {
+ return r.Runtime.Import(ctx, source, reference, changes, history, quiet)
+}