refactor(ish) of ipam plugin logging
prefix all log entries with "[ipam]" Also eliminate a dot import.
This commit is contained in:
1 parent
984cad5b58
commit
5aa2a7a14c
1 file changed
+18
-8
+18
-8
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/docker/libnetwork/discoverapi"
|
||||
"github.com/docker/libnetwork/netlabel"
|
||||
"github.com/weaveworks/weave/api"
|
||||
. "github.com/weaveworks/weave/common"
|
||||
"github.com/weaveworks/weave/common"
|
||||
)
|
||||
|
||||
type Ipam struct {
|
||||
@@ -20,13 +20,13 @@ func NewIpam(weave *api.Client) *Ipam {
|
||||
}
|
||||
|
||||
func (i *Ipam) GetDefaultAddressSpaces() (string, string, error) {
|
||||
Log.Debugln("GetDefaultAddressSpaces")
|
||||
i.logReq("GetDefaultAddressSpaces")
|
||||
return "weavelocal", "weaveglobal", nil
|
||||
}
|
||||
|
||||
func (i *Ipam) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (poolname string, subnet *net.IPNet, data map[string]string, err error) {
|
||||
Log.Debugln("RequestPool", addressSpace, pool, subPool, options)
|
||||
defer func() { Log.Debugln("RequestPool returning", poolname, subnet, data, err) }()
|
||||
i.logReq("RequestPool", addressSpace, pool, subPool, options)
|
||||
defer func() { i.logRes("RequestPool", poolname, subnet, data, err) }()
|
||||
if pool == "" {
|
||||
subnet, err = i.weave.DefaultSubnet()
|
||||
} else {
|
||||
@@ -50,13 +50,13 @@ func (i *Ipam) RequestPool(addressSpace, pool, subPool string, options map[strin
|
||||
}
|
||||
|
||||
func (i *Ipam) ReleasePool(poolID string) error {
|
||||
Log.Debugln("ReleasePool", poolID)
|
||||
i.logReq("ReleasePool", poolID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Ipam) RequestAddress(poolID string, address net.IP, options map[string]string) (ip *net.IPNet, _ map[string]string, err error) {
|
||||
Log.Debugln("RequestAddress", poolID, address, options)
|
||||
defer func() { Log.Debugln("allocateIP returned", ip, err) }()
|
||||
i.logReq("RequestAddress", poolID, address, options)
|
||||
defer func() { i.logRes("RequestAddress", ip, err) }()
|
||||
// If we pass magic string "_" to weave IPAM it stores the address under its own string
|
||||
if poolID == "weavepool" { // old-style
|
||||
ip, err = i.weave.AllocateIP("_")
|
||||
@@ -90,7 +90,7 @@ func (i *Ipam) RequestAddress(poolID string, address net.IP, options map[string]
|
||||
}
|
||||
|
||||
func (i *Ipam) ReleaseAddress(poolID string, address net.IP) error {
|
||||
Log.Debugln("ReleaseAddress", poolID, address)
|
||||
i.logReq("ReleaseAddress", poolID, address)
|
||||
return i.weave.ReleaseIPsFor(address.String())
|
||||
}
|
||||
|
||||
@@ -103,3 +103,13 @@ func (i *Ipam) DiscoverNew(discoverapi.DiscoveryType, interface{}) error {
|
||||
func (i *Ipam) DiscoverDelete(discoverapi.DiscoveryType, interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// logging
|
||||
|
||||
func (i *Ipam) logReq(fun string, args ...interface{}) {
|
||||
common.Log.Debugln(append([]interface{}{fmt.Sprintf("[ipam] %s", fun)}, args...)...)
|
||||
}
|
||||
|
||||
func (i *Ipam) logRes(fun string, args ...interface{}) {
|
||||
common.Log.Debugln(append([]interface{}{fmt.Sprintf("[ipam] %s result", fun)}, args...)...)
|
||||
}
|
||||
Reference in new issue
Block a user