Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 49146

How to move disks to another controller in vRO 7.4??

$
0
0

We recently got our vRO upgraded to 7.4. Since then I am unable to get the following code to work.

I am trying to move the virtual machine disks from one controller to other. vm has 3 SCSI paravirtual controllers

I have a simple requirement to accomplish following tasks

1) Disk number 1 and 2 needs to be on an original SCSI controller

2) Disk number 3 (Hard disk 3) should be on controller 1 (1:0)

3) Hard disk 4 should be on controller 2 (2:0)

4) Hard disk 5 should be on controller 2 (2:1)

5) Hard disk 6 should go to controller 3 (3:0)

6) Hard disk 7 should go to controller 3 (3:1)

 

 

I have following code but I can't get it to work in vRO 7.4 (in our older CMP 7.2 this is working fine so not sure is something changed in 7.4)

 

 

Can someone here suggest the correction? I am not able to understand what I am doing wrong. I feel the code goes wrong somewhere near "var deviceConfigSpec = new VcVirtualDeviceConfigSpec" line but I am unable to figure out the exact issue here

 

(vm is the variable for VC:Virtualmachine object and task is Vc:Task object)

===========================================

System.log("vm: " + vm.name);

// scsi controllers

var controllers = [];

for each (var device in vm.config.hardware.device) {

var label = device.deviceInfo.label;

for each (var i=1; i<=3; i++) {

var name = "SCSI controller " + i;

if (label == name) {

controllers[i] = device;

break;

}

}

}

 

if (!controllers[1] || !controllers[2] || !controllers[3]) {

throw "ERROR: cannot find SCSI controllers!";

}

 

// hard disks

System.log("Connecting disks to new SCSI controllers");

var deviceConfigSpecs = [];

for each (var device in vm.config.hardware.device) {

var label = device.deviceInfo.label;

if (label.search("Hard disk [3-7]") >= 0) {

System.log("Found " + label);

var disk = VcPlugin.deepClone(device);

switch (label) {

     case "Hard disk 3":

               System.log("Moving to SCSI(1:0)");

               disk.controllerKey = controllers[1].key;

               disk.unitNumber = 0;

break;

     case "Hard disk 4":

               System.log("Moving to SCSI(2:0)");

               disk.controllerKey = controllers[2].key;

               disk.unitNumber = 0;

break;

     case "Hard disk 5":

               System.log("Moving to SCSI(2:1)");

               disk.controllerKey = controllers[2].key;

               disk.unitNumber = 1;

break;

     case "Hard disk 6":

               System.log("Moving to SCSI(3:0)");

               disk.controllerKey = controllers[3].key;

               disk.unitNumber = 0;

break;

     case "Hard disk 7":

               System.log("Moving to SCSI(3:1)");

               disk.controllerKey = controllers[3].key;

               disk.unitNumber = 1;

break;

     }

var deviceConfigSpec = new VcVirtualDeviceConfigSpec();

     deviceConfigSpec.device = disk;

     deviceConfigSpec.operation = VcVirtualDeviceConfigSpecOperation.edit;

     deviceConfigSpecs.push(deviceConfigSpec);

}

}

var configSpec = new VcVirtualMachineConfigSpec();

configSpec.deviceChange = deviceConfigSpecs;

 

task = vm.reconfigVM_Task(configSpec);

===========================================


Viewing all articles
Browse latest Browse all 49146

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>