Exemple #1
0
func TestMain(m *testing.M) {
	n := object.NewNetwork(nil, types.ManagedObjectReference{})
	n.InventoryPath = "testBridge"
	testBridgeNetwork = n

	n = object.NewNetwork(nil, types.ManagedObjectReference{})
	n.InventoryPath = "testExternal"
	testExternalNetwork := n

	Config = Configuration{
		BridgeLink:    &mockLink{},
		BridgeNetwork: "bridge",
		ContainerNetworks: map[string]*ContainerNetwork{
			"bridge": &ContainerNetwork{
				PortGroup: testBridgeNetwork,
			},
			"bar7": &ContainerNetwork{
				Common: executor.Common{
					Name: "external",
				},
				Gateway:     net.IPNet{IP: net.ParseIP("10.13.0.1"), Mask: net.CIDRMask(16, 32)},
				Nameservers: []net.IP{net.ParseIP("10.10.1.1")},
				Pools:       []ip.Range{*ip.ParseRange("10.13.1.0-255"), *ip.ParseRange("10.13.2.0-10.13.2.15")},
				PortGroup:   testExternalNetwork,
			},
			"bar71": &ContainerNetwork{
				Common: executor.Common{
					Name: "external",
				},
				Gateway:     net.IPNet{IP: net.ParseIP("10.131.0.1"), Mask: net.CIDRMask(16, 32)},
				Nameservers: []net.IP{net.ParseIP("10.131.0.1"), net.ParseIP("10.131.0.2")},
				Pools:       []ip.Range{*ip.ParseRange("10.131.1.0/16")},
				PortGroup:   testExternalNetwork,
			},
			"bar72": &ContainerNetwork{
				Common: executor.Common{
					Name: "external",
				},
				PortGroup: testExternalNetwork,
			},
			"bar73": &ContainerNetwork{
				Common: executor.Common{
					Name: "external",
				},
				Gateway:   net.IPNet{IP: net.ParseIP("10.133.0.1"), Mask: net.CIDRMask(16, 32)},
				PortGroup: testExternalNetwork,
			},
		},
	}

	rc := m.Run()

	os.Exit(rc)
}
Exemple #2
0
func TestMain(m *testing.M) {
	n := object.NewNetwork(nil, types.ManagedObjectReference{})
	n.InventoryPath = "testBridge"
	testBridgeNetwork = n

	n = object.NewNetwork(nil, types.ManagedObjectReference{})
	n.InventoryPath = "testExternal"
	testExternalNetwork = n

	log.SetLevel(log.DebugLevel)

	rc := m.Run()

	os.Exit(rc)
}
Exemple #3
0
func (f *Finder) NetworkList(ctx context.Context, path string) ([]object.NetworkReference, error) {
	es, err := f.find(ctx, f.networkFolder, false, path)
	if err != nil {
		return nil, err
	}

	var ns []object.NetworkReference
	for _, e := range es {
		ref := e.Object.Reference()
		switch ref.Type {
		case "Network":
			r := object.NewNetwork(f.client, ref)
			r.InventoryPath = e.Path
			ns = append(ns, r)
		case "DistributedVirtualPortgroup":
			r := object.NewDistributedVirtualPortgroup(f.client, ref)
			r.InventoryPath = e.Path
			ns = append(ns, r)
		case "DistributedVirtualSwitch", "VmwareDistributedVirtualSwitch":
			r := object.NewDistributedVirtualSwitch(f.client, ref)
			r.InventoryPath = e.Path
			ns = append(ns, r)
		}
	}

	if len(ns) == 0 {
		return nil, &NotFoundError{"network", path}
	}

	return ns, nil
}
Exemple #4
0
func (f *Finder) NetworksList(ctx context.Context, path string, recursive bool) ([]object.Network, error) {
	es, err := f.find(ctx, f.networkFolder, recursive, path)
	if err != nil {
		return nil, err
	}

	var ns []object.Network
	for _, e := range es {
		ref := e.Object.Reference()
		switch ref.Type {
		case "Network":
			r := object.NewNetwork(f.client, ref)
			r.InventoryPath = e.Path
			ns = append(ns, *r)
		}
	}

	return ns, nil
}
Exemple #5
0
func TestVIC(t *testing.T) {
	log.SetLevel(log.PanicLevel)

	options.IP = "127.0.0.1"
	options.Port = 5354

	// BEGIN - Context initialization
	var bridgeNetwork object.NetworkReference

	n := object.NewNetwork(nil, types.ManagedObjectReference{})
	n.InventoryPath = "testBridge"
	bridgeNetwork = n

	network.Config = network.Configuration{
		BridgeNetwork: "bridge",
		ContainerNetworks: map[string]*network.ContainerNetwork{
			"bridge": &network.ContainerNetwork{
				Common: metadata.Common{
					Name: "testBridge",
				},
				PortGroup: bridgeNetwork,
			},
		},
	}

	// initialize the context
	err := network.Init()
	if err != nil {
		t.Fatalf("%s", err)
	}

	// create the container
	con := exec.NewContainer("foo")
	ip := net.IPv4(172, 16, 0, 2)

	// add it
	err = network.DefaultContext.AddContainer(con, "bridge", &ip)
	if err != nil {
		t.Fatalf("%s", err)
	}

	// bind it
	_, err = network.DefaultContext.BindContainer(con)
	if err != nil {
		t.Fatalf("%s", err)
	}

	server := NewServer(options)
	if server != nil {
		server.Start()
	}
	// END - Context initialization

	m := new(mdns.Msg)
	m.SetQuestion("foo.", mdns.TypeA)

	c := new(mdns.Client)
	r, _, err := c.Exchange(m, server.Addr())
	if err != nil || len(r.Answer) == 0 {
		t.Fatalf("Exchange failed: %s", err)
	}

	m = new(mdns.Msg)
	m.SetQuestion("foo.bridge.", mdns.TypeA)

	r, _, err = c.Exchange(m, server.Addr())
	if err != nil || len(r.Answer) == 0 {
		t.Fatalf("Exchange failed: %s", err)
	}

	server.Stop()
	server.Wait()
}
Exemple #6
0
func TestVIC(t *testing.T) {
	t.Skipf("Failing with CI")

	log.SetLevel(log.PanicLevel)

	options.IP = "127.0.0.1"
	options.Port = 5354

	// BEGIN - Context initialization
	var bridgeNetwork object.NetworkReference

	n := object.NewNetwork(nil, types.ManagedObjectReference{})
	n.InventoryPath = "testBridge"
	bridgeNetwork = n

	conf := &network.Configuration{
		Network: config.Network{
			BridgeNetwork: "lo",
			ContainerNetworks: map[string]*executor.ContainerNetwork{
				"lo": {
					Common: executor.Common{
						Name: "testBridge",
					},
					Type: constants.BridgeScopeType,
				},
			},
		},
		PortGroups: map[string]object.NetworkReference{
			"lo": bridgeNetwork,
		},
	}

	// initialize the context
	ctx, err := network.NewContext(conf, nil)
	if err != nil {
		t.Fatalf("%s", err)
	}

	// create the container
	con := exec.TestHandle("foo")
	ip := net.IPv4(172, 16, 0, 2)

	ctxOptions := &network.AddContainerOptions{
		Scope: "bridge",
		IP:    &ip,
	}
	// add it
	err = ctx.AddContainer(con, ctxOptions)
	if err != nil {
		t.Fatalf("%s", err)
	}

	// bind it
	_, err = ctx.BindContainer(con)
	if err != nil {
		t.Fatalf("%s", err)
	}

	server := NewServer(options)
	if server != nil {
		server.Start()
	}
	// END - Context initialization

	m := new(mdns.Msg)
	m.SetQuestion("foo.", mdns.TypeA)

	c := new(mdns.Client)
	r, _, err := c.Exchange(m, server.Addr())
	if err != nil || len(r.Answer) == 0 {
		t.Fatalf("Exchange failed: %s", err)
	}

	m = new(mdns.Msg)
	m.SetQuestion("foo.bridge.", mdns.TypeA)

	r, _, err = c.Exchange(m, server.Addr())
	if err != nil || len(r.Answer) == 0 {
		t.Fatalf("Exchange failed: %s", err)
	}

	server.Stop()
	server.Wait()
}