Example #1
0
File: main.go Project: matomesc/rkt
func cmdAdd(args *skel.CmdArgs) error {
	ipamConf, err := LoadIPAMConfig(args.StdinData, args.Args)
	if err != nil {
		return err
	}

	store, err := disk.New(ipamConf.Name)
	if err != nil {
		return err
	}
	defer store.Close()

	ipamArgs := IPAMArgs{}
	err = types.LoadArgs(args.Args, &ipamArgs)
	if err != nil {
		return err
	}
	ipamConf.Args = &ipamArgs

	allocator, err := NewIPAllocator(ipamConf, store)
	if err != nil {
		return err
	}

	ipConf, err := allocator.Get(args.ContainerID)
	if err != nil {
		return err
	}

	r := &types.Result{
		IP4: ipConf,
	}
	return r.Print()
}
Example #2
0
File: main.go Project: samarvin/rkt
func cmdAdd(args *skel.CmdArgs) error {
	ipamConf, err := LoadIPAMConfig(args.StdinData, args.Args)
	if err != nil {
		return err
	}

	store, err := disk.New(ipamConf.Name)
	if err != nil {
		return err
	}
	defer store.Close()

	ipamArgs := IPAMArgs{}
	err = plugin.LoadArgs(args.Args, &ipamArgs)
	if err != nil {
		return err
	}
	ipamConf.Args = &ipamArgs

	allocator, err := NewIPAllocator(ipamConf, store)
	if err != nil {
		return err
	}

	var ipConf *plugin.IPConfig

	switch ipamConf.Type {
	case "host-local":
		ipConf, err = allocator.Get(args.ContainerID)
	case "host-local-ptp":
		ipConf, err = allocator.GetPtP(args.ContainerID)
	default:
		return errors.New("Unsupported IPAM plugin type")
	}

	if err != nil {
		return err
	}

	r := &plugin.Result{
		IP4: ipConf,
	}
	return r.Print()
}
Example #3
0
File: main.go Project: samarvin/rkt
func cmdDel(args *skel.CmdArgs) error {
	ipamConf, err := LoadIPAMConfig(args.StdinData, args.Args)
	if err != nil {
		return err
	}

	store, err := disk.New(ipamConf.Name)
	if err != nil {
		return err
	}
	defer store.Close()

	allocator, err := NewIPAllocator(ipamConf, store)
	if err != nil {
		return err
	}

	return allocator.Release(args.ContainerID)
}
Example #4
0
func cmdAdd(args *skel.CmdArgs) error {
	ipamConf, err := LoadIPAMConfig(args.StdinData)
	if err != nil {
		return err
	}

	store, err := disk.New(ipamConf.Name)
	if err != nil {
		return err
	}
	defer store.Close()

	allocator, err := NewIPAllocator(ipamConf, store)
	if err != nil {
		return err
	}

	var ipConf *plugin.IPConfig

	switch ipamConf.Type {
	case "host-local":
		ipConf, err = allocator.Get(args.Netns)
	case "host-local-ptp":
		ipConf, err = allocator.GetPtP(args.Netns)
	default:
		return errors.New("Unsupported IPAM plugin type")
	}

	if err != nil {
		return err
	}

	return plugin.PrintResult(&plugin.Result{
		IP4: ipConf,
	})
}