2014-06-24 07:23:51 +08:00
|
|
|
// +build linux
|
|
|
|
|
2014-02-22 14:20:15 +08:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrNotValidStrategyType = errors.New("not a valid network strategy type")
|
|
|
|
)
|
|
|
|
|
|
|
|
var strategies = map[string]NetworkStrategy{
|
2014-03-16 08:01:31 +08:00
|
|
|
"veth": &Veth{},
|
|
|
|
"loopback": &Loopback{},
|
2014-02-22 14:20:15 +08:00
|
|
|
}
|
|
|
|
|
2014-02-27 11:19:14 +08:00
|
|
|
// NetworkStrategy represents a specific network configuration for
|
|
|
|
// a container's networking stack
|
2014-02-22 14:20:15 +08:00
|
|
|
type NetworkStrategy interface {
|
2014-06-26 06:51:28 +08:00
|
|
|
Create(*Network, int, *NetworkState) error
|
|
|
|
Initialize(*Network, *NetworkState) error
|
2014-02-22 14:20:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|