Exemplo n.º 1
0
func TestIPServe(t *testing.T) {
	inuse := make([]string, 0)
	ipam, err := netutils.NewIPAllocator("10.20.30.40/24", inuse)
	if err != nil {
		t.Fatalf("Error while initializing IPAM: %v", err)
	}
	ListenAndServeNetutilServer(ipam, net.ParseIP("127.0.0.1"), 9080, nil)

	// get, get, delete, get
	ip := getIP(t)
	if ip != "10.20.30.1/24" {
		t.Fatalf("Wrong IP. Expected 10.20.30.1/24, got %s", ip)
	}
	ip = getIP(t)
	if ip != "10.20.30.2/24" {
		t.Fatalf("Wrong IP. Expected 10.20.30.2/24, got %s", ip)
	}
	err = delIP(t, ip)
	if err != nil {
		t.Fatalf("Error while deleting IP address %s: %v", ip, err)
	}
	// get it again
	ip = getIP(t)
	if ip != "10.20.30.2/24" {
		t.Fatalf("Wrong IP. Expected 10.20.30.2/24, got %s", ip)
	}
	// delete the wrong one and fail if there is no error
	err = delIP(t, "10.10.10.10/23")
	if err == nil {
		t.Fatalf("Error while deleting IP address %s: %v", ip, err)
	}
}
Exemplo n.º 2
0
func (c *FlowController) manageLocalIpam(ipnet *net.IPNet) error {
	ipamHost := "127.0.0.1"
	ipamPort := uint(9080)
	inuse := make([]string, 0)
	ipam, _ := netutils.NewIPAllocator(ipnet.String(), inuse)
	f, err := os.Create("/etc/openshift-sdn/config.env")
	if err != nil {
		return err
	}
	_, err = f.WriteString(fmt.Sprintf("OPENSHIFT_SDN_TAP1_ADDR=%s\nOPENSHIFT_SDN_IPAM_SERVER=http://%s:%s", netutils.GenerateDefaultGateway(ipnet), ipamHost, ipamPort))
	if err != nil {
		return err
	}
	f.Close()
	netutils_server.ListenAndServeNetutilServer(ipam, net.ParseIP(ipamHost), ipamPort, nil)
	return nil
}