Extract 'api' package
This commit is contained in:
1 parent
bd2b8df7c5
commit
e101dde62e
7 files changed
+139
-149
No files matched your search
+18
-4
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
weaveapi "github.com/weaveworks/weave/api"
|
||||
. "github.com/weaveworks/weave/common"
|
||||
"github.com/weaveworks/weave/common/docker"
|
||||
)
|
||||
@@ -14,6 +15,7 @@ const (
|
||||
|
||||
type watcher struct {
|
||||
dockerer
|
||||
weave *weaveapi.Client
|
||||
}
|
||||
|
||||
type Watcher interface {
|
||||
@@ -33,6 +35,18 @@ func NewWatcher(client *docker.Client) (Watcher, error) {
|
||||
return w, nil
|
||||
}
|
||||
|
||||
func (w *watcher) haveWeaveClient() bool {
|
||||
if w.weave == nil {
|
||||
dnsip, err := w.client.GetContainerBridgeIP(WeaveContainer)
|
||||
if err != nil {
|
||||
Log.Warningf("nameserver not available: %s", err)
|
||||
return false
|
||||
}
|
||||
w.weave = weaveapi.NewClient(dnsip)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *watcher) ContainerStarted(id string) {
|
||||
Log.Debugf("Container started %s", id)
|
||||
info, err := w.client.InspectContainer(id)
|
||||
@@ -41,11 +55,11 @@ func (w *watcher) ContainerStarted(id string) {
|
||||
return
|
||||
}
|
||||
// FIXME: check that it's on our network; but, the docker client lib doesn't know about .NetworkID
|
||||
if isSubdomain(info.Config.Domainname, WeaveDomain) {
|
||||
if isSubdomain(info.Config.Domainname, WeaveDomain) && w.haveWeaveClient() {
|
||||
// one of ours
|
||||
ip := info.NetworkSettings.IPAddress
|
||||
fqdn := fmt.Sprintf("%s.%s", info.Config.Hostname, info.Config.Domainname)
|
||||
if err := w.registerWithDNS(id, fqdn, ip); err != nil {
|
||||
if err := w.weave.RegisterWithDNS(id, fqdn, ip); err != nil {
|
||||
Log.Warningf("unable to register with weaveDNS: %s", err)
|
||||
}
|
||||
}
|
||||
@@ -58,9 +72,9 @@ func (w *watcher) ContainerDied(id string) {
|
||||
Log.Warningf("error inspecting container: %s", err)
|
||||
return
|
||||
}
|
||||
if isSubdomain(info.Config.Domainname, WeaveDomain) {
|
||||
if isSubdomain(info.Config.Domainname, WeaveDomain) && w.haveWeaveClient() {
|
||||
ip := info.NetworkSettings.IPAddress
|
||||
if err := w.deregisterWithDNS(id, ip); err != nil {
|
||||
if err := w.weave.DeregisterWithDNS(id, ip); err != nil {
|
||||
Log.Warningf("unable to deregister with weaveDNS: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user