Wire peer discovery delete into reset and rmpeer
This commit is contained in:
1 parent
768f89c3de
commit
c8adcb2e79
2 files changed
+18
-2
No files matched your search
@@ -69,8 +69,18 @@ func peerDiscoveryUpdate(discoveryEndpoint, token, peername, nickname string, ad
|
|||||||
return updateResponse.Addresses, err
|
return updateResponse.Addresses, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleHTTPPeer(router *mux.Router, alloc *ipam.Allocator) {
|
func peerDiscoveryDelete(discoveryEndpoint, token, peername string) error {
|
||||||
|
request := PeerUpdateRequest{Name: peername}
|
||||||
|
return do("DELETE", discoveryEndpoint, token, request, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func HandleHTTPPeer(router *mux.Router, alloc *ipam.Allocator, discoveryEndpoint, token, peername string) {
|
||||||
router.Methods("DELETE").Path("/peer").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
router.Methods("DELETE").Path("/peer").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if discoveryEndpoint != "" {
|
||||||
|
if err := peerDiscoveryDelete(discoveryEndpoint, token, peername); err != nil {
|
||||||
|
Log.Errorf("Error while deleting self from peer discovery: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
if alloc != nil {
|
if alloc != nil {
|
||||||
alloc.Shutdown()
|
alloc.Shutdown()
|
||||||
}
|
}
|
||||||
@@ -79,6 +89,12 @@ func HandleHTTPPeer(router *mux.Router, alloc *ipam.Allocator) {
|
|||||||
|
|
||||||
router.Methods("DELETE").Path("/peer/{id}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
router.Methods("DELETE").Path("/peer/{id}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
ident := mux.Vars(r)["id"]
|
ident := mux.Vars(r)["id"]
|
||||||
|
if discoveryEndpoint != "" {
|
||||||
|
// TODO: deal with this being either a peername or a nickname
|
||||||
|
if err := peerDiscoveryDelete(discoveryEndpoint, token, ident); err != nil {
|
||||||
|
Log.Errorf("Error while deleting self from peer discovery: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
if alloc != nil {
|
if alloc != nil {
|
||||||
transferred := alloc.AdminTakeoverRanges(ident)
|
transferred := alloc.AdminTakeoverRanges(ident)
|
||||||
fmt.Fprintf(w, "%d IPs taken over from %s\n", transferred, ident)
|
fmt.Fprintf(w, "%d IPs taken over from %s\n", transferred, ident)
|
||||||
|
|||||||
+1
-1
@@ -372,7 +372,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
router.HandleHTTP(muxRouter)
|
router.HandleHTTP(muxRouter)
|
||||||
HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver)
|
HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver)
|
||||||
HandleHTTPPeer(muxRouter, allocator)
|
HandleHTTPPeer(muxRouter, allocator, discoveryEndpoint, token, name.String())
|
||||||
muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver))
|
muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver))
|
||||||
http.Handle("/", common.LoggingHTTPHandler(muxRouter))
|
http.Handle("/", common.LoggingHTTPHandler(muxRouter))
|
||||||
Log.Println("Listening for HTTP control messages on", httpAddr)
|
Log.Println("Listening for HTTP control messages on", httpAddr)
|
||||||
|
|||||||
Reference in new issue
Block a user