本文整理汇总了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
} //
示例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
}
}
示例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
}
示例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
}
示例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.")
}
}
示例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
}
示例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
}
示例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
}