mirror of
https://github.com/containers/podman.git
synced 2025-07-31 12:22:29 +08:00
apiv2 container create using specgen
this uses the specgen structure to create containers rather than the outdated createconfig. right now, only the apiv2 create is wired up. eventually the cli will also have to be done. Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
29
pkg/api/handlers/libpod/containers_create.go
Normal file
29
pkg/api/handlers/libpod/containers_create.go
Normal file
@ -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)
|
||||
}
|
Reference in New Issue
Block a user