2014-02-21 22:20:15 -08:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2014-03-03 14:41:38 -08:00
|
|
|
|
2014-02-21 22:20:15 -08:00
|
|
|
"github.com/dotcloud/docker/pkg/libcontainer"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrNotValidStrategyType = errors.New("not a valid network strategy type")
|
|
|
|
)
|
|
|
|
|
|
|
|
var strategies = map[string]NetworkStrategy{
|
2014-03-16 01:01:31 +01:00
|
|
|
"veth": &Veth{},
|
|
|
|
"loopback": &Loopback{},
|
2014-03-03 14:41:38 -08:00
|
|
|
"netns": &NetNS{},
|
2014-02-21 22:20:15 -08:00
|
|
|
}
|
|
|
|
|
2014-02-26 19:19:14 -08:00
|
|
|
// NetworkStrategy represents a specific network configuration for
|
|
|
|
// a container's networking stack
|
2014-02-21 22:20:15 -08:00
|
|
|
type NetworkStrategy interface {
|
2014-02-26 14:19:39 -08:00
|
|
|
Create(*libcontainer.Network, int, libcontainer.Context) error
|
2014-02-21 22:20:15 -08:00
|
|
|
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
|
|
|
|
}
|