refactor: make proxy use weave/api

and extend that api as required, namely with DNSDomain()
This commit is contained in:
Matthias Radestock committed 2016-02-02 20:45:30 +00:00
1 parent 34ab86124b
commit feee4f0494
2 files changed
+9 -15

No files matched your search

+4
View File
@@ -5,6 +5,10 @@ import (
"net/url" "net/url"
) )
func (client *Client) DNSDomain() (string, error) {
return client.httpVerb("GET", "/domain", nil)
}
func (client *Client) RegisterWithDNS(ID string, fqdn string, ip string) error { func (client *Client) RegisterWithDNS(ID string, fqdn string, ip string) error {
data := url.Values{} data := url.Values{}
data.Add("fqdn", fqdn) data.Add("fqdn", fqdn)
+5 -15
View File
@@ -5,7 +5,6 @@ import (
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"os" "os"
@@ -17,6 +16,7 @@ import (
"time" "time"
docker "github.com/fsouza/go-dockerclient" docker "github.com/fsouza/go-dockerclient"
weaveapi "github.com/weaveworks/weave/api"
. "github.com/weaveworks/weave/common" . "github.com/weaveworks/weave/common"
weavedocker "github.com/weaveworks/weave/common/docker" weavedocker "github.com/weaveworks/weave/common/docker"
) )
@@ -555,7 +555,7 @@ func (proxy *Proxy) setWeaveDNS(hostConfig jsonObject, hostname, dnsDomain strin
return nil return nil
} }
func (proxy *Proxy) getDNSDomain() (domain string) { func (proxy *Proxy) getDNSDomain() string {
if proxy.WithoutDNS { if proxy.WithoutDNS {
return "" return ""
} }
@@ -569,19 +569,9 @@ func (proxy *Proxy) getDNSDomain() (domain string) {
weaveIP = "127.0.0.1" weaveIP = "127.0.0.1"
} }
url := fmt.Sprintf("http://%s:6784/domain", weaveIP) weave := weaveapi.NewClient(weaveIP)
resp, err := http.Get(url) domain, _ := weave.DNSDomain()
if err != nil || resp.StatusCode != http.StatusOK { return domain
return
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
return string(b)
} }
func (proxy *Proxy) updateContainerNetworkSettings(container jsonObject) error { func (proxy *Proxy) updateContainerNetworkSettings(container jsonObject) error {