github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/api/server/register_volumes.go (about)

     1  package server
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/containers/podman/v2/pkg/api/handlers/compat"
     7  	"github.com/containers/podman/v2/pkg/api/handlers/libpod"
     8  	"github.com/gorilla/mux"
     9  )
    10  
    11  func (s *APIServer) registerVolumeHandlers(r *mux.Router) error {
    12  	// swagger:operation POST /libpod/volumes/create libpod libpodCreateVolume
    13  	// ---
    14  	// tags:
    15  	//  - volumes
    16  	// summary: Create a volume
    17  	// parameters:
    18  	//  - in: body
    19  	//    name: create
    20  	//    description: attributes for creating a container
    21  	//    schema:
    22  	//      $ref: "#/definitions/VolumeCreate"
    23  	// produces:
    24  	// - application/json
    25  	// responses:
    26  	//   '201':
    27  	//     $ref: "#/responses/VolumeCreateResponse"
    28  	//   '500':
    29  	//      "$ref": "#/responses/InternalError"
    30  	r.Handle(VersionedPath("/libpod/volumes/create"), s.APIHandler(libpod.CreateVolume)).Methods(http.MethodPost)
    31  	// swagger:operation GET /libpod/volumes/json libpod libpodListVolumes
    32  	// ---
    33  	// tags:
    34  	//  - volumes
    35  	// summary: List volumes
    36  	// description: Returns a list of volumes
    37  	// produces:
    38  	// - application/json
    39  	// parameters:
    40  	//  - in: query
    41  	//    name: filters
    42  	//    type: string
    43  	//    description: |
    44  	//      JSON encoded value of the filters (a map[string][]string) to process on the volumes list. Available filters:
    45  	//        - driver=<volume-driver-name> Matches volumes based on their driver.
    46  	//        - label=<key> or label=<key>:<value> Matches volumes based on the presence of a label alone or a label and a value.
    47  	//        - name=<volume-name> Matches all of volume name.
    48  	//        - opt=<driver-option> Matches a storage driver options
    49  	// responses:
    50  	//   '200':
    51  	//     "$ref": "#/responses/VolumeList"
    52  	//   '500':
    53  	//      "$ref": "#/responses/InternalError"
    54  	r.Handle(VersionedPath("/libpod/volumes/json"), s.APIHandler(libpod.ListVolumes)).Methods(http.MethodGet)
    55  	// swagger:operation POST /libpod/volumes/prune libpod libpodPruneVolumes
    56  	// ---
    57  	// tags:
    58  	//  - volumes
    59  	// summary: Prune volumes
    60  	// produces:
    61  	// - application/json
    62  	// responses:
    63  	//   '200':
    64  	//      "$ref": "#/responses/VolumePruneResponse"
    65  	//   '500':
    66  	//      "$ref": "#/responses/InternalError"
    67  	r.Handle(VersionedPath("/libpod/volumes/prune"), s.APIHandler(libpod.PruneVolumes)).Methods(http.MethodPost)
    68  	// swagger:operation GET /libpod/volumes/{name}/json libpod libpodInspectVolume
    69  	// ---
    70  	// tags:
    71  	//  - volumes
    72  	// summary: Inspect volume
    73  	// parameters:
    74  	//  - in: path
    75  	//    name: name
    76  	//    type: string
    77  	//    required: true
    78  	//    description: the name or ID of the volume
    79  	// produces:
    80  	// - application/json
    81  	// responses:
    82  	//   '200':
    83  	//     "$ref": "#/responses/VolumeCreateResponse"
    84  	//   '404':
    85  	//     "$ref": "#/responses/NoSuchVolume"
    86  	//   '500':
    87  	//     "$ref": "#/responses/InternalError"
    88  	r.Handle(VersionedPath("/libpod/volumes/{name}/json"), s.APIHandler(libpod.InspectVolume)).Methods(http.MethodGet)
    89  	// swagger:operation DELETE /libpod/volumes/{name} libpod libpodRemoveVolume
    90  	// ---
    91  	// tags:
    92  	//  - volumes
    93  	// summary: Remove volume
    94  	// parameters:
    95  	//  - in: path
    96  	//    name: name
    97  	//    type: string
    98  	//    required: true
    99  	//    description: the name or ID of the volume
   100  	//  - in: query
   101  	//    name: force
   102  	//    type: boolean
   103  	//    description: force removal
   104  	// produces:
   105  	// - application/json
   106  	// responses:
   107  	//   204:
   108  	//     description: no error
   109  	//   404:
   110  	//     $ref: "#/responses/NoSuchVolume"
   111  	//   409:
   112  	//     description: Volume is in use and cannot be removed
   113  	//   500:
   114  	//     $ref: "#/responses/InternalError"
   115  	r.Handle(VersionedPath("/libpod/volumes/{name}"), s.APIHandler(libpod.RemoveVolume)).Methods(http.MethodDelete)
   116  
   117  	/*
   118  	 * Docker compatibility endpoints
   119  	 */
   120  
   121  	// swagger:operation GET /volumes compat listVolumes
   122  	// ---
   123  	// tags:
   124  	//  - volumes (compat)
   125  	// summary: List volumes
   126  	// description: Returns a list of volume
   127  	// produces:
   128  	// - application/json
   129  	// parameters:
   130  	//  - in: query
   131  	//    name: filters
   132  	//    type: string
   133  	//    description: |
   134  	//      JSON encoded value of the filters (a map[string][]string) to process on the volumes list. Available filters:
   135  	//        - driver=<volume-driver-name> Matches volumes based on their driver.
   136  	//        - label=<key> or label=<key>:<value> Matches volumes based on the presence of a label alone or a label and a value.
   137  	//        - name=<volume-name> Matches all of volume name.
   138  	//
   139  	//      Note:
   140  	//        The boolean `dangling` filter is not yet implemented for this endpoint.
   141  	// responses:
   142  	//   '200':
   143  	//     "$ref": "#/responses/VolumeListResponse"
   144  	//   '500':
   145  	//     "$ref": "#/responses/InternalError"
   146  	r.Handle(VersionedPath("/volumes"), s.APIHandler(compat.ListVolumes)).Methods(http.MethodGet)
   147  	r.Handle("/volumes", s.APIHandler(compat.ListVolumes)).Methods(http.MethodGet)
   148  
   149  	// swagger:operation POST /volumes/create compat createVolume
   150  	// ---
   151  	// tags:
   152  	//  - volumes (compat)
   153  	// summary: Create a volume
   154  	// parameters:
   155  	//  - in: body
   156  	//    name: create
   157  	//    description: |
   158  	//      attributes for creating a container.
   159  	//      Note: If a volume by the same name exists, a 201 response with that volume's information will be generated.
   160  	//    schema:
   161  	//      $ref: "#/definitions/DockerVolumeCreate"
   162  	// produces:
   163  	// - application/json
   164  	// responses:
   165  	//   '201':
   166  	//     "$ref": "#/responses/DockerVolumeInfoResponse"
   167  	//   '500':
   168  	//     "$ref": "#/responses/InternalError"
   169  	r.Handle(VersionedPath("/volumes/create"), s.APIHandler(compat.CreateVolume)).Methods(http.MethodPost)
   170  	r.Handle("/volumes/create", s.APIHandler(compat.CreateVolume)).Methods(http.MethodPost)
   171  
   172  	// swagger:operation GET /volumes/{name} compat inspectVolume
   173  	// ---
   174  	// tags:
   175  	//  - volumes (compat)
   176  	// summary: Inspect volume
   177  	// parameters:
   178  	//  - in: path
   179  	//    name: name
   180  	//    type: string
   181  	//    required: true
   182  	//    description: the name or ID of the volume
   183  	// produces:
   184  	// - application/json
   185  	// responses:
   186  	//   '200':
   187  	//     "$ref": "#/responses/DockerVolumeInfoResponse"
   188  	//   '404':
   189  	//     "$ref": "#/responses/NoSuchVolume"
   190  	//   '500':
   191  	//     "$ref": "#/responses/InternalError"
   192  	r.Handle(VersionedPath("/volumes/{name}"), s.APIHandler(compat.InspectVolume)).Methods(http.MethodGet)
   193  	r.Handle("/volumes/{name}", s.APIHandler(compat.InspectVolume)).Methods(http.MethodGet)
   194  
   195  	// swagger:operation DELETE /volumes/{name} compat removeVolume
   196  	// ---
   197  	// tags:
   198  	//  - volumes (compat)
   199  	// summary: Remove volume
   200  	// parameters:
   201  	//  - in: path
   202  	//    name: name
   203  	//    type: string
   204  	//    required: true
   205  	//    description: the name or ID of the volume
   206  	//  - in: query
   207  	//    name: force
   208  	//    type: boolean
   209  	//    description: |
   210  	//      Force removal of the volume. This actually only causes errors due
   211  	//      to the names volume not being found to be suppressed, which is the
   212  	//      behaviour Docker implements.
   213  	// produces:
   214  	// - application/json
   215  	// responses:
   216  	//   204:
   217  	//     description: no error
   218  	//   404:
   219  	//     "$ref": "#/responses/NoSuchVolume"
   220  	//   409:
   221  	//     description: Volume is in use and cannot be removed
   222  	//   500:
   223  	//     "$ref": "#/responses/InternalError"
   224  	r.Handle(VersionedPath("/volumes/{name}"), s.APIHandler(compat.RemoveVolume)).Methods(http.MethodDelete)
   225  	r.Handle("/volumes/{name}", s.APIHandler(compat.RemoveVolume)).Methods(http.MethodDelete)
   226  
   227  	// swagger:operation POST /volumes/prune compat pruneVolumes
   228  	// ---
   229  	// tags:
   230  	//  - volumes (compat)
   231  	// summary: Prune volumes
   232  	// produces:
   233  	// - application/json
   234  	// parameters:
   235  	//  - in: query
   236  	//    name: filters
   237  	//    type: string
   238  	//    description: |
   239  	//      JSON encoded value of filters (a map[string][]string) to match volumes against before pruning.
   240  	//
   241  	//      Note: No filters are currently supported and any filters specified will cause an error response.
   242  	// responses:
   243  	//   '200':
   244  	//      "$ref": "#/responses/DockerVolumePruneResponse"
   245  	//   '500':
   246  	//      "$ref": "#/responses/InternalError"
   247  	r.Handle(VersionedPath("/volumes/prune"), s.APIHandler(compat.PruneVolumes)).Methods(http.MethodPost)
   248  	r.Handle("/volumes/prune", s.APIHandler(compat.PruneVolumes)).Methods(http.MethodPost)
   249  
   250  	return nil
   251  }