github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/api/server/register_volumes.go (about)

     1  package server
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/hanks177/podman/v4/pkg/api/handlers/compat"
     7  	"github.com/hanks177/podman/v4/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 VolumeCreateLibpod
    13  	// ---
    14  	// tags:
    15  	//  - volumes
    16  	// summary: Create a volume
    17  	// parameters:
    18  	//  - in: body
    19  	//    name: create
    20  	//    description: attributes for creating a volume
    21  	//    schema:
    22  	//      $ref: "#/definitions/VolumeCreateOptions"
    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/{name}/exists libpod VolumeExistsLibpod
    32  	// ---
    33  	// tags:
    34  	//  - volumes
    35  	// summary: Volume exists
    36  	// description: Check if a volume exists
    37  	// parameters:
    38  	//  - in: path
    39  	//    name: name
    40  	//    type: string
    41  	//    required: true
    42  	//    description: the name of the volume
    43  	// produces:
    44  	// - application/json
    45  	// responses:
    46  	//   204:
    47  	//     description: volume exists
    48  	//   404:
    49  	//     $ref: '#/responses/volumeNotFound'
    50  	//   500:
    51  	//     $ref: '#/responses/internalError'
    52  	r.Handle(VersionedPath("/libpod/volumes/{name}/exists"), s.APIHandler(libpod.ExistsVolume)).Methods(http.MethodGet)
    53  	// swagger:operation GET /libpod/volumes/json libpod VolumeListLibpod
    54  	// ---
    55  	// tags:
    56  	//  - volumes
    57  	// summary: List volumes
    58  	// description: Returns a list of volumes
    59  	// produces:
    60  	// - application/json
    61  	// parameters:
    62  	//  - in: query
    63  	//    name: filters
    64  	//    type: string
    65  	//    description: |
    66  	//      JSON encoded value of the filters (a map[string][]string) to process on the volumes list. Available filters:
    67  	//        - driver=<volume-driver-name> Matches volumes based on their driver.
    68  	//        - label=<key> or label=<key>:<value> Matches volumes based on the presence of a label alone or a label and a value.
    69  	//        - name=<volume-name> Matches all of volume name.
    70  	//        - opt=<driver-option> Matches a storage driver options
    71  	//        - `until=<timestamp>` List volumes created before this timestamp. The `<timestamp>` can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. `10m`, `1h30m`) computed relative to the daemon machine’s time.
    72  	// responses:
    73  	//   '200':
    74  	//     "$ref": "#/responses/volumeListLibpod"
    75  	//   '500':
    76  	//      "$ref": "#/responses/internalError"
    77  	r.Handle(VersionedPath("/libpod/volumes/json"), s.APIHandler(libpod.ListVolumes)).Methods(http.MethodGet)
    78  	// swagger:operation POST /libpod/volumes/prune libpod VolumePruneLibpod
    79  	// ---
    80  	// tags:
    81  	//  - volumes
    82  	// summary: Prune volumes
    83  	// produces:
    84  	// - application/json
    85  	// parameters:
    86  	//  - in: query
    87  	//    name: filters
    88  	//    type: string
    89  	//    description: |
    90  	//      JSON encoded value of filters (a map[string][]string) to match volumes against before pruning.
    91  	//      Available filters:
    92  	//        - `until=<timestamp>` Prune volumes created before this timestamp. The `<timestamp>` can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. `10m`, `1h30m`) computed relative to the daemon machine’s time.
    93  	//        - `label` (`label=<key>`, `label=<key>=<value>`, `label!=<key>`, or `label!=<key>=<value>`) Prune volumes with (or without, in case `label!=...` is used) the specified labels.
    94  	// responses:
    95  	//   '200':
    96  	//      "$ref": "#/responses/volumePruneLibpod"
    97  	//   '500':
    98  	//      "$ref": "#/responses/internalError"
    99  	r.Handle(VersionedPath("/libpod/volumes/prune"), s.APIHandler(libpod.PruneVolumes)).Methods(http.MethodPost)
   100  	// swagger:operation GET /libpod/volumes/{name}/json libpod VolumeInspectLibpod
   101  	// ---
   102  	// tags:
   103  	//  - volumes
   104  	// summary: Inspect volume
   105  	// parameters:
   106  	//  - in: path
   107  	//    name: name
   108  	//    type: string
   109  	//    required: true
   110  	//    description: the name or ID of the volume
   111  	// produces:
   112  	// - application/json
   113  	// responses:
   114  	//   200:
   115  	//     $ref: "#/responses/volumeCreateResponse"
   116  	//   404:
   117  	//     $ref: "#/responses/volumeNotFound"
   118  	//   500:
   119  	//     $ref: "#/responses/internalError"
   120  	r.Handle(VersionedPath("/libpod/volumes/{name}/json"), s.APIHandler(libpod.InspectVolume)).Methods(http.MethodGet)
   121  	// swagger:operation DELETE /libpod/volumes/{name} libpod VolumeDeleteLibpod
   122  	// ---
   123  	// tags:
   124  	//  - volumes
   125  	// summary: Remove volume
   126  	// parameters:
   127  	//  - in: path
   128  	//    name: name
   129  	//    type: string
   130  	//    required: true
   131  	//    description: the name or ID of the volume
   132  	//  - in: query
   133  	//    name: force
   134  	//    type: boolean
   135  	//    description: force removal
   136  	// produces:
   137  	// - application/json
   138  	// responses:
   139  	//   204:
   140  	//     description: no error
   141  	//   404:
   142  	//     $ref: "#/responses/volumeNotFound"
   143  	//   409:
   144  	//     description: Volume is in use and cannot be removed
   145  	//   500:
   146  	//     $ref: "#/responses/internalError"
   147  	r.Handle(VersionedPath("/libpod/volumes/{name}"), s.APIHandler(libpod.RemoveVolume)).Methods(http.MethodDelete)
   148  
   149  	/*
   150  	 * Docker compatibility endpoints
   151  	 */
   152  
   153  	// swagger:operation GET /volumes compat VolumeList
   154  	// ---
   155  	// tags:
   156  	//  - volumes (compat)
   157  	// summary: List volumes
   158  	// description: Returns a list of volume
   159  	// produces:
   160  	// - application/json
   161  	// parameters:
   162  	//  - in: query
   163  	//    name: filters
   164  	//    type: string
   165  	//    description: |
   166  	//      JSON encoded value of the filters (a map[string][]string) to process on the volumes list. Available filters:
   167  	//        - driver=<volume-driver-name> Matches volumes based on their driver.
   168  	//        - label=<key> or label=<key>:<value> Matches volumes based on the presence of a label alone or a label and a value.
   169  	//        - name=<volume-name> Matches all of volume name.
   170  	//        - `until=<timestamp>` List volumes created before this timestamp. The `<timestamp>` can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. `10m`, `1h30m`) computed relative to the daemon machine’s time.
   171  	//
   172  	//      Note:
   173  	//        The boolean `dangling` filter is not yet implemented for this endpoint.
   174  	// responses:
   175  	//   '200':
   176  	//     "$ref": "#/responses/volumeList"
   177  	//   '500':
   178  	//     "$ref": "#/responses/internalError"
   179  	r.Handle(VersionedPath("/volumes"), s.APIHandler(compat.ListVolumes)).Methods(http.MethodGet)
   180  	r.Handle("/volumes", s.APIHandler(compat.ListVolumes)).Methods(http.MethodGet)
   181  
   182  	// swagger:operation POST /volumes/create compat VolumeCreate
   183  	// ---
   184  	// tags:
   185  	//  - volumes (compat)
   186  	// summary: Create a volume
   187  	// parameters:
   188  	//  - in: body
   189  	//    name: create
   190  	//    description: |
   191  	//      attributes for creating a volume.
   192  	//      Note: If a volume by the same name exists, a 201 response with that volume's information will be generated.
   193  	//    schema:
   194  	//      $ref: "#/definitions/volumeCreate"
   195  	// produces:
   196  	// - application/json
   197  	// responses:
   198  	//   '201':
   199  	//     "$ref": "#/responses/volumeInspect"
   200  	//   '500':
   201  	//     "$ref": "#/responses/internalError"
   202  	r.Handle(VersionedPath("/volumes/create"), s.APIHandler(compat.CreateVolume)).Methods(http.MethodPost)
   203  	r.Handle("/volumes/create", s.APIHandler(compat.CreateVolume)).Methods(http.MethodPost)
   204  
   205  	// swagger:operation GET /volumes/{name} compat VolumeInspect
   206  	// ---
   207  	// tags:
   208  	//  - volumes (compat)
   209  	// summary: Inspect volume
   210  	// parameters:
   211  	//  - in: path
   212  	//    name: name
   213  	//    type: string
   214  	//    required: true
   215  	//    description: the name or ID of the volume
   216  	// produces:
   217  	// - application/json
   218  	// responses:
   219  	//   200:
   220  	//     $ref: "#/responses/volumeInspect"
   221  	//   40':
   222  	//     $ref: "#/responses/volumeNotFound"
   223  	//   500:
   224  	//     $ref: "#/responses/internalError"
   225  	r.Handle(VersionedPath("/volumes/{name}"), s.APIHandler(compat.InspectVolume)).Methods(http.MethodGet)
   226  	r.Handle("/volumes/{name}", s.APIHandler(compat.InspectVolume)).Methods(http.MethodGet)
   227  
   228  	// swagger:operation DELETE /volumes/{name} compat VolumeDelete
   229  	// ---
   230  	// tags:
   231  	//  - volumes (compat)
   232  	// summary: Remove volume
   233  	// parameters:
   234  	//  - in: path
   235  	//    name: name
   236  	//    type: string
   237  	//    required: true
   238  	//    description: the name or ID of the volume
   239  	//  - in: query
   240  	//    name: force
   241  	//    type: boolean
   242  	//    description: |
   243  	//      Force removal of the volume. This actually only causes errors due
   244  	//      to the names volume not being found to be suppressed, which is the
   245  	//      behaviour Docker implements.
   246  	// produces:
   247  	// - application/json
   248  	// responses:
   249  	//   204:
   250  	//     description: no error
   251  	//   404:
   252  	//     $ref: "#/responses/volumeNotFound"
   253  	//   409:
   254  	//     description: Volume is in use and cannot be removed
   255  	//   500:
   256  	//     "$ref": "#/responses/internalError"
   257  	r.Handle(VersionedPath("/volumes/{name}"), s.APIHandler(compat.RemoveVolume)).Methods(http.MethodDelete)
   258  	r.Handle("/volumes/{name}", s.APIHandler(compat.RemoveVolume)).Methods(http.MethodDelete)
   259  
   260  	// swagger:operation POST /volumes/prune compat VolumePrune
   261  	// ---
   262  	// tags:
   263  	//  - volumes (compat)
   264  	// summary: Prune volumes
   265  	// produces:
   266  	// - application/json
   267  	// parameters:
   268  	//  - in: query
   269  	//    name: filters
   270  	//    type: string
   271  	//    description: |
   272  	//      JSON encoded value of filters (a map[string][]string) to match volumes against before pruning.
   273  	//      Available filters:
   274  	//        - `until=<timestamp>` Prune volumes created before this timestamp. The `<timestamp>` can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. `10m`, `1h30m`) computed relative to the daemon machine’s time.
   275  	//        - `label` (`label=<key>`, `label=<key>=<value>`, `label!=<key>`, or `label!=<key>=<value>`) Prune volumes with (or without, in case `label!=...` is used) the specified labels.
   276  	// responses:
   277  	//   '200':
   278  	//      "$ref": "#/responses/volumePruneResponse"
   279  	//   '500':
   280  	//      "$ref": "#/responses/internalError"
   281  	r.Handle(VersionedPath("/volumes/prune"), s.APIHandler(compat.PruneVolumes)).Methods(http.MethodPost)
   282  	r.Handle("/volumes/prune", s.APIHandler(compat.PruneVolumes)).Methods(http.MethodPost)
   283  
   284  	return nil
   285  }