Browse code

Add Handle method to plugingetter.

This is necessary for IPAM and network plugins.

Signed-off-by: Anusha Ragunathan <anusha@docker.com>

Anusha Ragunathan authored on 2016/09/27 03:06:26
Showing 3 changed files
... ...
@@ -22,4 +22,5 @@ type CompatPlugin interface {
22 22
 type PluginGetter interface {
23 23
 	Get(name, capability string, mode int) (CompatPlugin, error)
24 24
 	GetAllByCap(capability string) ([]CompatPlugin, error)
25
+	Handle(capability string, callback func(string, *plugins.Client))
25 26
 }
... ...
@@ -24,3 +24,10 @@ func (ps Store) GetAllByCap(capability string) ([]getter.CompatPlugin, error) {
24 24
 func (ps Store) Get(name, capability string, _ int) (getter.CompatPlugin, error) {
25 25
 	return plugins.Get(name, capability)
26 26
 }
27
+
28
+// Handle sets a callback for a given capability. It is only used by network
29
+// and ipam drivers during plugin registration. The callback registers the
30
+// driver with the subsystem (network, ipam).
31
+func (ps *Store) Handle(capability string, callback func(string, *plugins.Client)) {
32
+	plugins.Handle(capability, callback)
33
+}
... ...
@@ -208,15 +208,13 @@ func (ps *Store) GetAllByCap(capability string) ([]getter.CompatPlugin, error) {
208 208
 // Handle sets a callback for a given capability. It is only used by network
209 209
 // and ipam drivers during plugin registration. The callback registers the
210 210
 // driver with the subsystem (network, ipam).
211
-func (ps Store) Handle(capability string, callback func(string, *plugins.Client)) {
211
+func (ps *Store) Handle(capability string, callback func(string, *plugins.Client)) {
212 212
 	pluginType := fmt.Sprintf("docker.%s/1", strings.ToLower(capability))
213 213
 
214
-	store := &ps
215
-
216 214
 	// Register callback with new plugin model.
217
-	store.Lock()
218
-	store.handlers[pluginType] = callback
219
-	store.Unlock()
215
+	ps.Lock()
216
+	ps.handlers[pluginType] = callback
217
+	ps.Unlock()
220 218
 
221 219
 	// Register callback with legacy plugin model.
222 220
 	if allowV1PluginsFallback {