Merge pull request #800 from paulbellamy/proxy-status
Add proxy info to 'weave status' output Closes #756.
This commit is contained in:
commit
59fd53ee99
3 files changed
+54
-15
No files matched your search
+39
-5
@@ -1,6 +1,8 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -19,14 +21,17 @@ var (
|
||||
|
||||
type Proxy struct {
|
||||
Dial func() (net.Conn, error)
|
||||
version string
|
||||
client *docker.Client
|
||||
dockerAddr string
|
||||
listenAddr string
|
||||
withDNS bool
|
||||
dockerBridgeIP string
|
||||
withIPAM bool
|
||||
}
|
||||
|
||||
func NewProxy(targetURL string, withDNS, withIPAM bool) (*Proxy, error) {
|
||||
u, err := url.Parse(targetURL)
|
||||
func NewProxy(version, dockerAddr, listenAddr string, withDNS, withIPAM bool) (*Proxy, error) {
|
||||
u, err := url.Parse(dockerAddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -39,7 +44,7 @@ func NewProxy(targetURL string, withDNS, withIPAM bool) (*Proxy, error) {
|
||||
}
|
||||
}
|
||||
|
||||
client, err := docker.NewClient(targetURL)
|
||||
client, err := docker.NewClient(dockerAddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -56,7 +61,10 @@ func NewProxy(targetURL string, withDNS, withIPAM bool) (*Proxy, error) {
|
||||
Dial: func() (net.Conn, error) {
|
||||
return net.Dial(u.Scheme, targetAddr)
|
||||
},
|
||||
version: version,
|
||||
client: client,
|
||||
dockerAddr: dockerAddr,
|
||||
listenAddr: listenAddr,
|
||||
withDNS: withDNS,
|
||||
dockerBridgeIP: string(dockerBridgeIP),
|
||||
withIPAM: withIPAM,
|
||||
@@ -73,8 +81,9 @@ func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
proxy.serveWithInterceptor(&startContainerInterceptor{proxy.client, proxy.withDNS, proxy.withIPAM}, w, r)
|
||||
case execCreateRegexp.MatchString(path):
|
||||
proxy.serveWithInterceptor(&createExecInterceptor{proxy.client, proxy.withIPAM}, w, r)
|
||||
case strings.HasPrefix(path, "/weave"):
|
||||
w.WriteHeader(http.StatusOK)
|
||||
case strings.HasPrefix(path, "/status"):
|
||||
fmt.Fprintln(w, "weave proxy", proxy.version)
|
||||
fmt.Fprintln(w, proxy.Status())
|
||||
default:
|
||||
proxy.serveWithInterceptor(&nullInterceptor{}, w, r)
|
||||
}
|
||||
@@ -83,3 +92,28 @@ func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
func (proxy *Proxy) serveWithInterceptor(i interceptor, w http.ResponseWriter, r *http.Request) {
|
||||
newClient(proxy.Dial, i).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
// Return status string
|
||||
func (proxy *Proxy) Status() string {
|
||||
var buf bytes.Buffer
|
||||
fmt.Fprintln(&buf, "Listen address is", proxy.listenAddr)
|
||||
fmt.Fprintln(&buf, "Docker address is", proxy.dockerAddr)
|
||||
if proxy.withDNS {
|
||||
fmt.Fprintln(&buf, "DNS on")
|
||||
} else {
|
||||
fmt.Fprintln(&buf, "DNS off")
|
||||
}
|
||||
if proxy.withIPAM {
|
||||
fmt.Fprintln(&buf, "IPAM on")
|
||||
} else {
|
||||
fmt.Fprintln(&buf, "IPAM off")
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func (proxy *Proxy) ListenAndServe() error {
|
||||
return (&http.Server{
|
||||
Addr: proxy.listenAddr,
|
||||
Handler: proxy,
|
||||
}).ListenAndServe()
|
||||
}
|
||||
Reference in new issue
Block a user