VMware Cloud Community
BWinchell
Enthusiast
Enthusiast
Jump to solution

Add extra disks to VM

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

1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee
Jump to solution

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 Smiley Happy

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);

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

2 Replies
Burke-
VMware Employee
VMware Employee
Jump to solution

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 Smiley Happy

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);

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
BWinchell
Enthusiast
Enthusiast
Jump to solution

Thanks Burke,

Worked great.  Here is the simple workflow for others.

(I owe you a beer.  You can collect at VMWorld Smiley Happy)

Reply
0 Kudos