本文整理匯總了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
}