Merge pull request #9027 from Luap99/podman-volume-exists

Podman volume exists
This commit is contained in:
OpenShift Merge Robot
2021-01-21 15:31:32 -05:00
committed by GitHub
14 changed files with 307 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/containers/podman/v2/pkg/domain/entities/reports"
"github.com/containers/podman/v2/pkg/domain/filters"
"github.com/containers/podman/v2/pkg/domain/infra/abi"
"github.com/containers/podman/v2/pkg/domain/infra/abi/parse"
"github.com/gorilla/schema"
"github.com/pkg/errors"
@ -203,3 +204,21 @@ func RemoveVolume(w http.ResponseWriter, r *http.Request) {
}
utils.WriteResponse(w, http.StatusNoContent, "")
}
// ExistsVolume check if a volume exists
func ExistsVolume(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
name := utils.GetName(r)
ic := abi.ContainerEngine{Libpod: runtime}
report, err := ic.VolumeExists(r.Context(), name)
if err != nil {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
return
}
if !report.Value {
utils.Error(w, "volume not found", http.StatusNotFound, define.ErrNoSuchVolume)
return
}
utils.WriteResponse(w, http.StatusNoContent, "")
}

View File

@ -28,6 +28,28 @@ func (s *APIServer) registerVolumeHandlers(r *mux.Router) error {
// '500':
// "$ref": "#/responses/InternalError"
r.Handle(VersionedPath("/libpod/volumes/create"), s.APIHandler(libpod.CreateVolume)).Methods(http.MethodPost)
// swagger:operation GET /libpod/volumes/{name}/exists libpod libpodExistsVolume
// ---
// tags:
// - volumes
// summary: Volume exists
// description: Check if a volume exists
// parameters:
// - in: path
// name: name
// type: string
// required: true
// description: the name of the volume
// produces:
// - application/json
// responses:
// 204:
// description: volume exists
// 404:
// $ref: '#/responses/NoSuchVolume'
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/libpod/volumes/{name}/exists"), s.APIHandler(libpod.ExistsVolume)).Methods(http.MethodGet)
// swagger:operation GET /libpod/volumes/json libpod libpodListVolumes
// ---
// tags: