VMware Cloud Community
deadon1130
Contributor
Contributor
Jump to solution

vRO Custom Action - Excluding More than One Datastore

Hello,

We currently have a vRO (Shell Generator) of sorts to provision shells within our environment that can then be used to run through the MDT build sequence to build servers.  Currently our custom action will pull all datastores from a host in a selected cluster, exclude any datastore that has the name preface of 'SU'.  Once that is done a datastore is selected based off a bit of math that will take into account the new VM size and ensure a datastore is selected with sufficient space to build the shell.  I am by no means an expert in vRO javascript and admittedly I need to learn more about this language.  Can someone assist in adding in the fact we want to exclude any datastore that has the preface of 'SU' AND 'LD'?  This would then exclude any datastore from being selected as "Special Use" or "Local Disk".  Below is the snippet, thanks in advance and much appreciated!

}

dsarray.sort(function(a, b){

return parseFloat(b.summary.freeSpace) - parseFloat(a.summary.freeSpace);

});

return dsarray;

function addDatastore(datastores) {

for (var i in datastores) {

if (keys.get(datastores[i].sdkId) == null) {

keys.put(datastores[i].sdkId, datastores[i].sdkId);

if (datastores[i].name.match('SU')) {

continue;

} else {

var rawCap = (datastores[i].summary.capacity); //raw capacity of the datastore

var cap = Math.round(rawCap / 1024 / 1024 /1024); //rounded capacity in GB

var usableCap = (90 / 100) * cap; //90% of capacity

var rawpSpace = VcPlugin.getProvisionedSpace(datastores[i]); //gets raw provisioned space

var pSpace = Math.round(rawpSpace / 1024 / 1024 /1024); //rounded provisioned space in GB

var disk1size = Math.round(SysDiskSize)

var disk2size = Math.round(AppDiskSize)

var vmemsize = Math.round(MemSize / 1024)

var useableSpace = (usableCap - pSpace - disk1size - disk2size - vmemsize ); //Usable capacity minus provisioned and disk&ram

if (useableSpace > 50){ //any datastore that has more than 50GB usable is returned

dsarray.push(datastores[i]);

}

}

}

}

}

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Hejahida82
VMware Employee
VMware Employee
Jump to solution

If you just want to check for a datastore name containing either SU or LD then you just need to update one line in the code.

Change the following line

if (datastores[i].name.match('SU')) {

to be

if (datastores[i].name.match('SU')||(datastores[i].name.match('LD')) {

The || is the javascript operator for OR.

View solution in original post

0 Kudos
3 Replies
Hejahida82
VMware Employee
VMware Employee
Jump to solution

If you just want to check for a datastore name containing either SU or LD then you just need to update one line in the code.

Change the following line

if (datastores[i].name.match('SU')) {

to be

if (datastores[i].name.match('SU')||(datastores[i].name.match('LD')) {

The || is the javascript operator for OR.

0 Kudos
deadon1130
Contributor
Contributor
Jump to solution

Thank You for that info.  I have gone ahead and tried it and it seems to be working!  One note however was there is a missing closing ) in the line.

So it should read:

if (datastores[i].name.match('SU')||(datastores[i].name.match('LD'))) { 

0 Kudos
Hejahida82
VMware Employee
VMware Employee
Jump to solution

glad it worked, and good spot on the missing ). My mac was giving me all sorts of weird formatting as I tried to copy the line of code so it doesn't surprise me that something went missing!

0 Kudos