本文整理匯總了Golang中github.com/vmware/govmomi/object.VirtualMachine.String方法的典型用法代碼示例。如果您正苦於以下問題:Golang VirtualMachine.String方法的具體用法?Golang VirtualMachine.String怎麽用?Golang VirtualMachine.String使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/vmware/govmomi/object.VirtualMachine
的用法示例。
在下文中一共展示了VirtualMachine.String方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: findDisk
// Find the disk by name attached to the given vm.
func findDisk(ctx context.Context, vm *object.VirtualMachine, name string) (*types.VirtualDisk, error) {
defer trace.End(trace.Begin(vm.String()))
log.Debugf("Looking for attached disk matching filename %s", name)
devices, err := vm.Device(ctx)
if err != nil {
return nil, fmt.Errorf("Failed to refresh devices for vm: %s", errors.ErrorStack(err))
}
candidates := devices.Select(func(device types.BaseVirtualDevice) bool {
db := device.GetVirtualDevice().Backing
if db == nil {
return false
}
backing, ok := device.GetVirtualDevice().Backing.(*types.VirtualDiskFlatVer2BackingInfo)
if !ok {
return false
}
log.Debugf("backing file name %s", backing.VirtualDeviceFileBackingInfo.FileName)
match := strings.HasSuffix(backing.VirtualDeviceFileBackingInfo.FileName, name)
if match {
log.Debugf("Found candidate disk for %s at %s", name, backing.VirtualDeviceFileBackingInfo.FileName)
}
return match
})
if len(candidates) == 0 {
log.Warnf("No disks match name: %s", name)
return nil, os.ErrNotExist
}
if len(candidates) > 1 {
return nil, errors.Errorf("Too many disks match name: %s", name)
}
return candidates[0].(*types.VirtualDisk), nil
}