当前位置: 首页>>代码示例>>Golang>>正文


Golang types.NewBool函数代码示例

本文整理汇总了Golang中github.com/vmware/govmomi/vim25/types.NewBool函数的典型用法代码示例。如果您正苦于以下问题:Golang NewBool函数的具体用法?Golang NewBool怎么用?Golang NewBool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewBool函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: buildVMRelocateSpec

// buildVMRelocateSpec builds VirtualMachineRelocateSpec to set a place for a new VirtualMachine.
func buildVMRelocateSpec(rp *object.ResourcePool, ds *object.Datastore, vm *object.VirtualMachine) (types.VirtualMachineRelocateSpec, error) {
	var key int

	devices, err := vm.Device(context.TODO())
	if err != nil {
		return types.VirtualMachineRelocateSpec{}, err
	}
	for _, d := range devices {
		if devices.Type(d) == "disk" {
			key = d.GetVirtualDevice().Key
		}
	}

	rpr := rp.Reference()
	dsr := ds.Reference()
	return types.VirtualMachineRelocateSpec{
		Datastore: &dsr,
		Pool:      &rpr,
		Disk: []types.VirtualMachineRelocateSpecDiskLocator{
			types.VirtualMachineRelocateSpecDiskLocator{
				Datastore: dsr,
				DiskBackingInfo: &types.VirtualDiskFlatVer2BackingInfo{
					DiskMode:        "persistent",
					ThinProvisioned: types.NewBool(false),
					EagerlyScrub:    types.NewBool(true),
				},
				DiskId: key,
			},
		},
	}, nil
}
开发者ID:AssertSelenium,项目名称:terraform,代码行数:32,代码来源:resource_vsphere_virtual_machine.go

示例2: createPool

func createPool(ctx context.Context, sess *session.Session, poolPath string, name string, t *testing.T) error {
	rp, err := sess.Finder.ResourcePool(ctx, poolPath)
	if err != nil {
		t.Logf("Failed to get parent pool: %s", err)
		return err
	}
	t.Logf("Creating Resource Pool %s", name)
	resSpec := types.ResourceConfigSpec{
		CpuAllocation: &types.ResourceAllocationInfo{
			Shares: &types.SharesInfo{
				Level: types.SharesLevelNormal,
			},
			ExpandableReservation: types.NewBool(true),
			Limit:       -1,
			Reservation: 1,
		},
		MemoryAllocation: &types.ResourceAllocationInfo{
			Shares: &types.SharesInfo{
				Level: types.SharesLevelNormal,
			},
			ExpandableReservation: types.NewBool(true),
			Limit:       -1,
			Reservation: 1,
		},
	}

	_, err = rp.Create(ctx, name, resSpec)
	if err != nil {
		t.Logf("Failed to create resource pool %s: %s", name, err)
		return err
	}
	return nil
}
开发者ID:vmware,项目名称:vic,代码行数:33,代码来源:validator_test.go

示例3: ListDatacenter

func (l Lister) ListDatacenter(ctx context.Context) ([]Element, error) {
	ospec := types.ObjectSpec{
		Obj:  l.Reference,
		Skip: types.NewBool(true),
	}

	// Include every datastore folder in the select set
	fields := []string{
		"vmFolder",
		"hostFolder",
		"datastoreFolder",
		"networkFolder",
	}

	for _, f := range fields {
		tspec := types.TraversalSpec{
			Path: f,
			Skip: types.NewBool(false),
			Type: "Datacenter",
		}

		ospec.SelectSet = append(ospec.SelectSet, &tspec)
	}

	pspec := types.PropertySpec{
		Type: "Folder",
	}

	if l.All {
		pspec.All = types.NewBool(true)
	} else {
		pspec.PathSet = []string{"name"}
	}

	req := types.RetrieveProperties{
		SpecSet: []types.PropertyFilterSpec{
			{
				ObjectSet: []types.ObjectSpec{ospec},
				PropSet:   []types.PropertySpec{pspec},
			},
		},
	}

	var dst []interface{}

	err := l.retrieveProperties(ctx, req, &dst)
	if err != nil {
		return nil, err
	}

	es := []Element{}
	for _, v := range dst {
		es = append(es, ToElement(v.(mo.Reference), l.Prefix))
	}

	return es, nil
}
开发者ID:vmware,项目名称:vic,代码行数:57,代码来源:lister.go

