mirror of https://github.com/status-im/consul.git
Adding more HTTP endpoints
This commit is contained in:
parent
1e3adb54f3
commit
5a087809dc
|
@ -0,0 +1,47 @@
|
|||
package agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (s *HTTPServer) AgentServices(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
// TODO
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *HTTPServer) AgentMembers(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
// Check if the WAN is being queried
|
||||
wan := false
|
||||
if other := req.URL.Query().Get("wan"); other != "" {
|
||||
wan = true
|
||||
}
|
||||
if wan {
|
||||
return s.agent.WANMembers(), nil
|
||||
} else {
|
||||
return s.agent.LANMembers(), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *HTTPServer) AgentJoin(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
// Check if the WAN is being queried
|
||||
wan := false
|
||||
if other := req.URL.Query().Get("wan"); other != "" {
|
||||
wan = true
|
||||
}
|
||||
|
||||
// Get the address
|
||||
addr := strings.TrimPrefix(req.URL.Path, "/v1/agent/join/")
|
||||
if wan {
|
||||
_, err := s.agent.JoinWAN([]string{addr})
|
||||
return err, nil
|
||||
} else {
|
||||
_, err := s.agent.JoinLAN([]string{addr})
|
||||
return err, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *HTTPServer) AgentForceLeave(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
addr := strings.TrimPrefix(req.URL.Path, "/v1/agent/force-leave/")
|
||||
return s.agent.ForceLeave(addr), nil
|
||||
}
|
|
@ -64,6 +64,11 @@ func (s *HTTPServer) registerHandlers() {
|
|||
s.mux.HandleFunc("/v1/catalog/services", s.wrap(s.CatalogServices))
|
||||
s.mux.HandleFunc("/v1/catalog/service/", s.wrap(s.CatalogServiceNodes))
|
||||
s.mux.HandleFunc("/v1/catalog/node/", s.wrap(s.CatalogNodeServices))
|
||||
|
||||
s.mux.HandleFunc("/v1/agent/services", s.wrap(s.AgentServices))
|
||||
s.mux.HandleFunc("/v1/agent/members", s.wrap(s.AgentMembers))
|
||||
s.mux.HandleFunc("/v1/agent/join/", s.wrap(s.AgentJoin))
|
||||
s.mux.HandleFunc("/v1/agent/force-leave/", s.wrap(s.AgentForceLeave))
|
||||
}
|
||||
|
||||
// wrap is used to wrap functions to make them more convenient
|
||||
|
|
|
@ -29,9 +29,9 @@ The current URLs supported are:
|
|||
* /v1/status/leader : Returns the current Raft leader
|
||||
* /v1/status/peers : Returns the current Raft peer set
|
||||
|
||||
* /v1/agent/services : Returns the services local agent is attempting to register
|
||||
* /v1/agent/health: Returns the health info from the local agent (future)
|
||||
* /v1/agent/services : Returns the services local agent is attempting to register
|
||||
* /v1/agent/members : Returns the members as seen by the local serf agent
|
||||
* /v1/agent/join : Instructs the local agent to join a node
|
||||
* /v1/agent/force-leave: Instructs the agent to force a node into the left state
|
||||
* /v1/agent/join/<node> : Instructs the local agent to join a node
|
||||
* /v1/agent/force-leave/<node>: Instructs the agent to force a node into the left state
|
||||
|
||||
|
|
Loading…
Reference in New Issue