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

Re: How to move extra disks to second controller

$
0
0

Hi,

 

Try the following code. It is almost verbatim copy of yours, with only differences on lines 11,12,52,53 and 57. What is changed it that the array property deviceChange of variable deviceConfigSpecs is not modified directly, but the spec values are accumulated in a separate array variable and at the end this array is assigned at once.

 

If I remember correctly there could be some issues with direct modification of properties of type Array.

 

var runtime = vm.config 
var hardware = runtime.hardware; 
var devices  = hardware.device;    
var foundController = false; 
var correctControllerType = false;  
var disks = [];  
var deviceConfigSpecs = new VcVirtualMachineConfigSpec(); 
//deviceConfigSpecs.deviceChange = new Array(); 
var devChange = new Array();  
System.log("deviceChange: " + deviceConfigSpecs.deviceChange);  
//System.log("Number of Devices: " + devices.length);  
for (var i in devices) {   if (((devices[i].deviceInfo.label).indexOf("Hard disk 1") == -1) && ((devices[i].deviceInfo.label).indexOf("Hard disk") > -1)) {     System.log(i + " " + "deviceInfo Label: " + i + " - " + devices[i].deviceInfo.label);     System.log(i + " " + "Backing: " + i + " - " + devices[i].backing);     System.log(i + " " + "ControllerKey: " + i + " - " + devices[i].controllerKey);     disks.push(devices[i]);   } 
}  
if (disks.length > 0) { // Multiple disks found   for (var i in devices) {     if ( devices[i].deviceInfo.label == "SCSI controller 1") {       var controllerType = devices[i].deviceInfo.summary;         if (controllerType.indexOf("VMware paravirtual SCSI") > -1) {         System.log("Found Correct Controller for Disks");         var deviceControllerKey = devices[i].key;       }     }   }    if (deviceControllerKey) {     var unit = 1;      for (var i in disks) {       System.log("Checking Controller Key: " + deviceControllerKey + " for Disk: " + disks[i].deviceInfo.label + " with key: " + disks[i].controllerKey);       if (true) { // (disk[i].controllerKey != deviceControllerKey) {         var deviceConfigSpec = new VcVirtualDeviceConfigSpec();         deviceConfigSpec.operation = VcVirtualDeviceConfigSpecOperation.edit;         deviceConfigSpec.device = new VcVirtualDisk;         deviceConfigSpec.device = disks[i];         deviceConfigSpec.device.controllerKey = deviceControllerKey;         deviceConfigSpec.device.unitNumber = unit++;         //deviceConfigSpecs.deviceChange.push(deviceConfigSpec);         devChange.push(deviceConfigSpec);         System.log("Settings Controller Key: " + deviceControllerKey + " for Disk: " + disks[i].deviceInfo.label + " - unit: " + unit);       }     }    deviceConfigSpecs.deviceChange = devChange;    task = vm.reconfigVM_Task( deviceConfigSpecs );   } 
} 

Viewing all articles
Browse latest Browse all 232319

Trending Articles



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