From 1b28c5e01d1cab44672899382ea145878490e796 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 --- libnetwork/controller.go | 24 +++++++++++++++---- libnetwork/driverapi/driverapi.go | 3 +++ libnetwork/drivers/bridge/bridge.go | 4 ++++ libnetwork/drivers/host/host.go | 4 ++++ libnetwork/drivers/ipvlan/ipvlan.go | 4 ++++ libnetwork/drivers/macvlan/macvlan.go | 4 ++++ libnetwork/drivers/null/null.go | 4 ++++ libnetwork/drivers/overlay/overlay.go | 4 ++++ .../drivers/overlay/ovmanager/ovmanager.go | 4 ++++ libnetwork/drivers/remote/driver.go | 4 ++++ libnetwork/drivers/solaris/bridge/bridge.go | 4 ++++ libnetwork/drivers/solaris/overlay/overlay.go | 4 ++++ .../solaris/overlay/ovmanager/ovmanager.go | 4 ++++ .../windows/overlay/overlay_windows.go | 4 ++++ libnetwork/drivers/windows/windows.go | 4 ++++ libnetwork/ipam/allocator.go | 5 ++++ libnetwork/ipamapi/contract.go | 3 +++ libnetwork/ipams/null/null.go | 4 ++++ libnetwork/ipams/remote/remote.go | 4 ++++ libnetwork/ipams/windowsipam/windowsipam.go | 4 ++++ libnetwork/libnetwork_internal_test.go | 3 +++ 21 files changed, 97 insertions(+), 5 deletions(-) diff --git a/libnetwork/controller.go b/libnetwork/controller.go index b551230baf..aa92b88f6b 100644 --- a/libnetwork/controller.go +++ b/libnetwork/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/libnetwork/driverapi/driverapi.go b/libnetwork/driverapi/driverapi.go index 98bc60ac9d..6e66ea221e 100644 --- a/libnetwork/driverapi/driverapi.go +++ b/libnetwork/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/libnetwork/drivers/bridge/bridge.go b/libnetwork/drivers/bridge/bridge.go index f6cbe07783..ec999731cd 100644 --- a/libnetwork/drivers/bridge/bridge.go +++ b/libnetwork/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/libnetwork/drivers/host/host.go b/libnetwork/drivers/host/host.go index bec64465a0..3bc9099761 100644 --- a/libnetwork/drivers/host/host.go +++ b/libnetwork/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/libnetwork/drivers/ipvlan/ipvlan.go b/libnetwork/drivers/ipvlan/ipvlan.go index aacea3df80..cd0c830f79 100644 --- a/libnetwork/drivers/ipvlan/ipvlan.go +++ b/libnetwork/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/libnetwork/drivers/macvlan/macvlan.go b/libnetwork/drivers/macvlan/macvlan.go index b89b4b7845..23fa850edc 100644 --- a/libnetwork/drivers/macvlan/macvlan.go +++ b/libnetwork/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/libnetwork/drivers/null/null.go b/libnetwork/drivers/null/null.go index a137b000fa..03f9777040 100644 --- a/libnetwork/drivers/null/null.go +++ b/libnetwork/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/libnetwork/drivers/overlay/overlay.go b/libnetwork/drivers/overlay/overlay.go index e3c1f7b899..7f20840db2 100644 --- a/libnetwork/drivers/overlay/overlay.go +++ b/libnetwork/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/libnetwork/drivers/overlay/ovmanager/ovmanager.go b/libnetwork/drivers/overlay/ovmanager/ovmanager.go index aaf94e586f..2c4c771e58 100644 --- a/libnetwork/drivers/overlay/ovmanager/ovmanager.go +++ b/libnetwork/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/libnetwork/drivers/remote/driver.go b/libnetwork/drivers/remote/driver.go index 209a28be52..12a8fb0cdb 100644 --- a/libnetwork/drivers/remote/driver.go +++ b/libnetwork/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/libnetwork/drivers/solaris/bridge/bridge.go b/libnetwork/drivers/solaris/bridge/bridge.go index 97180fbbd3..53092efeeb 100644 --- a/libnetwork/drivers/solaris/bridge/bridge.go +++ b/libnetwork/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/libnetwork/drivers/solaris/overlay/overlay.go b/libnetwork/drivers/solaris/overlay/overlay.go index b48cfe7e76..b001f58af7 100644 --- a/libnetwork/drivers/solaris/overlay/overlay.go +++ b/libnetwork/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/libnetwork/drivers/solaris/overlay/ovmanager/ovmanager.go b/libnetwork/drivers/solaris/overlay/ovmanager/ovmanager.go index 78a586e08e..a756990acb 100644 --- a/libnetwork/drivers/solaris/overlay/ovmanager/ovmanager.go +++ b/libnetwork/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/libnetwork/drivers/windows/overlay/overlay_windows.go b/libnetwork/drivers/windows/overlay/overlay_windows.go index 7ebc16eebd..c3028d7636 100644 --- a/libnetwork/drivers/windows/overlay/overlay_windows.go +++ b/libnetwork/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/libnetwork/drivers/windows/windows.go b/libnetwork/drivers/windows/windows.go index 7ce7fa8f81..b054898afe 100644 --- a/libnetwork/drivers/windows/windows.go +++ b/libnetwork/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/libnetwork/ipam/allocator.go b/libnetwork/ipam/allocator.go index bd00a14700..4243d57a74 100644 --- a/libnetwork/ipam/allocator.go +++ b/libnetwork/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/libnetwork/ipamapi/contract.go b/libnetwork/ipamapi/contract.go index 090205e11f..7f967863d8 100644 --- a/libnetwork/ipamapi/contract.go +++ b/libnetwork/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/libnetwork/ipams/null/null.go b/libnetwork/ipams/null/null.go index 60119a36ab..339b5308d1 100644 --- a/libnetwork/ipams/null/null.go +++ b/libnetwork/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/libnetwork/ipams/remote/remote.go b/libnetwork/ipams/remote/remote.go index ecaf10c2f1..3da05260e6 100644 --- a/libnetwork/ipams/remote/remote.go +++ b/libnetwork/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/libnetwork/ipams/windowsipam/windowsipam.go b/libnetwork/ipams/windowsipam/windowsipam.go index 1b9cd5a983..6b124d40d2 100644 --- a/libnetwork/ipams/windowsipam/windowsipam.go +++ b/libnetwork/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/libnetwork_internal_test.go b/libnetwork/libnetwork_internal_test.go index e4e90151f5..9d4d562d0d 100644 --- a/libnetwork/libnetwork_internal_test.go +++ b/libnetwork/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 }