Implement weave forget command

This commit is contained in:
Adam Harrison committed 2015-03-26 10:48:25 +00:00
1 parent 066d8001dd
commit dc8e82ea31
4 files changed
+30 -1

No files matched your search

+7
View File
@@ -52,6 +52,13 @@ func (cm *ConnectionMaker) InitiateConnection(address string) {
}
}
func (cm *ConnectionMaker) ForgetConnection(address string) {
cm.actionChan <- func() bool {
delete(cm.cmdLineAddress, NormalisePeerAddr(address))
return true
}
}
func (cm *ConnectionMaker) ConnectionTerminated(address string) {
cm.actionChan <- func() bool {
if target, found := cm.targets[address]; found {
+9 -1
View File
@@ -331,7 +331,15 @@ then on one of the existing hosts runs
host# weave connect $NEW_HOST
Other hosts in the weave network will automatically attempt to
establish connections to the new host too.
establish connections to the new host too. Conversely, it is possible
to instruct a peer to forget a particular host that was specified
to it via `weave launch` or `weave connect`:
host# weave forget $DECOMMISSIONED_HOST
This will prevent the peer from trying to reconnect to that host once
connectivity to it is lost, and thus can be used to administratively
remove peers from the network.
### <a name="container-mobility"></a>Container mobility
+5
View File
@@ -18,6 +18,7 @@ usage() {
echo "weave launch [-password <password>] [-nickname <nickname>] <peer> ..."
echo "weave launch-dns <cidr>"
echo "weave connect <peer>"
echo "weave forget <peer>"
echo "weave run [--with-dns] <cidr> <docker run args> ..."
echo "weave start <cidr> <container_id>"
echo "weave attach <cidr> <container_id>"
@@ -597,6 +598,10 @@ case "$COMMAND" in
[ $# -eq 1 ] || usage
http_call $CONTAINER_NAME $HTTP_PORT POST /connect -d "peer=$1"
;;
forget)
[ $# -eq 1 ] || usage
http_call $CONTAINER_NAME $HTTP_PORT POST /forget -d "peer=$1"
;;
status)
http_call $CONTAINER_NAME $HTTP_PORT GET /status || true
echo
+9
View File
@@ -176,6 +176,15 @@ func handleHttp(router *weave.Router) {
}
})
muxRouter.Methods("POST").Path("/forget").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
peer := r.FormValue("peer")
if addr, err := net.ResolveTCPAddr("tcp4", weave.NormalisePeerAddr(peer)); err == nil {
router.ConnectionMaker.ForgetConnection(addr.String())
} else {
http.Error(w, fmt.Sprint("invalid peer address: ", err), http.StatusBadRequest)
}
})
http.Handle("/", muxRouter)
address := fmt.Sprintf(":%d", weave.HttpPort)