Exemplo n.º 1
0
Arquivo: main.go Projeto: 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()
}
Exemplo n.º 2
0
Arquivo: daemon.go Projeto: NeilW/cni
// 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
}