diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-03-27 16:25:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-27 16:25:30 +0100 |
commit | 4233250c430a8f769048548b6ad6affd0d9e65e0 (patch) | |
tree | 0cf0c3dc86ccf85be3d5098f278021798c3f6b6c /pkg/bindings | |
parent | 3ddb5b10d53df54346a6d795047124fc4e995699 (diff) | |
parent | e56d5295614b745115abf0198f7b67ae157aae1e (diff) | |
download | podman-4233250c430a8f769048548b6ad6affd0d9e65e0.tar.gz podman-4233250c430a8f769048548b6ad6affd0d9e65e0.tar.bz2 podman-4233250c430a8f769048548b6ad6affd0d9e65e0.zip |
Merge pull request #5611 from baude/v2podcreate
podmanv2 pod create using podspecgen
Diffstat (limited to 'pkg/bindings')
-rw-r--r-- | pkg/bindings/pods/pods.go | 24 | ||||
-rw-r--r-- | pkg/bindings/test/pods_test.go | 12 |
2 files changed, 33 insertions, 3 deletions
diff --git a/pkg/bindings/pods/pods.go b/pkg/bindings/pods/pods.go index 49cce6e2b..bb0abebc4 100644 --- a/pkg/bindings/pods/pods.go +++ b/pkg/bindings/pods/pods.go @@ -5,15 +5,33 @@ import ( "net/http" "net/url" "strconv" + "strings" "github.com/containers/libpod/libpod" "github.com/containers/libpod/pkg/bindings" "github.com/containers/libpod/pkg/domain/entities" + "github.com/containers/libpod/pkg/specgen" + jsoniter "github.com/json-iterator/go" ) -func CreatePod() error { - // TODO - return bindings.ErrNotImplemented +func CreatePodFromSpec(ctx context.Context, s *specgen.PodSpecGenerator) (*entities.PodCreateReport, error) { + var ( + pcr entities.PodCreateReport + ) + conn, err := bindings.GetClient(ctx) + if err != nil { + return nil, err + } + specgenString, err := jsoniter.MarshalToString(s) + if err != nil { + return nil, err + } + stringReader := strings.NewReader(specgenString) + response, err := conn.DoRequest(stringReader, http.MethodPost, "/pods/create", nil) + if err != nil { + return nil, err + } + return &pcr, response.Process(&pcr) } // Exists is a lightweight method to determine if a pod exists in local storage diff --git a/pkg/bindings/test/pods_test.go b/pkg/bindings/test/pods_test.go index c54170648..0f786e341 100644 --- a/pkg/bindings/test/pods_test.go +++ b/pkg/bindings/test/pods_test.go @@ -7,6 +7,7 @@ import ( "github.com/containers/libpod/libpod/define" "github.com/containers/libpod/pkg/bindings" "github.com/containers/libpod/pkg/bindings/pods" + "github.com/containers/libpod/pkg/specgen" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gexec" @@ -307,4 +308,15 @@ var _ = Describe("Podman pods", func() { Expect(err).To(BeNil()) Expect(len(podSummary)).To(Equal(0)) }) + + It("simple create pod", func() { + ps := specgen.PodSpecGenerator{} + ps.Name = "foobar" + _, err := pods.CreatePodFromSpec(bt.conn, &ps) + Expect(err).To(BeNil()) + + exists, err := pods.Exists(bt.conn, "foobar") + Expect(err).To(BeNil()) + Expect(exists).To(BeTrue()) + }) }) |