VMware Cloud Community
segadson
Contributor
Contributor

Finding the Next Free Spot on a VM to add a disk

I have a Scriptable task in which I am trying to find the next free SCSI target.  In my action I call a custom action (attached) which checks the VM disk to find the next free SCSI controller for example:
it checkes 0:0 - 0:3 SCSI Targets and say 0:2 is the first free one then it returns the free number.

var abort = false;

var SCSIController = 0;

for (i = 0; i <= 3; i++){

  for (var j = 0; j < scsiControllers.length; j++) {

  if ( i != scsiControllers[j].busNumber  ||scsiControllers[j].busNumber == undefined ){

  System.log("add new scsi disk");

  //SCSIController = i + 1;

  }

  else if (i == scsiControllers[j].busNumber){

  System.log("This is the SCISI " + scsiControllers[j].deviceInfo.label);

  //System.log("check if device is full");

  var scsiController = scsiControllers[j].busNumber;

  actionResult = System.getModule("net.jpmc.virtualfirst.standard").getNextScsiUnitNumber(vm,scsiController);

  abort = true;

  }

  }

  if (abort == false){break;}

}

System.log(SCSIController);

In my Scriptable task what I want to do is test 3 Scenerios:

1) Checks to find if there is a free SCSI Target within the range 0:0 - 0:3 and if one is free then break out the loop and return the number (then add the disk, using the add disk workflow)

2) If all the free SCSI Targets are free and there is another disk then check that disk to find the next SCSI Target on the next disk (check this until the max SCSI Controllers) (then add the disk, using the add disk workflow until free)

3)If there isnt a free SCSI target and there isnt a new disk then add a new disk (I already have that workflow I just need to feed it a new diget)

Any Help would be great!

0 Kudos
0 Replies