• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang find.Finder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang cli.Register函数代码示例发布时间:2022-05-28
下一篇:
Golang find.NewFinder函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap