예제 #1
0
파일: portlayer.go 프로젝트: vmware/vic
func Init(ctx context.Context, sess *session.Session) error {
	source, err := extraconfig.GuestInfoSource()
	if err != nil {
		return err
	}

	sink, err := extraconfig.GuestInfoSink()
	if err != nil {
		return err
	}

	// Grab the storage layer config blobs from extra config
	extraconfig.Decode(source, &storage.Config)
	log.Debugf("Decoded VCH config for storage: %#v", storage.Config)

	// create or restore a portlayer k/v store in the VCH's directory.
	vch, err := guest.GetSelf(ctx, sess)
	if err != nil {
		return err
	}

	vchvm := vm.NewVirtualMachineFromVM(ctx, sess, vch)
	vmPath, err := vchvm.VMPathName(ctx)
	if err != nil {
		return err
	}

	// vmPath is set to the vmx.  Grab the directory from that.
	vmFolder, err := datastore.ToURL(path.Dir(vmPath))
	if err != nil {
		return err
	}

	if err = store.Init(ctx, sess, vmFolder); err != nil {
		return err
	}

	if err := exec.Init(ctx, sess, source, sink); err != nil {
		return err
	}

	if err = network.Init(ctx, sess, source, sink); err != nil {
		return err
	}

	return nil
}
예제 #2
0
// Configure assigns functions to all the scopes api handlers
func (handler *ScopesHandlersImpl) Configure(api *operations.PortLayerAPI, handlerCtx *HandlerContext) {
	api.ScopesCreateScopeHandler = scopes.CreateScopeHandlerFunc(handler.ScopesCreate)
	api.ScopesDeleteScopeHandler = scopes.DeleteScopeHandlerFunc(handler.ScopesDelete)
	api.ScopesListAllHandler = scopes.ListAllHandlerFunc(handler.ScopesListAll)
	api.ScopesListHandler = scopes.ListHandlerFunc(handler.ScopesList)
	api.ScopesAddContainerHandler = scopes.AddContainerHandlerFunc(handler.ScopesAddContainer)
	api.ScopesRemoveContainerHandler = scopes.RemoveContainerHandlerFunc(handler.ScopesRemoveContainer)
	api.ScopesBindContainerHandler = scopes.BindContainerHandlerFunc(handler.ScopesBindContainer)
	api.ScopesUnbindContainerHandler = scopes.UnbindContainerHandlerFunc(handler.ScopesUnbindContainer)

	err := network.Init()
	if err != nil {
		log.Fatalf("failed to create network context: %s", err)
	}

	handler.netCtx = network.DefaultContext
	handler.handlerCtx = handlerCtx
}
예제 #3
0
파일: dns_test.go 프로젝트: jak-atx/vic
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()
}