summaryrefslogtreecommitdiff
path: root/libpod/container_internal.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-06-07 14:33:20 +0200
committerGitHub <noreply@github.com>2019-06-07 14:33:20 +0200
commit346128792c9079d0092de4d84c16d63ce7df4515 (patch)
tree6048bf93558e5f7928cbb10690e3f88b3d975f5e /libpod/container_internal.go
parentba36a5f4461abfa2a2818b756bda4d6e609f6de6 (diff)
parentbef83c42eaacd83fb5020395f1bbdeb9a6f0f220 (diff)
downloadpodman-346128792c9079d0092de4d84c16d63ce7df4515.tar.gz
podman-346128792c9079d0092de4d84c16d63ce7df4515.tar.bz2
podman-346128792c9079d0092de4d84c16d63ce7df4515.zip
Merge pull request #2272 from adrianreber/migration
Add support to migrate containers
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r--libpod/container_internal.go40
1 files changed, 39 insertions, 1 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 5f8dd1c72..c0b5e4302 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -21,6 +21,7 @@ import (
"github.com/containers/storage/pkg/archive"
"github.com/containers/storage/pkg/mount"
spec "github.com/opencontainers/runtime-spec/specs-go"
+ "github.com/opencontainers/runtime-tools/generate"
"github.com/opencontainers/selinux/go-selinux/label"
opentracing "github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
@@ -1345,7 +1346,7 @@ func (c *Container) appendStringToRundir(destFile, output string) (string, error
return filepath.Join(c.state.RunDir, destFile), nil
}
-// Save OCI spec to disk, replacing any existing specs for the container
+// saveSpec saves the OCI spec to disk, replacing any existing specs for the container
func (c *Container) saveSpec(spec *spec.Spec) error {
// If the OCI spec already exists, we need to replace it
// Cannot guarantee some things, e.g. network namespaces, have the same
@@ -1501,3 +1502,40 @@ func (c *Container) checkReadyForRemoval() error {
return nil
}
+
+// writeJSONFile marshalls and writes the given data to a JSON file
+// in the bundle path
+func (c *Container) writeJSONFile(v interface{}, file string) (err error) {
+ fileJSON, err := json.MarshalIndent(v, "", " ")
+ if err != nil {
+ return errors.Wrapf(err, "error writing JSON to %s for container %s", file, c.ID())
+ }
+ file = filepath.Join(c.bundlePath(), file)
+ if err := ioutil.WriteFile(file, fileJSON, 0644); err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// prepareCheckpointExport writes the config and spec to
+// JSON files for later export
+func (c *Container) prepareCheckpointExport() (err error) {
+ // save live config
+ if err := c.writeJSONFile(c.Config(), "config.dump"); err != nil {
+ return err
+ }
+
+ // save spec
+ jsonPath := filepath.Join(c.bundlePath(), "config.json")
+ g, err := generate.NewFromFile(jsonPath)
+ if err != nil {
+ logrus.Debugf("generating spec for container %q failed with %v", c.ID(), err)
+ return err
+ }
+ if err := c.writeJSONFile(g.Spec(), "spec.dump"); err != nil {
+ return err
+ }
+
+ return nil
+}