From 768f89c3de4ed69d941afafe0ff4867bcc43a79a Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 9 Mar 2017 18:23:29 +0000 Subject: [PATCH] Move peer http handlers from ipam to weaver --- ipam/http.go | 11 ----------- prog/weaver/discovery.go | 21 +++++++++++++++++++++ prog/weaver/main.go | 1 + 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/ipam/http.go b/ipam/http.go index d6e08e51..b024f3ae 100644 --- a/ipam/http.go +++ b/ipam/http.go @@ -198,17 +198,6 @@ func (alloc *Allocator) HandleHTTP(router *mux.Router, defaultSubnet address.CID w.WriteHeader(204) }) - router.Methods("DELETE").Path("/peer").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - alloc.Shutdown() - w.WriteHeader(204) - }) - - router.Methods("DELETE").Path("/peer/{id}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - ident := mux.Vars(r)["id"] - transferred := alloc.AdminTakeoverRanges(ident) - fmt.Fprintf(w, "%d IPs taken over from %s\n", transferred, ident) - }) - router.Methods("GET").Path("/ipinfo/tracker").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, tracker) }) diff --git a/prog/weaver/discovery.go b/prog/weaver/discovery.go index 107a27ee..3331faa3 100644 --- a/prog/weaver/discovery.go +++ b/prog/weaver/discovery.go @@ -8,6 +8,10 @@ import ( "io/ioutil" "net/http" "time" + + "github.com/gorilla/mux" + + "github.com/weaveworks/weave/ipam" ) // TODO: move these definitions somewhere more shareable @@ -64,3 +68,20 @@ func peerDiscoveryUpdate(discoveryEndpoint, token, peername, nickname string, ad err := do("POST", discoveryEndpoint, token, request, &updateResponse) return updateResponse.Addresses, err } + +func HandleHTTPPeer(router *mux.Router, alloc *ipam.Allocator) { + router.Methods("DELETE").Path("/peer").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if alloc != nil { + alloc.Shutdown() + } + w.WriteHeader(204) + }) + + router.Methods("DELETE").Path("/peer/{id}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ident := mux.Vars(r)["id"] + if alloc != nil { + transferred := alloc.AdminTakeoverRanges(ident) + fmt.Fprintf(w, "%d IPs taken over from %s\n", transferred, ident) + } + }) +} diff --git a/prog/weaver/main.go b/prog/weaver/main.go index f6090f37..7e277952 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -372,6 +372,7 @@ func main() { } router.HandleHTTP(muxRouter) HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver) + HandleHTTPPeer(muxRouter, allocator) muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver)) http.Handle("/", common.LoggingHTTPHandler(muxRouter)) Log.Println("Listening for HTTP control messages on", httpAddr)