示例4: addHardDisk

// addHardDisk adds a new Hard Disk to the VirtualMachine.
func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, datastore *object.Datastore, diskPath string, controller_type string) error {
	devices, err := vm.Device(context.TODO())
	if err != nil {
		return err
	}
	log.Printf("[DEBUG] vm devices: %#v\n", devices)

	controller, err := devices.FindDiskController(controller_type)
	if err != nil {
		return err
	}
	log.Printf("[DEBUG] disk controller: %#v\n", controller)

	// TODO Check if diskPath & datastore exist
	// If diskPath is not specified, pass empty string to CreateDisk()
	if diskPath == "" {
		return fmt.Errorf("[ERROR] addHardDisk - No path proided")
	} else {
		// TODO Check if diskPath & datastore exist
		diskPath = fmt.Sprintf("[%v] %v", datastore.Name(), diskPath)
	}
	log.Printf("[DEBUG] addHardDisk - diskPath: %v", diskPath)
	disk := devices.CreateDisk(controller, datastore.Reference(), diskPath)

	existing := devices.SelectByBackingInfo(disk.Backing)
	log.Printf("[DEBUG] disk: %#v\n", disk)

	if len(existing) == 0 {
		disk.CapacityInKB = int64(size * 1024 * 1024)
		if iops != 0 {
			disk.StorageIOAllocation = &types.StorageIOAllocationInfo{
				Limit: iops,
			}
		}
		backing := disk.Backing.(*types.VirtualDiskFlatVer2BackingInfo)

		if diskType == "eager_zeroed" {
			// eager zeroed thick virtual disk
			backing.ThinProvisioned = types.NewBool(false)
			backing.EagerlyScrub = types.NewBool(true)
		} else if diskType == "thin" {
			// thin provisioned virtual disk
			backing.ThinProvisioned = types.NewBool(true)
		}

		log.Printf("[DEBUG] addHardDisk: %#v\n", disk)
		log.Printf("[DEBUG] addHardDisk capacity: %#v\n", disk.CapacityInKB)

		return vm.AddDevice(context.TODO(), disk)
	} else {
		log.Printf("[DEBUG] addHardDisk: Disk already present.\n")

		return nil
	}
}
开发者ID:srikalyan,项目名称:terraform,代码行数:56,代码来源:resource_vsphere_virtual_machine.go

示例5: buildVMRelocateSpec

// buildVMRelocateSpec builds VirtualMachineRelocateSpec to set a place for a new VirtualMachine.
func buildVMRelocateSpec(finder *find.Finder, rp *object.ResourcePool, ds *object.Datastore, vm *object.VirtualMachine, linked bool) (types.VirtualMachineRelocateSpec, error) {
	var key int
	var parent *types.VirtualDiskFlatVer2BackingInfo

	devices, err := vm.Device(context.TODO())
	if err != nil {
		return types.VirtualMachineRelocateSpec{}, err
	}

	for _, d := range devices {
		if devices.Type(d) == "disk" {
			vd := d.GetVirtualDevice()
			parent = vd.Backing.(*types.VirtualDiskFlatVer2BackingInfo)
			key = vd.Key
		}
	}

	rpr := rp.Reference()
	relocateSpec := types.VirtualMachineRelocateSpec{}
	// Treat linked clones a bit differently.
	if linked {
		parentDs := strings.SplitN(parent.FileName[1:], "]", 2)
		parentDsObj, err := finder.Datastore(context.TODO(), parentDs[0])
		if err != nil {
			return types.VirtualMachineRelocateSpec{}, err
		}

		parentDbObjRef := parentDsObj.Reference()
		relocateSpec = types.VirtualMachineRelocateSpec{
			Datastore:    &parentDbObjRef,
			Pool:         &rpr,
			DiskMoveType: "createNewChildDiskBacking",
		}
	} else {
		dsr := ds.Reference()

		relocateSpec = types.VirtualMachineRelocateSpec{
			Datastore: &dsr,
			Pool:      &rpr,
			Disk: []types.VirtualMachineRelocateSpecDiskLocator{
				types.VirtualMachineRelocateSpecDiskLocator{
					Datastore: dsr,
					DiskId:    key,
					DiskBackingInfo: &types.VirtualDiskFlatVer2BackingInfo{
						DiskMode:        "persistent",
						ThinProvisioned: types.NewBool(false),
						EagerlyScrub:    types.NewBool(true),
					},
				},
			},
		}
	}

	return relocateSpec, nil
}
开发者ID:NetworkBytes,项目名称:terraform,代码行数:56,代码来源:resource_vsphere_virtual_machine.go

示例6: Register

func (cmd *boot) Register(f *flag.FlagSet) {
	f.Int64Var(&cmd.BootDelay, "delay", 0, "Delay in ms before starting the boot sequence")
	f.StringVar(&cmd.order, "order", "", "Boot device order")
	f.Int64Var(&cmd.BootRetryDelay, "retry-delay", 0, "Delay in ms before a boot retry")

	cmd.BootRetryEnabled = types.NewBool(false)
	f.BoolVar(cmd.BootRetryEnabled, "retry", false, "If true, retry boot after retry-delay")

	cmd.EnterBIOSSetup = types.NewBool(false)
	f.BoolVar(cmd.EnterBIOSSetup, "setup", false, "If true, enter BIOS setup on next boot")
}
开发者ID:MerlinDMC,项目名称:machine,代码行数:11,代码来源:boot.go

示例7: Register

func (cmd *configure) Register(f *flag.FlagSet) {
	cmd.defaults.Enabled = types.NewBool(false)
	f.BoolVar(cmd.defaults.Enabled, "enabled", false, "")

	f.IntVar(&cmd.defaults.StartDelay, "start-delay", 0, "")
	f.StringVar(&cmd.defaults.StopAction, "stop-action", "", "")
	f.IntVar(&cmd.defaults.StopDelay, "stop-delay", 0, "")

	cmd.defaults.WaitForHeartbeat = types.NewBool(false)
	f.BoolVar(cmd.defaults.WaitForHeartbeat, "wait-for-heartbeat", false, "")
}
开发者ID:MerlinDMC,项目名称:machine,代码行数:11,代码来源:configure.go

示例8: loadUsedPorts

func loadUsedPorts(c *vim25.Client, host types.ManagedObjectReference) ([]int, error) {
	ctx := context.TODO()
	ospec := types.ObjectSpec{
		Obj: host,
		SelectSet: []types.BaseSelectionSpec{
			&types.TraversalSpec{
				Type: "HostSystem",
				Path: "vm",
				Skip: types.NewBool(false),
			},
		},
		Skip: types.NewBool(false),
	}

	pspec := types.PropertySpec{
		Type:    "VirtualMachine",
		PathSet: []string{"config.extraConfig"},
	}

	req := types.RetrieveProperties{
		This: c.ServiceContent.PropertyCollector,
		SpecSet: []types.PropertyFilterSpec{
			{
				ObjectSet: []types.ObjectSpec{ospec},
				PropSet:   []types.PropertySpec{pspec},
			},
		},
	}

	var vms []mo.VirtualMachine
	err := mo.RetrievePropertiesForRequest(ctx, c, req, &vms)
	if err != nil {
		return nil, err
	}

	var ports []int
	for _, vm := range vms {
		if vm.Config == nil || vm.Config.ExtraConfig == nil {
			continue
		}

		options := vncOptionsFromExtraConfig(vm.Config.ExtraConfig)
		if ps, ok := options["port"]; ok && ps != "" {
			pi, err := strconv.Atoi(ps)
			if err == nil {
				ports = append(ports, pi)
			}
		}
	}

	return ports, nil
}
开发者ID:vmware,项目名称:vic,代码行数:52,代码来源:vnc.go

示例9: CreateDisk

// CreateDisk creates a new VirtualDisk device which can be added to a VM.
func (l VirtualDeviceList) CreateDisk(c types.BaseVirtualController, name string) *types.VirtualDisk {
	// If name is not specified, one will be chosen for you.
	// But if when given, make sure it ends in .vmdk, otherwise it will be treated as a directory.
	if len(name) > 0 && filepath.Ext(name) != ".vmdk" {
		name += ".vmdk"
	}

	device := &types.VirtualDisk{
		VirtualDevice: types.VirtualDevice{
			Backing: &types.VirtualDiskFlatVer2BackingInfo{
				DiskMode:        string(types.VirtualDiskModePersistent),
				ThinProvisioned: types.NewBool(true),
				VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
					FileName: name,
				},
			},
		},
	}

	l.AssignController(device, c)

	if device.UnitNumber == 0 {
		device.UnitNumber = -1 // TODO: this field is annotated as omitempty
	}

	return device
}
开发者ID:EricYT,项目名称:govmomi,代码行数:28,代码来源:virtual_device_list.go

示例10: searchByUUID

func (flag *SearchFlag) searchByUUID(c *vim25.Client, dc *object.Datacenter) (object.Reference, error) {
	isVM := false
	switch flag.t {
	case SearchVirtualMachines:
		isVM = true
	case SearchHosts:
	default:
		panic("unsupported type")
	}

	var ref object.Reference
	var err error

	for _, iu := range []*bool{nil, types.NewBool(true)} {
		ref, err = flag.searchIndex(c).FindByUuid(context.TODO(), dc, flag.byUUID, isVM, iu)
		if err != nil {
			if soap.IsSoapFault(err) {
				fault := soap.ToSoapFault(err).VimFault()
				if _, ok := fault.(types.InvalidArgument); ok {
					continue
				}
			}
			return nil, err
		}
		if ref != nil {
			break
		}
	}

	return ref, nil
}
开发者ID:hmahmood,项目名称:govmomi,代码行数:31,代码来源:search.go

示例11: RevertToSnapshot

// RevertToSnapshot reverts to a named snapshot
func (v VirtualMachine) RevertToSnapshot(ctx context.Context, name string, suppressPowerOn bool) (*Task, error) {
	var o mo.VirtualMachine

	err := v.Properties(ctx, v.Reference(), []string{"snapshot"}, &o)

	snapshotTree := o.Snapshot.RootSnapshotList
	if len(snapshotTree) < 1 {
		return nil, errors.New("No snapshots for this VM")
	}

	snapshot, err := traverseSnapshotInTree(snapshotTree, name)
	if err != nil {
		return nil, err
	}

	req := types.RevertToSnapshot_Task{
		This:            snapshot,
		SuppressPowerOn: types.NewBool(suppressPowerOn),
	}

	res, err := methods.RevertToSnapshot_Task(ctx, v.c, &req)
	if err != nil {
		return nil, err
	}

	return NewTask(v.c, res.Returnval), nil
}
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:28,代码来源:virtual_machine.go

示例12: Register

func (s *ResourceConfigSpecFlag) Register(f *flag.FlagSet) {
	opts := []struct {
		name  string
		units string
		*types.ResourceAllocationInfo
	}{
		{"CPU", "MHz", &s.CpuAllocation},
		{"Memory", "MB", &s.MemoryAllocation},
	}

	for _, opt := range opts {
		prefix := strings.ToLower(opt.name)[:3]
		shares := (*sharesInfo)(opt.Shares)

		expandableReservation := false
		if v := opt.ExpandableReservation; v != nil {
			expandableReservation = *v
		}

		// Initialize bool pointer
		opt.ExpandableReservation = types.NewBool(false)

		f.Int64Var(&opt.Limit, prefix+".limit", 0, opt.name+" limit in "+opt.units)
		f.Int64Var(&opt.Reservation, prefix+".reservation", 0, opt.name+" reservation in "+opt.units)
		f.BoolVar(opt.ExpandableReservation, prefix+".expandable", expandableReservation, opt.name+" expandable reservation")
		f.Var(shares, prefix+".shares", opt.name+" shares level or number")
	}
}
开发者ID:EricYT,项目名称:govmomi,代码行数:28,代码来源:resource_config_spec.go

