github.com/rawahars/moby@v24.0.4+incompatible/libnetwork/drvregistry/drvregistry.go (about) 1 package drvregistry 2 3 import ( 4 "fmt" 5 6 "github.com/docker/docker/libnetwork/driverapi" 7 "github.com/docker/docker/libnetwork/ipamapi" 8 "github.com/docker/docker/pkg/plugingetter" 9 ) 10 11 // DrvRegistry holds the registry of all network drivers and IPAM drivers that it knows about. 12 type DrvRegistry struct { 13 Networks 14 IPAMs 15 pluginGetter plugingetter.PluginGetter 16 } 17 18 var _ driverapi.DriverCallback = (*DrvRegistry)(nil) 19 var _ ipamapi.Callback = (*DrvRegistry)(nil) 20 21 // InitFunc defines the driver initialization function signature. 22 type InitFunc func(driverapi.DriverCallback, map[string]interface{}) error 23 24 // Placeholder is a type for function arguments which need to be present for Swarmkit 25 // to compile, but for which the only acceptable value is nil. 26 type Placeholder *struct{} 27 28 // New returns a new legacy driver registry. 29 // 30 // Deprecated: use the separate [Networks] and [IPAMs] registries. 31 func New(lDs, gDs Placeholder, dfn DriverNotifyFunc, ifn Placeholder, pg plugingetter.PluginGetter) (*DrvRegistry, error) { 32 return &DrvRegistry{ 33 Networks: Networks{Notify: dfn}, 34 pluginGetter: pg, 35 }, nil 36 } 37 38 // AddDriver adds a network driver to the registry. 39 // 40 // Deprecated: call fn(r, config) directly. 41 func (r *DrvRegistry) AddDriver(_ string, fn InitFunc, config map[string]interface{}) error { 42 return fn(r, config) 43 } 44 45 // IPAMDefaultAddressSpaces returns the default address space strings for the passed IPAM driver name. 46 // 47 // Deprecated: call GetDefaultAddressSpaces() on the IPAM driver. 48 func (r *DrvRegistry) IPAMDefaultAddressSpaces(name string) (string, string, error) { 49 d, _ := r.IPAM(name) 50 51 if d == nil { 52 return "", "", fmt.Errorf("ipam %s not found", name) 53 } 54 55 return d.GetDefaultAddressSpaces() 56 } 57 58 // GetPluginGetter returns the plugingetter 59 func (r *DrvRegistry) GetPluginGetter() plugingetter.PluginGetter { 60 return r.pluginGetter 61 } 62 63 // Driver returns the network driver instance registered under name, and its capability. 64 func (r *DrvRegistry) Driver(name string) (driverapi.Driver, *driverapi.Capability) { 65 d, c := r.Networks.Driver(name) 66 67 if c == (driverapi.Capability{}) { 68 return d, nil 69 } 70 return d, &c 71 }