<commit_before>package ipamplugin

import (
	"encoding/json"
	"fmt"
	"net"

	"github.com/appc/cni/pkg/skel"
	"github.com/appc/cni/pkg/types"
)

func (i *Ipam) CmdAdd(args *skel.CmdArgs) error {
	result, err := i.Allocate(args)
	if err != nil {
		return err
	}
	return result.Print()
}

func (i *Ipam) Allocate(args *skel.CmdArgs) (*types.Result, error) {
	// extract the things we care about
	conf, err := loadIPAMConf(args.StdinData)
	if err != nil {
		return nil, err
	}
	if conf == nil {
		conf = &ipamConf{}
	}
	containerID := args.ContainerID
	var ipnet *net.IPNet

	if conf.Subnet == "" {
		ipnet, err = i.weave.AllocateIP(containerID)
	} else {
		var subnet *net.IPNet
		subnet, err = types.ParseCIDR(conf.Subnet)
		if err != nil {
			return nil, fmt.Errorf("subnet given in config, but not parseable: %s", err)
		}
		ipnet, err = i.weave.AllocateIPInSubnet(containerID, subnet)
	}

	if err != nil {
		return nil, err
	}
	result := &types.Result{<commit_msg>Sanity-check ipam args to make diagnosis easier<commit_after>package ipamplugin

import (
	"encoding/json"
	"fmt"
	"net"

	"github.com/appc/cni/pkg/skel"
	"github.com/appc/cni/pkg/types"
)

func (i *Ipam) CmdAdd(args *skel.CmdArgs) error {
	result, err := i.Allocate(args)
	if err != nil {
		return err
	}
	return result.Print()
}

func (i *Ipam) Allocate(args *skel.CmdArgs) (*types.Result, error) {
	// extract the things we care about
	conf, err := loadIPAMConf(args.StdinData)
	if err != nil {
		return nil, err
	}
	if conf == nil {
		conf = &ipamConf{}
	}
	containerID := args.ContainerID
	if containerID == "" {
		return nil, fmt.Errorf("Weave CNI Allocate: blank container name")
	}
	var ipnet *net.IPNet

	if conf.Subnet == "" {
		ipnet, err = i.weave.AllocateIP(containerID)
	} else {
		var subnet *net.IPNet
		subnet, err = types.ParseCIDR(conf.Subnet)
		if err != nil {
			return nil, fmt.Errorf("subnet given in config, but not parseable: %s", err)
		}
		ipnet, err = i.weave.AllocateIPInSubnet(containerID, subnet)
	}

	if err != nil {
		return nil, err
	}
	result := &types.Result{
{'fraction_non_alphanumeric': 0.1436893203883495, 'fraction_numerical': 0.0, 'mean_word_length': 3.5902004454342986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6156478', 'n_tokens_mistral': 849, 'n_tokens_neox': 817, 'n_words': 203}