host-local: allow ip request via CNI_ARGS

A specific IP can now be requested via the environment variable CNI_ARGS, e.g.
`CNI_ARGS=ip=1.2.3.4`.
The plugin will try to reserve the specified IP.
If this is not successful the execution will fail.
This commit is contained in:
Stefan Junker
2015-08-16 02:30:04 +02:00
parent 59f58fb974
commit 1d398af124
5 changed files with 98 additions and 4 deletions

View File

@ -32,6 +32,11 @@ type IPAMConfig struct {
Subnet ip.IPNet `json:"subnet"`
Gateway net.IP `json:"gateway"`
Routes []plugin.Route `json:"routes"`
Args *IPAMArgs `json:"-"`
}
type IPAMArgs struct {
IP net.IP `json:"ip",omitempty`
}
type Net struct {
@ -40,12 +45,20 @@ type Net struct {
}
// NewIPAMConfig creates a NetworkConfig from the given network name.
func LoadIPAMConfig(bytes []byte) (*IPAMConfig, error) {
func LoadIPAMConfig(bytes []byte, args string) (*IPAMConfig, error) {
n := Net{}
if err := json.Unmarshal(bytes, &n); err != nil {
return nil, err
}
if args != "" {
ipamArgs := IPAMArgs{}
err := plugin.LoadArgs(args, &ipamArgs)
if err != nil {
return nil, err
}
}
if n.IPAM == nil {
return nil, fmt.Errorf("%q missing 'ipam' key")
}