summaryrefslogtreecommitdiff
path: root/pkg/api
diff options
context:
space:
mode:
authorPaul Holzinger <paul.holzinger@web.de>2021-01-19 23:03:51 +0100
committerPaul Holzinger <paul.holzinger@web.de>2021-01-21 19:18:51 +0100
commit9d31fed5f75186f618e95ab7492ef6bc2b511d5f (patch)
tree11215b0dd70351b4157fd19a17c65d4fcfca77ed /pkg/api
parent7d024a2fc8c675e4d34e3b34b56b6217a48ef9ce (diff)
downloadpodman-9d31fed5f75186f618e95ab7492ef6bc2b511d5f.tar.gz
podman-9d31fed5f75186f618e95ab7492ef6bc2b511d5f.tar.bz2
podman-9d31fed5f75186f618e95ab7492ef6bc2b511d5f.zip
podman volume exists
Add podman volume exists command with remote support. Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
Diffstat (limited to 'pkg/api')
-rw-r--r--pkg/api/handlers/libpod/volumes.go19
-rw-r--r--pkg/api/server/register_volumes.go22
2 files changed, 41 insertions, 0 deletions
diff --git a/pkg/api/handlers/libpod/volumes.go b/pkg/api/handlers/libpod/volumes.go
index 38fdf1b4d..1a8759c6c 100644
--- a/pkg/api/handlers/libpod/volumes.go
+++ b/pkg/api/handlers/libpod/volumes.go
@@ -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, "")
+}
diff --git a/pkg/api/server/register_volumes.go b/pkg/api/server/register_volumes.go
index aa0f67604..68727f2e1 100644
--- a/pkg/api/server/register_volumes.go
+++ b/pkg/api/server/register_volumes.go
@@ -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: