func cmdAdd(args *skel.CmdArgs) error { result := types.Result{} if err := rpcCall("DHCP.Allocate", args, &result); err != nil { return err } return result.Print() }
// 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 *types.Result) error { conf := types.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 = &types.IPConfig{ IP: *ipn, Gateway: l.Gateway(), Routes: l.Routes(), } return nil }