mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
The List Volumes API was originally written for CSI but assumed we'd have future volume types, dispatched on a query parameter. Dynamic host volumes uses this, but the resulting code has host volumes concerns comingled in the CSI volumes endpoint. Refactor this so that we have a top-level `GET /v1/volumes` route that's shared between CSI and DHV, and have it dispatch to the appropriate handler in the type-specific endpoints. Ref: https://github.com/hashicorp/nomad/pull/24479
28 lines
651 B
Go
28 lines
651 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package agent
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
)
|
|
|
|
// ListVolumesRequest dispatches requests for listing volumes to a specific type.
|
|
func (s *HTTPServer) ListVolumesRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
query := req.URL.Query()
|
|
qtype, ok := query["type"]
|
|
if !ok {
|
|
return []*structs.CSIVolListStub{}, nil
|
|
}
|
|
switch qtype[0] {
|
|
case "host":
|
|
return s.HostVolumesListRequest(resp, req)
|
|
case "csi":
|
|
return s.CSIVolumesRequest(resp, req)
|
|
default:
|
|
return nil, CodedError(404, resourceNotFoundErr)
|
|
}
|
|
}
|