<commit_before>package main

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

	"github.com/appc/cni/pkg/skel"
	"github.com/appc/cni/pkg/types"
	"github.com/cloudfoundry-incubator/ducati-daemon/client"
	"github.com/cloudfoundry-incubator/ducati-daemon/models"
)

type NetConf struct {
	types.NetConf
	NetworkID     string `json:"network_id"`
	DaemonBaseURL string `json:"daemon_base_url"`
}

func loadConf(bytes []byte) (*NetConf, error) {
	n := &NetConf{}

	if err := json.Unmarshal(bytes, n); err != nil {
		return nil, fmt.Errorf("failed to load netconf: %v", err)
	}

	if n.DaemonBaseURL == "" {
		return nil, fmt.Errorf(`"daemon_base_url" field required.`)
	}

	return n, nil
}

func cmdAdd(args *skel.CmdArgs) error {
	if args.ContainerID == "" {
		return errors.New("CNI_CONTAINERID is required")
	}

	netConf, err := loadConf(args.StdinData)
	if err != nil {
		return fmt.Errorf("loading config: %s", err)
	}

	if netConf.NetworkID == "" {
		return fmt.Errorf(`loading config: "network_id" field required.`)
	}

	daemonClient := client.New(netConf.DaemonBaseURL, http.DefaultClient)

	ipamResult, err := daemonClient.ContainerUp(models.NetworksSetupContainerPayload{
		Args:               args.Args,
		ContainerNamespace: args.Netns,
		InterfaceName:      args.IfName,
		NetworkID:          netConf.NetworkID,
		ContainerID:        args.ContainerID,
	})
	if err != nil {
		return err
	}

	return ipamResult.Print()
}

func cmdDel(args *skel.CmdArgs) error {
	netConf, err := loadConf(args.StdinData)
	if err != nil {
		return fmt.Errorf("loading config: %s", err)
	}

	daemonClient := client.New(netConf.DaemonBaseURL, http.DefaultClient)

	err = daemonClient.ContainerDown(models.NetworksDeleteContainerPayload{
		ContainerNamespace: args.Netns,
		InterfaceName:      args.IfName,
		ContainerID:        args.ContainerID,
	})
	if err != nil {
		return err
	}

	return nil
}<commit_msg>Update daemon client call with new model names<commit_after>package main

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

	"github.com/appc/cni/pkg/skel"
	"github.com/appc/cni/pkg/types"
	"github.com/cloudfoundry-incubator/ducati-daemon/client"
	"github.com/cloudfoundry-incubator/ducati-daemon/models"
)

type NetConf struct {
	types.NetConf
	NetworkID     string `json:"network_id"`
	DaemonBaseURL string `json:"daemon_base_url"`
}

func loadConf(bytes []byte) (*NetConf, error) {
	n := &NetConf{}

	if err := json.Unmarshal(bytes, n); err != nil {
		return nil, fmt.Errorf("failed to load netconf: %v", err)
	}

	if n.DaemonBaseURL == "" {
		return nil, fmt.Errorf(`"daemon_base_url" field required.`)
	}

	return n, nil
}

func cmdAdd(args *skel.CmdArgs) error {
	if args.ContainerID == "" {
		return errors.New("CNI_CONTAINERID is required")
	}

	netConf, err := loadConf(args.StdinData)
	if err != nil {
		return fmt.Errorf("loading config: %s", err)
	}

	if netConf.NetworkID == "" {
		return fmt.Errorf(`loading config: "network_id" field required.`)
	}

	daemonClient := client.New(netConf.DaemonBaseURL, http.DefaultClient)

	ipamResult, err := daemonClient.ContainerUp(models.CNIAddPayload{
		Args:               args.Args,
		ContainerNamespace: args.Netns,
		InterfaceName:      args.IfName,
		NetworkID:          netConf.NetworkID,
		ContainerID:        args.ContainerID,
	})
	if err != nil {
		return err
	}

	return ipamResult.Print()
}

func cmdDel(args *skel.CmdArgs) error {
	netConf, err := loadConf(args.StdinData)
	if err != nil {
		return fmt.Errorf("loading config: %s", err)
	}

	daemonClient := client.New(netConf.DaemonBaseURL, http.DefaultClient)

	err = daemonClient.ContainerDown(models.CNIDelPayload{
		ContainerNamespace: args.Netns,
		InterfaceName:      args.IfName,
		ContainerID:        args.ContainerID,
	})
	if err != nil {
		return err
	}

	return nil
}
{'fraction_non_alphanumeric': 0.1332280147446024, 'fraction_numerical': 0.0, 'mean_word_length': 3.9209844559585494, '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': '3467974', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1357, 'n_words': 281}