Hello,
I am working on a workflow that will add disk(s) to an existing VM. I have looked at the default workflow "Add disk". The 2 inputs I cannot figure out is diskIndex and scsiBusNumber. How can I find these numbers? Is there a way to search the existing VM, extract the current backing info, then increase the diskIndex by 1 to create a loop for additional disks?
Any assistance or point me in the right direction.
Thanks
B
Hello B, give this a try... the workflow you mention is vCenter based so here:
Input: vm (VC:VirtualMachine)
Outputs: diskIndex (number), busNumber (number), datastore (VC:Datastore)
The diskIndex returned should be the next available diskIndex. The busNumber is the current busNumber of the disk already in the VM. And Datastore is the first Datastore referenced by the vm
Code:
scsiControllerKey = -1;
var devices = vm.config.hardware.device;
var bus = null;
if ( devices != null ) {
for ( device in devices ) {
if ( devices[device] instanceof VcVirtualBusLogicController || devices[device] instanceof VcVirtualLsiLogicController
|| devices[device] instanceof VcParaVirtualSCSIController || devices[device] instanceof VcVirtualLsiLogicSASController ) {
scsiControllerKey = devices[device].key;
bus = devices[device];
busNumber = devices[device].busNumber;
//System.log( "SCSI controller found. (Key: " + scsiControllerKey + ")" );
//System.log(" Bus Number: "+busNumber);
break;
}
}
}
var validNumbers = [0,1,2,3,4,5,6];
var devices = vm.config.hardware.device;
if ( devices != null ) {
for ( device in devices ) {
if ( devices[device] instanceof VcVirtualDisk) {
var u = devices[device].unitNumber;
for (i in validNumbers) {
if (validNumbers[i] == u) {
validNumbers.splice(i,1); // Remove number in use
}
}
}
}
}
var datastore = vm.datastore[0];
var diskIndex = validNumbers[0];
//System.log("diskIndex: "+diskIndex);
Hello B, give this a try... the workflow you mention is vCenter based so here:
Input: vm (VC:VirtualMachine)
Outputs: diskIndex (number), busNumber (number), datastore (VC:Datastore)
The diskIndex returned should be the next available diskIndex. The busNumber is the current busNumber of the disk already in the VM. And Datastore is the first Datastore referenced by the vm
Code:
scsiControllerKey = -1;
var devices = vm.config.hardware.device;
var bus = null;
if ( devices != null ) {
for ( device in devices ) {
if ( devices[device] instanceof VcVirtualBusLogicController || devices[device] instanceof VcVirtualLsiLogicController
|| devices[device] instanceof VcParaVirtualSCSIController || devices[device] instanceof VcVirtualLsiLogicSASController ) {
scsiControllerKey = devices[device].key;
bus = devices[device];
busNumber = devices[device].busNumber;
//System.log( "SCSI controller found. (Key: " + scsiControllerKey + ")" );
//System.log(" Bus Number: "+busNumber);
break;
}
}
}
var validNumbers = [0,1,2,3,4,5,6];
var devices = vm.config.hardware.device;
if ( devices != null ) {
for ( device in devices ) {
if ( devices[device] instanceof VcVirtualDisk) {
var u = devices[device].unitNumber;
for (i in validNumbers) {
if (validNumbers[i] == u) {
validNumbers.splice(i,1); // Remove number in use
}
}
}
}
}
var datastore = vm.datastore[0];
var diskIndex = validNumbers[0];
//System.log("diskIndex: "+diskIndex);