mirror of
https://github.com/containers/podman.git
synced 2025-05-20 08:36:23 +08:00

create a container in podmanv2 using specgen approach. this is the core implementation and still has quite a bit of code commented out specifically around volumes, devices, and namespaces. need contributions from smes on these parts. Signed-off-by: Brent Baude <bbaude@redhat.com>
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
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/containers/libpod/pkg/specgen/generate"
|
|
"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
|
|
}
|
|
if err := generate.CompleteSpec(r.Context(), runtime, &sg); err != nil {
|
|
utils.InternalServerError(w, err)
|
|
return
|
|
}
|
|
ctr, err := generate.MakeContainer(runtime, &sg)
|
|
if err != nil {
|
|
utils.InternalServerError(w, err)
|
|
return
|
|
}
|
|
response := utils.ContainerCreateResponse{ID: ctr.ID()}
|
|
utils.WriteJSON(w, http.StatusCreated, response)
|
|
}
|