Rename strategy to driver
Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
This commit is contained in:
parent
0d29ca540f
commit
8ebeb1da5c
4 changed files with 28 additions and 31 deletions
|
@ -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 {
|
||||
|
|
19
libnetwork/drivers.go
Normal file
19
libnetwork/drivers.go
Normal 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
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in a new issue