Skip to content

Commit

Permalink
refactor: make proxy use weave/api
Browse files Browse the repository at this point in the history
and extend that api as required, namely with DNSDomain()
  • Loading branch information
rade committed Feb 2, 2016
1 parent 34ab861 commit feee4f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
4 changes: 4 additions & 0 deletions api/dns.go
Expand Up @@ -5,6 +5,10 @@ import (
"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 {
data := url.Values{}
data.Add("fqdn", fqdn)
Expand Down
20 changes: 5 additions & 15 deletions proxy/proxy.go
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/tls"
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
Expand All @@ -17,6 +16,7 @@ import (
"time"

docker "github.com/fsouza/go-dockerclient"
weaveapi "github.com/weaveworks/weave/api"
. "github.com/weaveworks/weave/common"
weavedocker "github.com/weaveworks/weave/common/docker"
)
Expand Down Expand Up @@ -555,7 +555,7 @@ func (proxy *Proxy) setWeaveDNS(hostConfig jsonObject, hostname, dnsDomain strin
return nil
}

func (proxy *Proxy) getDNSDomain() (domain string) {
func (proxy *Proxy) getDNSDomain() string {
if proxy.WithoutDNS {
return ""
}
Expand All @@ -569,19 +569,9 @@ func (proxy *Proxy) getDNSDomain() (domain string) {
weaveIP = "127.0.0.1"
}

url := fmt.Sprintf("http://%s:6784/domain", weaveIP)
resp, err := http.Get(url)
if err != nil || resp.StatusCode != http.StatusOK {
return
}
defer resp.Body.Close()

b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}

return string(b)
weave := weaveapi.NewClient(weaveIP)
domain, _ := weave.DNSDomain()
return domain
}

func (proxy *Proxy) updateContainerNetworkSettings(container jsonObject) error {
Expand Down

0 comments on commit feee4f0

Please sign in to comment.