本文整理汇总了Golang中github.com/vmware/govmomi/object.VirtualMachine.RemoveDevice方法的典型用法代码示例。如果您正苦于以下问题:Golang VirtualMachine.RemoveDevice方法的具体用法?Golang VirtualMachine.RemoveDevice怎么用?Golang VirtualMachine.RemoveDevice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vmware/govmomi/object.VirtualMachine
的用法示例。
在下文中一共展示了VirtualMachine.RemoveDevice方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: delVNIC
func delVNIC(ui packer.Ui, f *find.Finder, ctx context.Context, vm *object.VirtualMachine) error {
ui.Say("Deleting NIC ")
devicelst, err := vm.Device(ctx)
if err != nil {
return err
}
for _, device := range devicelst {
switch device.(type) {
case *types.VirtualVmxnet3:
ui.Message(fmt.Sprintf("Removing NIC %s\n", device.GetVirtualDevice().DeviceInfo))
err := vm.RemoveDevice(ctx, device)
if err != nil {
return err
}
return nil
case *types.VirtualE1000:
ui.Message(fmt.Sprintf("Removing NIC %s\n", device.GetVirtualDevice().DeviceInfo))
err := vm.RemoveDevice(ctx, device)
if err != nil {
return err
}
return nil
default:
fmt.Printf("Type %s\n", reflect.TypeOf(device).Elem())
fmt.Printf("Device info %s\n", device.GetVirtualDevice().DeviceInfo)
}
}
return nil
} //
示例2: cleanUpController
// Removes SCSI controller which is latest attached to VM.
func cleanUpController(newSCSIController types.BaseVirtualDevice, vmDevices object.VirtualDeviceList, vm *object.VirtualMachine, ctx context.Context) error {
ctls := vmDevices.SelectByType(newSCSIController)
if len(ctls) < 1 {
return ErrNoDevicesFound
}
newScsi := ctls[len(ctls)-1]
err := vm.RemoveDevice(ctx, true, newScsi)
if err != nil {
return err
}
return nil
}
示例3: DetachRDM
func (vmh *VMHost) DetachRDM(vm *object.VirtualMachine, deviceNAA string) error {
scsiLuns, err := vmh.GetSCSILuns()
if err != nil {
return err
}
mapSDI := make(map[string]*types.ScsiLun)
for _, d := range scsiLuns {
mapSDI[d.Uuid] = d
}
devices, err := vm.Device(context.TODO())
if err != nil {
return err
}
for _, device := range devices {
device2 := device.(types.BaseVirtualDevice).GetVirtualDevice()
if device2.Backing != nil {
elem := reflect.ValueOf(device2.Backing).Elem()
lunUuid := elem.FieldByName("LunUuid")
if lunUuid.Kind() == reflect.Invalid {
continue
}
if sd, ok := mapSDI[lunUuid.String()]; ok && strings.Contains(sd.CanonicalName, deviceNAA) {
deviceName := devices.Name(device)
newDevice := devices.Find(deviceName)
if newDevice == nil {
return fmt.Errorf("device '%s' not found", deviceName)
}
if err = vm.RemoveDevice(context.TODO(), newDevice); err != nil {
return err
}
break
}
}
}
return nil
}