Beispiel #1
0
Datei: main.go Projekt: NeilW/cni
func cmdAdd(args *skel.CmdArgs) error {
	result := plugin.Result{}
	if err := rpcCall("DHCP.Allocate", args, &result); err != nil {
		return err
	}
	return result.Print()
}
Beispiel #2
0
// Allocate acquires an IP from a DHCP server for a specified container.
// The acquired lease will be maintained until Release() is called.
func (d *DHCP) Allocate(args *skel.CmdArgs, result *plugin.Result) error {
	conf := plugin.NetConf{}
	if err := json.Unmarshal(args.StdinData, &conf); err != nil {
		return fmt.Errorf("error parsing netconf: %v", err)
	}

	clientID := args.ContainerID + "/" + conf.Name
	l, err := AcquireLease(clientID, args.Netns, args.IfName)
	if err != nil {
		return err
	}

	ipn, err := l.IPNet()
	if err != nil {
		l.Stop()
		return err
	}

	d.setLease(args.ContainerID, conf.Name, l)

	result.IP4 = &plugin.IPConfig{
		IP:      *ipn,
		Gateway: l.Gateway(),
		Routes:  l.Routes(),
	}

	return nil
}