summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/compat/containers_export.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-04-02 00:13:21 +0200
committerGitHub <noreply@github.com>2020-04-02 00:13:21 +0200
commit79f191cb5933ac0d3f64d123d8b8e6fec8e2a9c9 (patch)
tree055e000b03084fbd41cd7f9b6cf8c3c407f397c0 /pkg/api/handlers/compat/containers_export.go
parent0f357be5aeaa5dc651659cf0945a58780641e77d (diff)
parentbb39051616fbce12b4cb3135a62c7747273ab0aa (diff)
downloadpodman-79f191cb5933ac0d3f64d123d8b8e6fec8e2a9c9.tar.gz
podman-79f191cb5933ac0d3f64d123d8b8e6fec8e2a9c9.tar.bz2
podman-79f191cb5933ac0d3f64d123d8b8e6fec8e2a9c9.zip
Merge pull request #5697 from baude/v2export
podmanv2 export
Diffstat (limited to 'pkg/api/handlers/compat/containers_export.go')
-rw-r--r--pkg/api/handlers/compat/containers_export.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/pkg/api/handlers/compat/containers_export.go b/pkg/api/handlers/compat/containers_export.go
new file mode 100644
index 000000000..37b9fbf2b
--- /dev/null
+++ b/pkg/api/handlers/compat/containers_export.go
@@ -0,0 +1,42 @@
+package compat
+
+import (
+ "io/ioutil"
+ "net/http"
+ "os"
+
+ "github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/pkg/api/handlers/utils"
+ "github.com/pkg/errors"
+)
+
+func ExportContainer(w http.ResponseWriter, r *http.Request) {
+ runtime := r.Context().Value("runtime").(*libpod.Runtime)
+ name := utils.GetName(r)
+ con, err := runtime.LookupContainer(name)
+ if err != nil {
+ utils.ContainerNotFound(w, name, err)
+ return
+ }
+ tmpfile, err := ioutil.TempFile("", "api.tar")
+ if err != nil {
+ utils.Error(w, "unable to create tarball tempfile", http.StatusInternalServerError, errors.Wrap(err, "unable to create tempfile"))
+ return
+ }
+ defer os.Remove(tmpfile.Name())
+ if err := tmpfile.Close(); err != nil {
+ utils.Error(w, "unable to close tempfile", http.StatusInternalServerError, errors.Wrap(err, "unable to close tempfile"))
+ return
+ }
+ if err := con.Export(tmpfile.Name()); err != nil {
+ utils.Error(w, "failed to save the image", http.StatusInternalServerError, errors.Wrap(err, "failed to save image"))
+ return
+ }
+ rdr, err := os.Open(tmpfile.Name())
+ if err != nil {
+ utils.Error(w, "failed to read temp tarball", http.StatusInternalServerError, errors.Wrap(err, "failed to read the exported tarfile"))
+ return
+ }
+ defer rdr.Close()
+ utils.WriteResponse(w, http.StatusOK, rdr)
+}