diff --git a/plugin/status.go b/plugin/status.go new file mode 100644 index 00000000..fc44990b --- /dev/null +++ b/plugin/status.go @@ -0,0 +1,19 @@ +package plugin + +type Status struct { + DriverName string + MeshDriverName string `json:"MeshDriverName,omitempty"` + Version int +} + +func NewStatus(address, meshAddress string, isPluginV2 bool) *Status { + status := &Status{ + DriverName: pluginNameFromAddress(address), + MeshDriverName: pluginNameFromAddress(meshAddress), + Version: 1, + } + if isPluginV2 { + status.Version = 2 + } + return status +} diff --git a/prog/weaver/http.go b/prog/weaver/http.go index f18ac745..57197e13 100644 --- a/prog/weaver/http.go +++ b/prog/weaver/http.go @@ -17,6 +17,8 @@ import ( "github.com/weaveworks/weave/ipam" "github.com/weaveworks/weave/nameserver" "github.com/weaveworks/weave/net/address" + "github.com/weaveworks/weave/plugin" + "github.com/weaveworks/weave/proxy" weave "github.com/weaveworks/weave/router" ) @@ -203,6 +205,18 @@ var statusTemplate = defTemplate("status", `\ TTL: {{.DNS.TTL}} Entries: {{countDNSEntries .DNS.Entries}} {{end}}\ +{{if .Proxy}}\ + + Service: proxy + Address: {{printList .Proxy.Addresses}} +{{end}}\ +{{if .Plugin}}\ + + Service: plugin (v{{.Plugin.Version}}) +{{if eq .Plugin.Version 1}}\ + DriverName: {{.Plugin.DriverName}} +{{end}}\ +{{end}}\ `) var targetsTemplate = defTemplate("targetsTemplate", `\ @@ -280,10 +294,12 @@ type WeaveStatus struct { Router *weave.NetworkRouterStatus `json:"Router,omitempty"` IPAM *ipam.Status `json:"IPAM,omitempty"` DNS *nameserver.Status `json:"DNS,omitempty"` + Proxy *proxy.Status `json:"Proxy,omitempty"` + Plugin *plugin.Status `json:"Plugin,omitempty"` } // Read-only functions, suitable for exposing on an unprotected socket -func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRouter, allocator *ipam.Allocator, defaultSubnet address.CIDR, ns *nameserver.Nameserver, dnsserver *nameserver.DNSServer, waitReady *common.WaitGroup) { +func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRouter, allocator *ipam.Allocator, defaultSubnet address.CIDR, ns *nameserver.Nameserver, dnsserver *nameserver.DNSServer, prxy *proxy.Proxy, pluginStatus *plugin.Status, waitReady *common.WaitGroup) { status := func() WeaveStatus { return WeaveStatus{ waitReady.IsDone(), @@ -291,7 +307,10 @@ func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRout versionCheck(), weave.NewNetworkRouterStatus(router), ipam.NewStatus(allocator, defaultSubnet), - nameserver.NewStatus(ns, dnsserver)} + nameserver.NewStatus(ns, dnsserver), + proxy.NewStatus(prxy), + pluginStatus, + } } muxRouter.Methods("GET").Path("/report").Headers("Accept", "application/json").HandlerFunc( func(w http.ResponseWriter, r *http.Request) { diff --git a/prog/weaver/main.go b/prog/weaver/main.go index 7e7d5dcf..2a01c6f0 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -427,6 +427,12 @@ func main() { } checkFatal(router.CreateRestartSentinel()) + // Slightly ugly that plugin status is separated from the plugin.Start call + var pluginStatus *plugin.Status + if enablePlugin || enablePluginV2 { + pluginStatus = plugin.NewStatus(pluginSocket, pluginMeshSocket, enablePluginV2) + } + // The weave script always waits for a status call to succeed, // so there is no point in doing "weave launch --http-addr ''". // This is here to support stand-alone use of weaver. @@ -439,7 +445,7 @@ func main() { ns.HandleHTTP(muxRouter, dockerCli) } router.HandleHTTP(muxRouter) - HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, &waitReady) + HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, proxy, pluginStatus, &waitReady) HandleHTTPPeer(muxRouter, allocator, discoveryEndpoint, token, name.String()) muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver)) if proxy != nil { @@ -452,7 +458,7 @@ func main() { if statusAddr != "" { muxRouter := mux.NewRouter() - HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, &waitReady) + HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, proxy, pluginStatus, &waitReady) muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver)) statusMux := http.NewServeMux() statusMux.Handle("/", muxRouter) diff --git a/proxy/status.go b/proxy/status.go new file mode 100644 index 00000000..802ed88c --- /dev/null +++ b/proxy/status.go @@ -0,0 +1,15 @@ +package proxy + +type Status struct { + Addresses []string +} + +func NewStatus(proxy *Proxy) *Status { + if proxy == nil { + return nil + } + status := &Status{ + Addresses: proxy.normalisedAddrs, + } + return status +} diff --git a/weave b/weave index 6bdc4459..8e955fe9 100755 --- a/weave +++ b/weave @@ -1456,20 +1456,6 @@ case "$COMMAND" in echo "Invalid 'weave status' sub-command: $SUB_COMMAND" >&2 usage fi - if [ -z "$SUB_STATUS" ] && PROXY_ADDRS=$(proxy_addrs 2>/dev/null) ; then - echo - echo " Service: proxy" - echo " Address: $PROXY_ADDRS" - fi - if [ -z "$SUB_STATUS" ] && is_plugin_v1_enabled ; then - echo - echo " Service: plugin (v1)" - echo " DriverName: weave" - elif [ -z "$SUB_STATUS" ] && PLUGIN_FULL_NAME=$(is_plugin_v2_enabled) ; then - echo - echo " Service: plugin (v2)" - echo " DriverName: $PLUGIN_FULL_NAME" - fi [ -n "$SUB_STATUS" ] || echo [ $res -eq 0 ] ;;