1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Rename strategy to driver

Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
This commit is contained in:
Arnaud Porterie 2015-02-19 17:37:53 -08:00
parent 0d29ca540f
commit 8ebeb1da5c
4 changed files with 28 additions and 31 deletions

View file

@ -1,10 +1,6 @@
package bridge package bridge
import ( import "github.com/docker/libnetwork"
"net"
"github.com/docker/libnetwork"
)
const networkType = "bridgednetwork" const networkType = "bridgednetwork"
@ -12,20 +8,15 @@ func init() {
libnetwork.RegisterNetworkType(networkType, Create) libnetwork.RegisterNetworkType(networkType, Create)
} }
func Create(options libnetwork.strategyParams) libnetwork.Network { func Create(options libnetwork.DriverParams) (libnetwork.Network, error) {
return &bridgeNetwork{} return &bridgeNetwork{}, nil
}
type Configuration struct {
Subnet net.IPNet
} }
type bridgeNetwork struct { type bridgeNetwork struct {
Config Configuration
} }
func (b *bridgeNetwork) Name() string { func (b *bridgeNetwork) Name() string {
return b.Id return ""
} }
func (b *bridgeNetwork) Type() string { func (b *bridgeNetwork) Type() string {

19
libnetwork/drivers.go Normal file
View file

@ -0,0 +1,19 @@
package libnetwork
import "fmt"
type DriverParams map[string]interface{}
type DriverConstructor func(DriverParams) (Network, error)
var drivers = map[string]DriverConstructor{}
// RegisterNetworkType associates a textual identifier with a way to create a
// new network. It is called by the various network implementations, and used
// upon invokation of the libnetwork.NetNetwork function.
func RegisterNetworkType(name string, ctor DriverConstructor) error {
if _, ok := drivers[name]; ok {
return fmt.Errorf("a driver for network type %q is already registed", name)
}
drivers[name] = ctor
return nil
}

View file

@ -32,6 +32,9 @@ package libnetwork
import "fmt" import "fmt"
// A Network represents a logical connectivity zone that containers may
// ulteriorly join using the Link method. A Network is managed by a specific
// driver.
type Network interface { type Network interface {
Name() string Name() string
Type() string Type() string
@ -61,8 +64,8 @@ type Namespace interface {
} }
// TODO Figure out the proper options type // TODO Figure out the proper options type
func NewNetwork(networkType string, options strategyParams) (Network, error) { func NewNetwork(networkType string, options DriverParams) (Network, error) {
if ctor, ok := strategies[networkType]; ok { if ctor, ok := drivers[networkType]; ok {
return ctor(options) return ctor(options)
} }
return nil, fmt.Errorf("Unknown network type %q", networkType) return nil, fmt.Errorf("Unknown network type %q", networkType)

View file

@ -1,16 +0,0 @@
package libnetwork
import "fmt"
type strategyParams map[string]interface{}
type strategyConstructor func(strategyParams) (Network, error)
var strategies = map[string]strategyConstructor{}
func RegisterNetworkType(name string, ctor strategyConstructor) error {
if _, ok := strategies[name]; ok {
return fmt.Errorf("network type %q is already registed", name)
}
strategies[name] = ctor
return nil
}