Ejemplo n.º 1
0
//Init initilizes ipam module
func New(state state.State, config *config.BalancerConfig) (Allocator, error) {
	var rangeCursor *ipaddr.Cursor
	var err error

	ranges := strings.Join(config.Ipam.Ranges, ",")
	if ranges != "" {
		rangeCursor, err = ipaddr.Parse(ranges)
		if err != nil {
			return nil, errors.Wrap(err, "error parsing IPAM ranges")
		}
	}

	return &Ipam{rangeCursor, state, config}, nil
}
Ejemplo n.º 2
0
func ExampleCursor_traversal() {
	c, err := ipaddr.Parse("2001:db8::/126,192.0.2.128/30,198.51.100.0/29")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(c.Pos(), c.First(), c.Last(), c.List())
	for pos := c.Next(); pos != nil; pos = c.Next() {
		fmt.Println(pos)
	}
	fmt.Println(c.Pos(), c.First(), c.Last(), c.List())
	for pos := c.Prev(); pos != nil; pos = c.Prev() {
		fmt.Println(pos)
	}
	fmt.Println(c.Pos(), c.First(), c.Last(), c.List())
	// Output:
	// &{192.0.2.128 192.0.2.128/30} &{192.0.2.128 192.0.2.128/30} &{2001:db8::3 2001:db8::/126} [192.0.2.128/30 198.51.100.0/29 2001:db8::/126]
	// &{192.0.2.129 192.0.2.128/30}
	// &{192.0.2.130 192.0.2.128/30}
	// &{192.0.2.131 192.0.2.128/30}
	// &{198.51.100.0 198.51.100.0/29}
	// &{198.51.100.1 198.51.100.0/29}
	// &{198.51.100.2 198.51.100.0/29}
	// &{198.51.100.3 198.51.100.0/29}
	// &{198.51.100.4 198.51.100.0/29}
	// &{198.51.100.5 198.51.100.0/29}
	// &{198.51.100.6 198.51.100.0/29}
	// &{198.51.100.7 198.51.100.0/29}
	// &{2001:db8:: 2001:db8::/126}
	// &{2001:db8::1 2001:db8::/126}
	// &{2001:db8::2 2001:db8::/126}
	// &{2001:db8::3 2001:db8::/126}
	// &{2001:db8::3 2001:db8::/126} &{192.0.2.128 192.0.2.128/30} &{2001:db8::3 2001:db8::/126} [192.0.2.128/30 198.51.100.0/29 2001:db8::/126]
	// &{2001:db8::2 2001:db8::/126}
	// &{2001:db8::1 2001:db8::/126}
	// &{2001:db8:: 2001:db8::/126}
	// &{198.51.100.7 198.51.100.0/29}
	// &{198.51.100.6 198.51.100.0/29}
	// &{198.51.100.5 198.51.100.0/29}
	// &{198.51.100.4 198.51.100.0/29}
	// &{198.51.100.3 198.51.100.0/29}
	// &{198.51.100.2 198.51.100.0/29}
	// &{198.51.100.1 198.51.100.0/29}
	// &{198.51.100.0 198.51.100.0/29}
	// &{192.0.2.131 192.0.2.128/30}
	// &{192.0.2.130 192.0.2.128/30}
	// &{192.0.2.129 192.0.2.128/30}
	// &{192.0.2.128 192.0.2.128/30}
	// &{192.0.2.128 192.0.2.128/30} &{192.0.2.128 192.0.2.128/30} &{2001:db8::3 2001:db8::/126} [192.0.2.128/30 198.51.100.0/29 2001:db8::/126]
}
Ejemplo n.º 3
0
func TestParse(t *testing.T) {
	for i, tt := range parseTests {
		out, err := ipaddr.Parse(tt.in)
		if err != nil {
			t.Errorf("#%d: %v", i, err)
			continue
		}
		if !reflect.DeepEqual(out.Pos(), tt.pos) {
			t.Errorf("#%d: got %v; want %v", i, out.Pos(), tt.pos)
		}
		if !reflect.DeepEqual(out.List(), tt.ps) {
			t.Errorf("#%d: got %v; want %v", i, out.List(), tt.ps)
		}
	}
}