示例13: MoveVirtualDisk

// MoveVirtualDisk moves a virtual disk.
func (m VirtualDiskManager) MoveVirtualDisk(
	ctx context.Context,
	sourceName string, sourceDatacenter *Datacenter,
	destName string, destDatacenter *Datacenter,
	force bool) (*Task, error) {
	req := types.MoveVirtualDisk_Task{
		This:       m.Reference(),
		SourceName: sourceName,
		DestName:   destName,
		Force:      types.NewBool(force),
	}

	if sourceDatacenter != nil {
		ref := sourceDatacenter.Reference()
		req.SourceDatacenter = &ref
	}

	if destDatacenter != nil {
		ref := destDatacenter.Reference()
		req.DestDatacenter = &ref
	}

	res, err := methods.MoveVirtualDisk_Task(ctx, m.c, &req)
	if err != nil {
		return nil, err
	}

	return NewTask(m.c, res.Returnval), nil
}
开发者ID:hickeng,项目名称:govmomi,代码行数:30,代码来源:virtual_disk_manager.go

示例14: CopyDatastoreFile

func (f FileManager) CopyDatastoreFile(ctx context.Context, sourceName string, sourceDatacenter *Datacenter, destinationName string, destinationDatacenter *Datacenter, force bool) (*Task, error) {
	req := types.CopyDatastoreFile_Task{
		This:            f.Reference(),
		SourceName:      sourceName,
		DestinationName: destinationName,
		Force:           types.NewBool(force),
	}

	if sourceDatacenter != nil {
		ref := sourceDatacenter.Reference()
		req.SourceDatacenter = &ref
	}

	if destinationDatacenter != nil {
		ref := destinationDatacenter.Reference()
		req.DestinationDatacenter = &ref
	}

	res, err := methods.CopyDatastoreFile_Task(ctx, f.c, &req)
	if err != nil {
		return nil, err
	}

	return NewTask(f.c, res.Returnval), nil
}
开发者ID:vmware,项目名称:vic,代码行数:25,代码来源:file_manager.go

示例15: Run

func (cmd *ls) Run(f *flag.FlagSet) error {
	ds, err := cmd.Datastore()
	if err != nil {
		return err
	}

	b, err := ds.Browser(context.TODO())
	if err != nil {
		return err
	}

	args := f.Args()
	if len(args) == 0 {
		args = []string{""}
	}

	result := &listOutput{
		rs:   make([]types.HostDatastoreBrowserSearchResults, 0),
		long: cmd.long,
	}

	for _, arg := range args {
		spec := types.HostDatastoreBrowserSearchSpec{
			MatchPattern: []string{"*"},
		}

		if cmd.long {
			spec.Details = &types.FileQueryFlags{
				FileType:     true,
				FileSize:     true,
				FileOwner:    types.NewBool(true), // TODO: omitempty is generated, but seems to be required
				Modification: true,
			}
		}

		for i := 0; ; i++ {
			r, err := cmd.ListPath(b, arg, spec)
			if err != nil {
				// Treat the argument as a match pattern if not found as directory
				if i == 0 && types.IsFileNotFound(err) {
					spec.MatchPattern[0] = path.Base(arg)
					arg = path.Dir(arg)
					continue
				}

				return err
			}

			// Treat an empty result against match pattern as file not found
			if i == 1 && len(r.File) == 0 {
				return fmt.Errorf("File %s/%s was not found", r.FolderPath, spec.MatchPattern[0])
			}

			result.add(r)
			break
		}
	}

	return cmd.WriteResult(result)
}
开发者ID:EricYT,项目名称:govmomi,代码行数:60,代码来源:ls.go


注:本文中的github.com/vmware/govmomi/vim25/types.NewBool函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。