當前位置: 首頁>>代碼示例>>Golang>>正文


Golang VirtualMachine.RemoveDevice方法代碼示例

本文整理匯總了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
} //
開發者ID:amitinfo2k,項目名稱:packerfixdvsnw,代碼行數:35,代碼來源:step_fix_network.go

示例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
}
開發者ID:thrasher-redhat,項目名稱:origin,代碼行數:13,代碼來源:vsphere.go

示例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
}
開發者ID:zhaog918,項目名稱:govmax,代碼行數:42,代碼來源:vmomi.go


注:本文中的github.com/vmware/govmomi/object.VirtualMachine.RemoveDevice方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。