From fb8744be86f04056bd88ea3f1638fe0f56f208a9 Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Sun, 18 Dec 2016 19:56:34 -0800 Subject: [PATCH] Internal interface to differentiate built-in drivers from remote Signed-off-by: Madhu Venugopal --- controller.go | 24 +++++++++++++++---- driverapi/driverapi.go | 3 +++ drivers/bridge/bridge.go | 4 ++++ drivers/host/host.go | 4 ++++ drivers/ipvlan/ipvlan.go | 4 ++++ drivers/macvlan/macvlan.go | 4 ++++ drivers/null/null.go | 4 ++++ drivers/overlay/overlay.go | 4 ++++ drivers/overlay/ovmanager/ovmanager.go | 4 ++++ drivers/remote/driver.go | 4 ++++ drivers/solaris/bridge/bridge.go | 4 ++++ drivers/solaris/overlay/overlay.go | 4 ++++ .../solaris/overlay/ovmanager/ovmanager.go | 4 ++++ drivers/windows/overlay/overlay_windows.go | 4 ++++ drivers/windows/windows.go | 4 ++++ ipam/allocator.go | 5 ++++ ipamapi/contract.go | 3 +++ ipams/null/null.go | 4 ++++ ipams/remote/remote.go | 4 ++++ ipams/windowsipam/windowsipam.go | 4 ++++ libnetwork_internal_test.go | 3 +++ 21 files changed, 97 insertions(+), 5 deletions(-) diff --git a/controller.go b/controller.go index b551230b..aa92b88f 100644 --- a/controller.go +++ b/controller.go @@ -79,6 +79,9 @@ type NetworkController interface { // BuiltinDrivers returns list of builtin drivers BuiltinDrivers() []string + // BuiltinIPAMDrivers returns list of builtin ipam drivers + BuiltinIPAMDrivers() []string + // Config method returns the bootup configuration for the controller Config() config.Config @@ -476,12 +479,23 @@ func (c *controller) ID() string { func (c *controller) BuiltinDrivers() []string { drivers := []string{} - for _, i := range getInitializers(c.cfg.Daemon.Experimental) { - if i.ntype == "remote" { - continue + c.drvRegistry.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool { + if driver.IsBuiltIn() { + drivers = append(drivers, name) } - drivers = append(drivers, i.ntype) - } + return false + }) + return drivers +} + +func (c *controller) BuiltinIPAMDrivers() []string { + drivers := []string{} + c.drvRegistry.WalkIPAMs(func(name string, driver ipamapi.Ipam, cap *ipamapi.Capability) bool { + if driver.IsBuiltIn() { + drivers = append(drivers, name) + } + return false + }) return drivers } diff --git a/driverapi/driverapi.go b/driverapi/driverapi.go index 98bc60ac..6e66ea22 100644 --- a/driverapi/driverapi.go +++ b/driverapi/driverapi.go @@ -74,6 +74,9 @@ type Driver interface { // Type returns the the type of this driver, the network type this driver manages Type() string + + // IsBuiltIn returns true if it is a built-in driver + IsBuiltIn() bool } // NetworkInfo provides a go interface for drivers to provide network diff --git a/drivers/bridge/bridge.go b/drivers/bridge/bridge.go index f6cbe077..ec999731 100644 --- a/drivers/bridge/bridge.go +++ b/drivers/bridge/bridge.go @@ -1424,6 +1424,10 @@ func (d *driver) Type() string { return networkType } +func (d *driver) IsBuiltIn() bool { + return true +} + // DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error { return nil diff --git a/drivers/host/host.go b/drivers/host/host.go index bec64465..3bc90997 100644 --- a/drivers/host/host.go +++ b/drivers/host/host.go @@ -86,6 +86,10 @@ func (d *driver) Type() string { return networkType } +func (d *driver) IsBuiltIn() bool { + return true +} + // DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error { return nil diff --git a/drivers/ipvlan/ipvlan.go b/drivers/ipvlan/ipvlan.go index aacea3df..cd0c830f 100644 --- a/drivers/ipvlan/ipvlan.go +++ b/drivers/ipvlan/ipvlan.go @@ -84,6 +84,10 @@ func (d *driver) Type() string { return ipvlanType } +func (d *driver) IsBuiltIn() bool { + return true +} + func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error { return nil } diff --git a/drivers/macvlan/macvlan.go b/drivers/macvlan/macvlan.go index b89b4b78..23fa850e 100644 --- a/drivers/macvlan/macvlan.go +++ b/drivers/macvlan/macvlan.go @@ -86,6 +86,10 @@ func (d *driver) Type() string { return macvlanType } +func (d *driver) IsBuiltIn() bool { + return true +} + func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error { return nil } diff --git a/drivers/null/null.go b/drivers/null/null.go index a137b000..03f97770 100644 --- a/drivers/null/null.go +++ b/drivers/null/null.go @@ -86,6 +86,10 @@ func (d *driver) Type() string { return networkType } +func (d *driver) IsBuiltIn() bool { + return true +} + // DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error { return nil diff --git a/drivers/overlay/overlay.go b/drivers/overlay/overlay.go index e3c1f7b8..7f20840d 100644 --- a/drivers/overlay/overlay.go +++ b/drivers/overlay/overlay.go @@ -211,6 +211,10 @@ func (d *driver) Type() string { return networkType } +func (d *driver) IsBuiltIn() bool { + return true +} + func validateSelf(node string) error { advIP := net.ParseIP(node) if advIP == nil { diff --git a/drivers/overlay/ovmanager/ovmanager.go b/drivers/overlay/ovmanager/ovmanager.go index aaf94e58..2c4c771e 100644 --- a/drivers/overlay/ovmanager/ovmanager.go +++ b/drivers/overlay/ovmanager/ovmanager.go @@ -229,6 +229,10 @@ func (d *driver) Type() string { return networkType } +func (d *driver) IsBuiltIn() bool { + return true +} + // DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error { return types.NotImplementedErrorf("not implemented") diff --git a/drivers/remote/driver.go b/drivers/remote/driver.go index 209a28be..12a8fb0c 100644 --- a/drivers/remote/driver.go +++ b/drivers/remote/driver.go @@ -312,6 +312,10 @@ func (d *driver) Type() string { return d.networkType } +func (d *driver) IsBuiltIn() bool { + return false +} + // DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error { if dType != discoverapi.NodeDiscovery { diff --git a/drivers/solaris/bridge/bridge.go b/drivers/solaris/bridge/bridge.go index 97180fbb..53092efe 100644 --- a/drivers/solaris/bridge/bridge.go +++ b/drivers/solaris/bridge/bridge.go @@ -916,6 +916,10 @@ func (d *driver) Type() string { return networkType } +func (d *driver) IsBuiltIn() bool { + return true +} + // DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error { return nil diff --git a/drivers/solaris/overlay/overlay.go b/drivers/solaris/overlay/overlay.go index b48cfe7e..b001f58a 100644 --- a/drivers/solaris/overlay/overlay.go +++ b/drivers/solaris/overlay/overlay.go @@ -200,6 +200,10 @@ func (d *driver) Type() string { return networkType } +func (d *driver) IsBuiltIn() bool { + return true +} + func validateSelf(node string) error { advIP := net.ParseIP(node) if advIP == nil { diff --git a/drivers/solaris/overlay/ovmanager/ovmanager.go b/drivers/solaris/overlay/ovmanager/ovmanager.go index 78a586e0..a756990a 100644 --- a/drivers/solaris/overlay/ovmanager/ovmanager.go +++ b/drivers/solaris/overlay/ovmanager/ovmanager.go @@ -229,6 +229,10 @@ func (d *driver) Type() string { return networkType } +func (d *driver) IsBuiltIn() bool { + return true +} + // DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error { return types.NotImplementedErrorf("not implemented") diff --git a/drivers/windows/overlay/overlay_windows.go b/drivers/windows/overlay/overlay_windows.go index 7ebc16ee..c3028d76 100644 --- a/drivers/windows/overlay/overlay_windows.go +++ b/drivers/windows/overlay/overlay_windows.go @@ -176,6 +176,10 @@ func (d *driver) Type() string { return networkType } +func (d *driver) IsBuiltIn() bool { + return true +} + func validateSelf(node string) error { advIP := net.ParseIP(node) if advIP == nil { diff --git a/drivers/windows/windows.go b/drivers/windows/windows.go index 7ce7fa8f..b054898a 100644 --- a/drivers/windows/windows.go +++ b/drivers/windows/windows.go @@ -698,6 +698,10 @@ func (d *driver) Type() string { return d.name } +func (d *driver) IsBuiltIn() bool { + return true +} + // DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error { return nil diff --git a/ipam/allocator.go b/ipam/allocator.go index bd00a147..4243d57a 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -594,3 +594,8 @@ func (a *Allocator) DumpDatabase() string { return s } + +// IsBuiltIn returns true for builtin drivers +func (a *Allocator) IsBuiltIn() bool { + return true +} diff --git a/ipamapi/contract.go b/ipamapi/contract.go index 090205e1..7f967863 100644 --- a/ipamapi/contract.go +++ b/ipamapi/contract.go @@ -80,6 +80,9 @@ type Ipam interface { RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error) // Release the address from the specified pool ID ReleaseAddress(string, net.IP) error + + //IsBuiltIn returns true if it is a built-in driver. + IsBuiltIn() bool } // Capability represents the requirements and capabilities of the IPAM driver diff --git a/ipams/null/null.go b/ipams/null/null.go index 60119a36..339b5308 100644 --- a/ipams/null/null.go +++ b/ipams/null/null.go @@ -65,6 +65,10 @@ func (a *allocator) DiscoverDelete(dType discoverapi.DiscoveryType, data interfa return nil } +func (a *allocator) IsBuiltIn() bool { + return true +} + // Init registers a remote ipam when its plugin is activated func Init(ic ipamapi.Callback, l, g interface{}) error { return ic.RegisterIpamDriver(ipamapi.NullIPAM, &allocator{}) diff --git a/ipams/remote/remote.go b/ipams/remote/remote.go index ecaf10c2..3da05260 100644 --- a/ipams/remote/remote.go +++ b/ipams/remote/remote.go @@ -149,3 +149,7 @@ func (a *allocator) DiscoverNew(dType discoverapi.DiscoveryType, data interface{ func (a *allocator) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error { return nil } + +func (a *allocator) IsBuiltIn() bool { + return false +} diff --git a/ipams/windowsipam/windowsipam.go b/ipams/windowsipam/windowsipam.go index 1b9cd5a9..6b124d40 100644 --- a/ipams/windowsipam/windowsipam.go +++ b/ipams/windowsipam/windowsipam.go @@ -101,3 +101,7 @@ func (a *allocator) DiscoverNew(dType discoverapi.DiscoveryType, data interface{ func (a *allocator) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error { return nil } + +func (a *allocator) IsBuiltIn() bool { + return true +} diff --git a/libnetwork_internal_test.go b/libnetwork_internal_test.go index e4e90151..9d4d562d 100644 --- a/libnetwork_internal_test.go +++ b/libnetwork_internal_test.go @@ -544,6 +544,9 @@ func (b *badDriver) DiscoverDelete(dType discoverapi.DiscoveryType, data interfa func (b *badDriver) Type() string { return badDriverName } +func (b *badDriver) IsBuiltIn() bool { + return false +} func (b *badDriver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error { return nil }