diff --git a/libnetwork/bridge/bridge.go b/libnetwork/bridge/bridge.go index bd6a96090b..d5f380f8b6 100644 --- a/libnetwork/bridge/bridge.go +++ b/libnetwork/bridge/bridge.go @@ -1,10 +1,6 @@ package bridge -import ( - "net" - - "github.com/docker/libnetwork" -) +import "github.com/docker/libnetwork" const networkType = "bridgednetwork" @@ -12,20 +8,15 @@ func init() { libnetwork.RegisterNetworkType(networkType, Create) } -func Create(options libnetwork.strategyParams) libnetwork.Network { - return &bridgeNetwork{} -} - -type Configuration struct { - Subnet net.IPNet +func Create(options libnetwork.DriverParams) (libnetwork.Network, error) { + return &bridgeNetwork{}, nil } type bridgeNetwork struct { - Config Configuration } func (b *bridgeNetwork) Name() string { - return b.Id + return "" } func (b *bridgeNetwork) Type() string { diff --git a/libnetwork/drivers.go b/libnetwork/drivers.go new file mode 100644 index 0000000000..ca8845e3df --- /dev/null +++ b/libnetwork/drivers.go @@ -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 +} diff --git a/libnetwork/network.go b/libnetwork/network.go index 9cb64264df..5fc2797202 100644 --- a/libnetwork/network.go +++ b/libnetwork/network.go @@ -32,6 +32,9 @@ package libnetwork 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 { Name() string Type() string @@ -61,8 +64,8 @@ type Namespace interface { } // TODO Figure out the proper options type -func NewNetwork(networkType string, options strategyParams) (Network, error) { - if ctor, ok := strategies[networkType]; ok { +func NewNetwork(networkType string, options DriverParams) (Network, error) { + if ctor, ok := drivers[networkType]; ok { return ctor(options) } return nil, fmt.Errorf("Unknown network type %q", networkType) diff --git a/libnetwork/strategies.go b/libnetwork/strategies.go deleted file mode 100644 index 582c590dc9..0000000000 --- a/libnetwork/strategies.go +++ /dev/null @@ -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 -}