VMware Cloud Community
Lie_DW
Contributor
Contributor

Virtual Machine search - exclude SRM placeholders

Hi again!

Using vRA 7.4 and I'm a vRA/vRO noob Smiley Wink

I created a XaaS blueprint with an orchestrator workflow to create (and schedule) a snapshot of a machine, after an approval from our side.

Since it will be used by users who do not have the knowledge of vmware, I don't like the Tree selection.

I wanted to have a search box but the search box will give 2 entries for a machine, one for the real vm and one for the srm placeholder. You can't see the difference so if a user selects the srm placeholder, the workflow will fail.

I thought about a vro action where it would list all the VMs where the managedBy is not com.vmware.vcDr but a dropdown with 1000 machines is not a good solution.

Does anyone have an idea on how to do this? I have another workflow to reset the CBT (for our backup crew) and it's the same thing, a tree search. For them it will probably work but a search box with only 1 entry would be better.

I already got this piece of code but I'm not sure if i'm on the right track

var vms = VcPlugin.getAllVirtualMachines();
for each (var vm in vms) {

if (vm.name == vmName && vm.config.managedBy.extensionKey != "com.vmware.vcDr") {
    return vmName;
}
}

Thanks!

0 Kudos
3 Replies
Lie_DW
Contributor
Contributor

So I found a solution, not sure if it's the right one but it works Smiley Happy

I get all datastores and exclude the datastores where the placeholders are located. Then I get all the VMs from those datastores:

var allVMs = new Array();
var AllDatastores = VcPlugin.getAllDatastores();
for(var i in AllDatastores)
{
if((AllDatastores[i].name).toLowerCase().indexOf("placeholder") < 0)
{
allVMs = allVMs.concat(System.getModule("com.vmware.library.vc.datastore").getAllVMsOfDatastore(AllDatastores[i]));
}

}

return allVMs.sort();

Now, I have over a 1000 VMs, this will not look pretty in a dropdown so I looked at the Field Picker but I think there is a bug. It does not search the values and instead is giving me a list with all the VMs like a normal dropdown.

Anyway, I learned a lot today and I think I added +1 to my javascript skill level ^^

0 Kudos
qc4vmware
Virtuoso
Virtuoso

If you use an action you may want to try this to lookup by name

VcPlugin.getAllVirtualMachines(null, "xpath:name='" + vmName + "'");

In theory it should be pretty fast.

You may also want to load lists of just text arrays for selection as performance will be much better (I've found) for large lists of things.  You end up having to locate the object based on those choices during the workflow execution but may improve user experience dramatically.

0 Kudos
Lie_DW
Contributor
Contributor

Hi,

I use that to have a validation to check if the machine already exists but it does not filter the SRM placeholders. When youget 2 entries, it's impossible to see if the one you select is the placeholder or not and the request will fail.

0 Kudos