diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-04-14 14:34:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-14 14:34:18 +0200 |
commit | 004826653f2a8b064af8c1f055b1a402f4060d1c (patch) | |
tree | 715f035f049b161b55932fa9586f24c1876f11a5 /pkg/bindings | |
parent | 5cf64aee11063bc8e7ff22f1365b0bf6b3ab0900 (diff) | |
parent | d8d1aa49d27d51f914a0858ab99c57d7dc929926 (diff) | |
download | podman-004826653f2a8b064af8c1f055b1a402f4060d1c.tar.gz podman-004826653f2a8b064af8c1f055b1a402f4060d1c.tar.bz2 podman-004826653f2a8b064af8c1f055b1a402f4060d1c.zip |
Merge pull request #5803 from baude/v2init
v2podman add container init
Diffstat (limited to 'pkg/bindings')
-rw-r--r-- | pkg/bindings/containers/containers.go | 19 | ||||
-rw-r--r-- | pkg/bindings/test/containers_test.go | 18 |
2 files changed, 37 insertions, 0 deletions
diff --git a/pkg/bindings/containers/containers.go b/pkg/bindings/containers/containers.go index a188d73a0..963f0ec57 100644 --- a/pkg/bindings/containers/containers.go +++ b/pkg/bindings/containers/containers.go @@ -12,6 +12,7 @@ import ( "github.com/containers/libpod/pkg/api/handlers" "github.com/containers/libpod/pkg/bindings" "github.com/containers/libpod/pkg/domain/entities" + "github.com/pkg/errors" ) // List obtains a list of containers in local storage. All parameters to this method are optional. @@ -316,3 +317,21 @@ func Export(ctx context.Context, nameOrID string, w io.Writer) error { } return response.Process(nil) } + +// ContainerInit takes a created container and executes all of the +// preparations to run the container except it will not start +// or attach to the container +func ContainerInit(ctx context.Context, nameOrID string) error { + conn, err := bindings.GetClient(ctx) + if err != nil { + return err + } + response, err := conn.DoRequest(nil, http.MethodPost, "/containers/%s/init", nil, nameOrID) + if err != nil { + return err + } + if response.StatusCode == http.StatusNotModified { + return errors.Wrapf(define.ErrCtrStateInvalid, "container %s has already been created in runtime", nameOrID) + } + return response.Process(nil) +} diff --git a/pkg/bindings/test/containers_test.go b/pkg/bindings/test/containers_test.go index a8e2fd071..c6501ac9e 100644 --- a/pkg/bindings/test/containers_test.go +++ b/pkg/bindings/test/containers_test.go @@ -513,4 +513,22 @@ var _ = Describe("Podman containers ", func() { Expect(err).To(BeNil()) }) + It("container init on a bogus container", func() { + err := containers.ContainerInit(bt.conn, "doesnotexist") + Expect(err).ToNot(BeNil()) + code, _ := bindings.CheckResponseCode(err) + Expect(code).To(BeNumerically("==", http.StatusNotFound)) + }) + + It("container init", func() { + s := specgen.NewSpecGenerator(alpine.name) + ctr, err := containers.CreateWithSpec(bt.conn, s) + Expect(err).To(BeNil()) + err = containers.ContainerInit(bt.conn, ctr.ID) + Expect(err).To(BeNil()) + // trying to init again should be an error + err = containers.ContainerInit(bt.conn, ctr.ID) + Expect(err).ToNot(BeNil()) + }) + }) |