summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/libpod/containers_create.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-02-19 23:49:06 +0100
committerGitHub <noreply@github.com>2020-02-19 23:49:06 +0100
commite561280510e4ef5fc4100811a971d134b01c72a9 (patch)
tree63bdda9690847c269079ea531e7beacc5eb7fe22 /pkg/api/handlers/libpod/containers_create.go
parentf2bcc9cc7dc8b1937f39db503db96651d84c3e3e (diff)
parentd65ff6b3ec18aad6a64329c54a83d5ba5d51b62f (diff)
downloadpodman-e561280510e4ef5fc4100811a971d134b01c72a9.tar.gz
podman-e561280510e4ef5fc4100811a971d134b01c72a9.tar.bz2
podman-e561280510e4ef5fc4100811a971d134b01c72a9.zip
Merge pull request #5204 from baude/apiv2createlibpod
apiv2 container create using specgen
Diffstat (limited to 'pkg/api/handlers/libpod/containers_create.go')
-rw-r--r--pkg/api/handlers/libpod/containers_create.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/pkg/api/handlers/libpod/containers_create.go b/pkg/api/handlers/libpod/containers_create.go
new file mode 100644
index 000000000..ebca41151
--- /dev/null
+++ b/pkg/api/handlers/libpod/containers_create.go
@@ -0,0 +1,29 @@
+package libpod
+
+import (
+ "encoding/json"
+ "net/http"
+
+ "github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/pkg/api/handlers/utils"
+ "github.com/containers/libpod/pkg/specgen"
+ "github.com/pkg/errors"
+)
+
+// CreateContainer takes a specgenerator and makes a container. It returns
+// the new container ID on success along with any warnings.
+func CreateContainer(w http.ResponseWriter, r *http.Request) {
+ runtime := r.Context().Value("runtime").(*libpod.Runtime)
+ var sg specgen.SpecGenerator
+ if err := json.NewDecoder(r.Body).Decode(&sg); err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
+ return
+ }
+ ctr, err := sg.MakeContainer(runtime)
+ if err != nil {
+ utils.InternalServerError(w, err)
+ return
+ }
+ response := utils.ContainerCreateResponse{ID: ctr.ID()}
+ utils.WriteJSON(w, http.StatusCreated, response)
+}