Support driver labels

Add support for in-tree driver configuration labels
by pushing the labels which has the appropriate
prefix to the corresponding driver.

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
Jana Radhakrishnan 2015-06-15 19:09:59 -07:00
parent ec68d342d1
commit 421ef35df2
1 changed files with 64 additions and 35 deletions

View File

@ -47,6 +47,7 @@ package libnetwork
import (
"fmt"
"net"
"strings"
"sync"
log "github.com/Sirupsen/logrus"
@ -56,6 +57,7 @@ import (
"github.com/docker/libnetwork/datastore"
"github.com/docker/libnetwork/driverapi"
"github.com/docker/libnetwork/hostdiscovery"
"github.com/docker/libnetwork/netlabel"
"github.com/docker/libnetwork/sandbox"
"github.com/docker/libnetwork/types"
)
@ -187,14 +189,41 @@ func (c *controller) ConfigureNetworkDriver(networkType string, options map[stri
func (c *controller) RegisterDriver(networkType string, driver driverapi.Driver, capability driverapi.Capability) error {
c.Lock()
defer c.Unlock()
if !config.IsValidName(networkType) {
c.Unlock()
return ErrInvalidName(networkType)
}
if _, ok := c.drivers[networkType]; ok {
c.Unlock()
return driverapi.ErrActiveRegistration(networkType)
}
c.drivers[networkType] = &driverData{driver, capability}
if c.cfg == nil {
c.Unlock()
return nil
}
opt := make(map[string]interface{})
for _, label := range c.cfg.Daemon.Labels {
if strings.HasPrefix(label, netlabel.DriverPrefix+"."+networkType) {
opt[netlabel.Key(label)] = netlabel.Value(label)
}
}
if capability.Scope == driverapi.GlobalScope {
opt[netlabel.KVProvider] = c.cfg.Datastore.Client.Provider
opt[netlabel.KVProviderURL] = c.cfg.Datastore.Client.Address
}
c.Unlock()
if len(opt) != 0 {
if err := driver.Config(opt); err != nil {
return err
}
}
return nil
}