vRO 添加已有磁盘到VM

在vRO实现将已有虚拟机磁盘添加到另外的虚拟机上,以为vRA发布Oracle/SQL集群做准备:

// 脚本需要两个输入 vm_obj和diskPath
System.log("Attempting to attach " + diskPath + " to " + vcVM.name); // Max number of vmdks attached to a single scsi controller var MAX_NUMBER_ATTACHED_VMDKS = 15; var devices = vcVm.config.hardware.device; var diskFilePath = diskPath; // sample: [sharedata]abc/abc_1.vmdk var controllerKey; var unitNumber; var usedUnitNumbers = []; for each (controller in devices) { var isScsi = controller instanceof VcVirtualBusLogicController || controller instanceof VcVirtualLsiLogicController || controller instanceof VcParaVirtualSCSIController || controller instanceof VcVirtualLsiLogicSASController; if (!isScsi) { continue; } System.log("SCSI controller found: " + controller.deviceInfo.label); for each (device in devices) { if (device.controllerKey == controller.key) { System.log("Device found: '" + device.deviceInfo.label + "' 'SCSI (" + controller.busNumber + ":" + device.unitNumber + ")'"); controllerKey = controller.key; usedUnitNumbers.push(device.unitNumber); } } break; } if (usedUnitNumbers.length >= MAX_NUMBER_ATTACHED_VMDKS) { throw "SCSI controller is full, the VMDK can not be attached!"; } var backing = new VcVirtualDiskFlatVer2BackingInfo(); backing.fileName = diskFilePath; backing.diskMode = VcVirtualDiskMode.persistent; var connectable = new VcVirtualDeviceConnectInfo(); connectable.startConnected = true; connectable.allowGuestControl = false; connectable.connected = true; // Find the first available SCSI id for (i = 0; i < MAX_NUMBER_ATTACHED_VMDKS; i++) { if (usedUnitNumbers.indexOf(i) == -1) { unitNumber = i; System.log("Found available SCSI unit numebr '" + unitNumber + "'"); break; } } var device = new VcVirtualDisk(); device.backing = backing; device.connectable = connectable; device.controllerKey = controllerKey; device.unitNumber = unitNumber; var deviceChange = new VcVirtualDeviceConfigSpec(); deviceChange.operation = VcVirtualDeviceConfigSpecOperation.add; deviceChange.device = device; var deviceChangeArray = [deviceChange]; var spec = new VcVirtualMachineConfigSpec(); spec.deviceChange = deviceChangeArray; var task = vcVm.reconfigVM_Task(spec); System.log("Initiating reconfigure..."); System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(task,true,3); System.log("Reconfigure of VM '" + vcVm.name + "' successful.");

 

转载于:https://www.cnblogs.com/vincenshen/p/8799378.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值