Refactor network creation and initialization into strategies
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
cda4f27f57
commit
609c298810
7 changed files with 211 additions and 107 deletions
32
libcontainer/network/strategy.go
Normal file
32
libcontainer/network/strategy.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/dotcloud/docker/pkg/libcontainer"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNotValidStrategyType = errors.New("not a valid network strategy type")
|
||||
)
|
||||
|
||||
var strategies = map[string]NetworkStrategy{
|
||||
"veth": &Veth{},
|
||||
}
|
||||
|
||||
// NetworkStrategy represends a specific network configuration for
|
||||
// a containers networking stack
|
||||
type NetworkStrategy interface {
|
||||
Create(*libcontainer.Network, int) (libcontainer.Context, error)
|
||||
Initialize(*libcontainer.Network, libcontainer.Context) error
|
||||
}
|
||||
|
||||
// GetStrategy returns the specific network strategy for the
|
||||
// provided type. If no strategy is registered for the type an
|
||||
// ErrNotValidStrategyType is returned.
|
||||
func GetStrategy(tpe string) (NetworkStrategy, error) {
|
||||
s, exists := strategies[tpe]
|
||||
if !exists {
|
||||
return nil, ErrNotValidStrategyType
|
||||
}
|
||||
return s, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue