Skip to content

Commit

Permalink
add a option to disable initialization of specific driver
Browse files Browse the repository at this point in the history
Signed-off-by: mYmNeo <mymneo@163.com>
  • Loading branch information
mYmNeo committed Mar 1, 2016
1 parent 9994ce1 commit c32e6ac
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
24 changes: 17 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ type Config struct {

// DaemonCfg represents libnetwork core configuration
type DaemonCfg struct {
Debug bool
DataDir string
DefaultNetwork string
DefaultDriver string
Labels []string
DriverCfg map[string]interface{}
Debug bool
DataDir string
DefaultNetwork string
DefaultDriver string
Labels []string
DriverCfg map[string]interface{}
UnsupportedDriver map[string]interface{}
}

// ClusterCfg represents cluster configuration
Expand Down Expand Up @@ -66,7 +67,8 @@ func ParseConfig(tomlCfgFile string) (*Config, error) {
func ParseConfigOptions(cfgOptions ...Option) *Config {
cfg := &Config{
Daemon: DaemonCfg{
DriverCfg: make(map[string]interface{}),
DriverCfg: make(map[string]interface{}),
UnsupportedDriver: make(map[string]interface{}),
},
Scopes: make(map[string]*datastore.ScopeCfg),
}
Expand Down Expand Up @@ -241,3 +243,11 @@ func OptionLocalKVProviderConfig(config *store.Config) Option {
c.Scopes[datastore.LocalScope].Client.Config = config
}
}

// OptionUnsupportedDriver function returns an option setter for a unsupported driver
func OptionUnsupportedDriver(ud string) Option {
return func(c *Config) {
log.Debugf("Option UnsupportDriver: %s", ud)
c.Daemon.UnsupportedDriver[ud] = nil
}
}
6 changes: 4 additions & 2 deletions drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ type initializer struct {

func initDrivers(c *controller) error {
for _, i := range getInitializers() {
if err := i.fn(c, makeDriverConfig(c, i.ntype)); err != nil {
return err
if _, ok := c.cfg.Daemon.UnsupportedDriver[i.ntype]; !ok {
if err := i.fn(c, makeDriverConfig(c, i.ntype)); err != nil {
return err
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions libnetwork_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"testing"

"github.com/docker/libnetwork/config"
"github.com/docker/libnetwork/datastore"
"github.com/docker/libnetwork/discoverapi"
"github.com/docker/libnetwork/driverapi"
Expand Down Expand Up @@ -455,3 +456,15 @@ func (b *badDriver) DiscoverDelete(dType discoverapi.DiscoveryType, data interfa
func (b *badDriver) Type() string {
return badDriverName
}

func TestUnsupportedDriver(t *testing.T) {
bridgeNetType := "bridge"
c, err := New(config.OptionUnsupportedDriver("bridge"))
if err != nil {
t.Fatal(err)
}
defer c.Stop()
if _, err := c.(*controller).NewNetwork(bridgeNetType, "dummy"); err == nil {
t.Fatalf("Expecting the NewNetwork to faild for %s", bridgeNetType)
}
}

0 comments on commit c32e6ac

Please sign in to comment.