示例#1
0
文件: vm_test.go 项目: vmware/vic
func CreateVM(ctx context.Context, session *session.Session, host *object.HostSystem, name string) (*types.ManagedObjectReference, error) {
	// Create the spec config
	specconfig := test.SpecConfig(session, name)

	// Create a linux guest
	linux, err := guest.NewLinuxGuest(ctx, session, specconfig)
	if err != nil {
		return nil, err
	}

	// Find the Virtual Machine folder that we use
	folders, err := session.Datacenter.Folders(ctx)
	if err != nil {
		return nil, err
	}
	parent := folders.VmFolder

	// Create the vm
	task, err := parent.CreateVM(ctx, *linux.Spec().Spec(), session.Pool, host)
	if err != nil {
		return nil, err
	}
	info, err := task.WaitForResult(ctx, nil)
	if err != nil {
		return nil, err
	}

	moref := info.Result.(types.ManagedObjectReference)
	// Return the moRef
	return &moref, nil
}
示例#2
0
文件: linux_test.go 项目: jak-atx/vic
func TestNewLinuxGuest(t *testing.T) {

	ctx := context.Background()

	session := test.Session(ctx, t)
	defer session.Logout(ctx)

	specconfig := test.SpecConfig(session)

	root, _ := NewLinuxGuest(ctx, session, specconfig)
	assert.Equal(t, "other3xLinux64Guest", root.GuestID())
}