From 8e2c0df38de810689a6d88a742c94754afaf1221 Mon Sep 17 00:00:00 2001 From: Onur Filiz Date: Thu, 19 Jan 2017 16:29:55 -0800 Subject: [PATCH] Exposed address source start/stop APIs for CNI plugin --- ipam/manager.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ipam/manager.go b/ipam/manager.go index 54d0dcebc..d905fb824 100644 --- a/ipam/manager.go +++ b/ipam/manager.go @@ -33,7 +33,11 @@ type AddressManager interface { Initialize(config *common.PluginConfig, options map[string]interface{}) error Uninitialize() + StartSource(options map[string]interface{}) error + StopSource() + GetDefaultAddressSpaces() (string, string) + RequestPool(asId, poolId, subPoolId string, options map[string]string, v6 bool) (string, string, error) ReleasePool(asId, poolId string) error GetPoolInfo(asId, poolId string) (*AddressPoolInfo, error) @@ -77,14 +81,14 @@ func (am *addressManager) Initialize(config *common.PluginConfig, options map[st } // Start source. - err = am.startSource(options) + err = am.StartSource(options) return err } // Uninitialize cleans up address manager. func (am *addressManager) Uninitialize() { - am.stopSource() + am.StopSource() } // Restore reads address manager state from persistent store. @@ -149,7 +153,7 @@ func (am *addressManager) save() error { } // Starts configuration source. -func (am *addressManager) startSource(options map[string]interface{}) error { +func (am *addressManager) StartSource(options map[string]interface{}) error { var err error environment, _ := options[common.OptEnvironment].(string) @@ -172,14 +176,19 @@ func (am *addressManager) startSource(options map[string]interface{}) error { } if am.source != nil { + log.Printf("[ipam] Starting source %v.", environment) err = am.source.start(am) } + if err != nil { + log.Printf("[ipam] Failed to start source %v, err:%v.", environment, err) + } + return err } // Stops the configuration source. -func (am *addressManager) stopSource() { +func (am *addressManager) StopSource() { if am.source != nil { am.source.stop() am.source = nil