mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 09:25:46 +03:00
32 lines
861 B
Go
32 lines
861 B
Go
package agent
|
|
|
|
import (
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
"net/http"
|
|
)
|
|
|
|
// ResourceListRequest accepts a prefix and context and returns a list of matching
|
|
// IDs for that context.
|
|
func (s *HTTPServer) ResourceListRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
if req.Method == "POST" || req.Method == "PUT" {
|
|
return s.resourcesRequest(resp, req)
|
|
}
|
|
return nil, CodedError(405, ErrInvalidMethod)
|
|
}
|
|
|
|
func (s *HTTPServer) resourcesRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
args := structs.ResourceListRequest{}
|
|
|
|
if err := decodeBody(req, &args); err != nil {
|
|
return nil, CodedError(400, err.Error())
|
|
}
|
|
|
|
var out structs.ResourceListResponse
|
|
if err := s.agent.RPC("Resources.List", &args, &out); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
setMeta(resp, &out.QueryMeta)
|
|
return out, nil
|
|
}
|