當前位置: 首頁>>代碼示例>>Golang>>正文


Golang find.Finder類代碼示例

本文整理匯總了Golang中github.com/vmware/govmomi/find.Finder的典型用法代碼示例。如果您正苦於以下問題:Golang Finder類的具體用法?Golang Finder怎麽用?Golang Finder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Finder類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: addVNIC

func addVNIC(ui packer.Ui, f *find.Finder, ctx context.Context, c *govmomi.Client, vm *object.VirtualMachine, network string, nwType string) error {

	ui.Say("Adding NIC")

	nets, err := f.NetworkList(ctx, network)
	if err != nil {
		return err
	}
	// TODO expose param for DVS
	net := nets[1]

	backing, err := net.EthernetCardBackingInfo(ctx)
	if err != nil {
		return err
	}
	device, err := object.EthernetCardTypes().CreateEthernetCard(nwType, backing)
	if err != nil {
		return err
	}
	err = vm.AddDevice(ctx, device)
	if err != nil {
		return err
	}
	ui.Say("Adding NIC Success")

	return nil
} //
開發者ID:amitinfo2k,項目名稱:packerfixdvsnw,代碼行數:27,代碼來源:step_fix_network.go

示例2: getDatastore

// getDatastore gets datastore object
func getDatastore(f *find.Finder, ds string) (*object.Datastore, error) {

	if ds != "" {
		dso, err := f.Datastore(context.TODO(), ds)
		return dso, err
	} else {
		dso, err := f.DefaultDatastore(context.TODO())
		return dso, err
	}
}
開發者ID:RezaDKhan,項目名稱:terraform,代碼行數:11,代碼來源:resource_vsphere_file.go

示例3: 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

示例4: getHostSystem

func (d *Driver) getHostSystem(f *find.Finder, ctx context.Context) (hs *object.HostSystem, err error) {
	// HostSystem
	if d.HostSystem != "" {
		// Find specified HostSystem
		hs, err = f.HostSystem(ctx, d.HostSystem)
		if err != nil {
			return hs, err
		}
	} else {
		// Find default HostSystem
		hs, err = f.DefaultHostSystem(ctx)
		if err != nil {
			return hs, err
		}
	}
	log.Debug("HostSystem found: ", hs)
	return hs, nil
}
開發者ID:MerlinDMC,項目名稱:machine,代碼行數:18,代碼來源:vsphere.go

示例5: buildNetworkDevice

// buildNetworkDevice builds VirtualDeviceConfigSpec for Network Device.
func buildNetworkDevice(f *find.Finder, label, adapterType string) (*types.VirtualDeviceConfigSpec, error) {
	network, err := f.Network(context.TODO(), "*"+label)
	if err != nil {
		return nil, err
	}

	backing, err := network.EthernetCardBackingInfo(context.TODO())
	if err != nil {
		return nil, err
	}

	if adapterType == "vmxnet3" {
		return &types.VirtualDeviceConfigSpec{
			Operation: types.VirtualDeviceConfigSpecOperationAdd,
			Device: &types.VirtualVmxnet3{
				VirtualVmxnet: types.VirtualVmxnet{
					VirtualEthernetCard: types.VirtualEthernetCard{
						VirtualDevice: types.VirtualDevice{
							Key:     -1,
							Backing: backing,
						},
						AddressType: string(types.VirtualEthernetCardMacTypeGenerated),
					},
				},
			},
		}, nil
	} else if adapterType == "e1000" {
		return &types.VirtualDeviceConfigSpec{
			Operation: types.VirtualDeviceConfigSpecOperationAdd,
			Device: &types.VirtualE1000{
				VirtualEthernetCard: types.VirtualEthernetCard{
					VirtualDevice: types.VirtualDevice{
						Key:     -1,
						Backing: backing,
					},
					AddressType: string(types.VirtualEthernetCardMacTypeGenerated),
				},
			},
		}, nil
	} else {
		return nil, fmt.Errorf("Invalid network adapter type.")
	}
}
開發者ID:mafrosis,項目名稱:terraform,代碼行數:44,代碼來源:resource_vsphere_virtual_machine.go

示例6: getDatastore

func (d *Driver) getDatastore(f *find.Finder, ctx context.Context) (dss *object.Datastore, err error) {

	// Datastore
	if d.Datastore != "" {
		// Find specified Datastore
		dss, err = f.Datastore(ctx, d.Datastore)
		if err != nil {
			return dss, err
		}
	} else {
		// Find default Datastore
		dss, err = f.DefaultDatastore(ctx)
		if err != nil {
			return dss, err
		}
	}
	log.Debug("Datastore found: ", dss)
	return dss, err
}
開發者ID:MerlinDMC,項目名稱:machine,代碼行數:19,代碼來源:vsphere.go

示例7: getDatacenter

func (d *Driver) getDatacenter(f *find.Finder, ctx context.Context) (dc *object.Datacenter, err error) {

	// Datacenter
	if d.Datacenter != "" {
		// Find specified Datacenter
		dc, err = f.Datacenter(ctx, d.Datacenter)
		if err != nil {
			return dc, err
		}
	} else {
		// Use default Datacenter
		dc, err = f.DefaultDatacenter(ctx)
		if err != nil {
			return dc, err
		}
	}
	log.Debug("Datacenter found: ", dc)
	return dc, nil
}
開發者ID:MerlinDMC,項目名稱:machine,代碼行數:19,代碼來源:vsphere.go

示例8: getNetwork

func (d *Driver) getNetwork(f *find.Finder, ctx context.Context) (net object.NetworkReference, err error) {

	// Network
	if d.Network != "" {
		// Find specified Network
		net, err = f.Network(ctx, d.Network)
		if err != nil {
			return net, err
		}
	} else {
		// Find default Network
		net, err = f.DefaultNetwork(ctx)
		if err != nil {
			return net, err
		}
	}
	log.Debug("Network found: ", net)
	return net, nil

}
開發者ID:MerlinDMC,項目名稱:machine,代碼行數:20,代碼來源:vsphere.go


注:本文中的github.com/vmware/govmomi/find.Finder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。