diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-02-19 23:49:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-19 23:49:06 +0100 |
commit | e561280510e4ef5fc4100811a971d134b01c72a9 (patch) | |
tree | 63bdda9690847c269079ea531e7beacc5eb7fe22 /pkg/api/handlers/utils/containers.go | |
parent | f2bcc9cc7dc8b1937f39db503db96651d84c3e3e (diff) | |
parent | d65ff6b3ec18aad6a64329c54a83d5ba5d51b62f (diff) | |
download | podman-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/utils/containers.go')
-rw-r--r-- | pkg/api/handlers/utils/containers.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/api/handlers/utils/containers.go b/pkg/api/handlers/utils/containers.go index c9bb9cf09..402005581 100644 --- a/pkg/api/handlers/utils/containers.go +++ b/pkg/api/handlers/utils/containers.go @@ -1,6 +1,7 @@ package utils import ( + "context" "fmt" "net/http" "syscall" @@ -9,10 +10,19 @@ import ( "github.com/containers/libpod/cmd/podman/shared" "github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod/define" + createconfig "github.com/containers/libpod/pkg/spec" "github.com/gorilla/schema" "github.com/pkg/errors" ) +// ContainerCreateResponse is the response struct for creating a container +type ContainerCreateResponse struct { + // ID of the container created + ID string `json:"id"` + // Warnings during container creation + Warnings []string `json:"Warnings"` +} + func KillContainer(w http.ResponseWriter, r *http.Request) (*libpod.Container, error) { runtime := r.Context().Value("runtime").(*libpod.Runtime) decoder := r.Context().Value("decoder").(*schema.Decoder) @@ -119,3 +129,18 @@ func GenerateFilterFuncsFromMap(r *libpod.Runtime, filters map[string][]string) } return filterFuncs, nil } + +func CreateContainer(ctx context.Context, w http.ResponseWriter, runtime *libpod.Runtime, cc *createconfig.CreateConfig) { + var pod *libpod.Pod + ctr, err := shared.CreateContainerFromCreateConfig(runtime, cc, ctx, pod) + if err != nil { + Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "CreateContainerFromCreateConfig()")) + return + } + + response := ContainerCreateResponse{ + ID: ctr.ID(), + Warnings: []string{}} + + WriteResponse(w, http.StatusCreated, response) +} |