mirror of
https://github.com/containers/podman.git
synced 2025-12-02 02:58:03 +08:00
APIv2 review corrections #3
The third pass of corrections for the APIv2. Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
@@ -19,8 +19,6 @@ func StopContainer(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func ContainerExists(w http.ResponseWriter, r *http.Request) {
|
||||
// 404 no such container
|
||||
// 200 ok
|
||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||
name := mux.Vars(r)["name"]
|
||||
_, err := runtime.LookupContainer(name)
|
||||
@@ -147,10 +145,6 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) {
|
||||
// tail string
|
||||
}
|
||||
|
||||
func CreateContainer(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
func UnmountContainer(w http.ResponseWriter, r *http.Request) {
|
||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||
name := mux.Vars(r)["name"]
|
||||
|
||||
@@ -2,9 +2,11 @@ package libpod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/containers/libpod/libpod"
|
||||
"github.com/containers/libpod/pkg/api/handlers"
|
||||
@@ -91,12 +93,13 @@ func GetImages(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func PruneImages(w http.ResponseWriter, r *http.Request) {
|
||||
// 200 ok
|
||||
// 500 internal
|
||||
var (
|
||||
all bool
|
||||
err error
|
||||
)
|
||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||
query := struct {
|
||||
All bool `schema:"all"`
|
||||
Filters map[string][]string `schema:"filters"`
|
||||
}{
|
||||
// override any golang type defaults
|
||||
@@ -110,11 +113,16 @@ func PruneImages(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var libpodFilters = []string{}
|
||||
if _, found := r.URL.Query()["filters"]; found {
|
||||
all, err = strconv.ParseBool(query.Filters["all"][0])
|
||||
if err != nil {
|
||||
utils.InternalServerError(w, err)
|
||||
return
|
||||
}
|
||||
for k, v := range query.Filters {
|
||||
libpodFilters = append(libpodFilters, fmt.Sprintf("%s=%s", k, v[0]))
|
||||
}
|
||||
}
|
||||
cids, err := runtime.ImageRuntime().PruneImages(r.Context(), query.All, libpodFilters)
|
||||
cids, err := runtime.ImageRuntime().PruneImages(r.Context(), all, libpodFilters)
|
||||
if err != nil {
|
||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
|
||||
return
|
||||
@@ -171,3 +179,47 @@ func ExportImage(w http.ResponseWriter, r *http.Request) {
|
||||
defer os.Remove(tmpfile.Name())
|
||||
utils.WriteResponse(w, http.StatusOK, rdr)
|
||||
}
|
||||
|
||||
func ImportImage(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO this is basically wrong
|
||||
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||
|
||||
query := struct {
|
||||
Changes map[string]string `json:"changes"`
|
||||
Message string `json:"message"`
|
||||
Quiet bool `json:"quiet"`
|
||||
}{
|
||||
// This is where you can override the golang default value for one of fields
|
||||
}
|
||||
|
||||
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
|
||||
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
writer io.Writer
|
||||
)
|
||||
f, err := ioutil.TempFile("", "api_load.tar")
|
||||
if err != nil {
|
||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "failed to create tempfile"))
|
||||
return
|
||||
}
|
||||
if err := handlers.SaveFromBody(f, r); err != nil {
|
||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "failed to write temporary file"))
|
||||
return
|
||||
}
|
||||
id, err := runtime.LoadImage(r.Context(), "", f.Name(), writer, "")
|
||||
//id, err := runtime.Import(r.Context())
|
||||
if err != nil {
|
||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "failed to load image"))
|
||||
return
|
||||
}
|
||||
utils.WriteResponse(w, http.StatusOK, struct {
|
||||
Stream string `json:"stream"`
|
||||
}{
|
||||
Stream: fmt.Sprintf("Loaded image: %s\n", id),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ func PodDelete(w http.ResponseWriter, r *http.Request) {
|
||||
decoder = r.Context().Value("decoder").(*schema.Decoder)
|
||||
)
|
||||
query := struct {
|
||||
force bool `schema:"force"`
|
||||
Force bool `schema:"force"`
|
||||
}{
|
||||
// override any golang type defaults
|
||||
}
|
||||
@@ -284,7 +284,7 @@ func PodDelete(w http.ResponseWriter, r *http.Request) {
|
||||
utils.PodNotFound(w, name, err)
|
||||
return
|
||||
}
|
||||
if err := runtime.RemovePod(r.Context(), pod, true, query.force); err != nil {
|
||||
if err := runtime.RemovePod(r.Context(), pod, true, query.Force); err != nil {
|
||||
utils.Error(w, "Something went wrong", http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
@@ -309,43 +309,14 @@ func PodRestart(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func PodPrune(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
err error
|
||||
pods []*libpod.Pod
|
||||
runtime = r.Context().Value("runtime").(*libpod.Runtime)
|
||||
decoder = r.Context().Value("decoder").(*schema.Decoder)
|
||||
)
|
||||
query := struct {
|
||||
force bool `schema:"force"`
|
||||
}{
|
||||
// override any golang type defaults
|
||||
}
|
||||
|
||||
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
|
||||
utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
|
||||
errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
|
||||
pruned, err := runtime.PrunePods()
|
||||
if err != nil {
|
||||
utils.InternalServerError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
if query.force {
|
||||
pods, err = runtime.GetAllPods()
|
||||
if err != nil {
|
||||
utils.Error(w, "Something went wrong", http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// TODO We need to make a libpod.PruneVolumes or this code will be a mess. Volumes
|
||||
// already does this right. It will also help clean this code path up with less
|
||||
// conditionals. We do this when we integrate with libpod again.
|
||||
utils.Error(w, "not implemented", http.StatusInternalServerError, errors.New("not implemented"))
|
||||
return
|
||||
}
|
||||
for _, p := range pods {
|
||||
if err := runtime.RemovePod(r.Context(), p, true, query.force); err != nil {
|
||||
utils.Error(w, "Something went wrong", http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
utils.WriteResponse(w, http.StatusNoContent, "")
|
||||
utils.WriteResponse(w, http.StatusOK, pruned)
|
||||
}
|
||||
|
||||
func PodPause(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user