VMware Cloud Community
aslk5
Enthusiast
Enthusiast

what is the fastest way to search for an object?

I have a workflow that needs to search for a specific portgroup by partial name. I know the vcenter and cluster it should be in. The largest venter environment has roughly 1600 portgroups across several clusters. WIth all the vcenters in vRO that number might be closer to 3000.

The first time I ran the workflow (option 1 below) it worked fine except is was a bit slow (took about 1.5 minutes). Subsequent runs were faster/almost instance so I think it might just be due to cache. I would prefer to have things more consistent and avoid random delays if possible.

Does anyone have any advice on which would be the best way in terms of speed? Is there's a 5th option that's better?

Option 1:

var vc = cluster.sdkConnection;

var filter = "myclustername";

var filter2 = "-xyz-"

var results = vc.getAllDistributedVirtualPortgroups(null,"xpath:name[contains(.,'" + filter + "') and contains(.,'" + filter2 + "')]");

There should only be 1 or 2 hits in the results so checking what I got back is fine.

Option 2:

var filter = cluster.name + ".*" + "-xyz-";

var re = new RegExp(filter, "i");

var allNetworks = cluster.network;

var results = new Array();

for each (network in allNetworks){

     if (network.name.search(re) != -1)

     results.push(network);

}

Option 3:

Server.findAllForType

I didn't try this as I figured it would try to search all vcenetrs in vRO so less efficent than option 1 and 2 where I can limit the scope of my search.

Option 4:

Using the property collector (I copy/pasted the samples workflows into an action to return the data I want). I can search for:

targetType = Network

properties = name

filter = mycluster-xyz-

but there's two issues:

1) Is there a way to search for wildcards? In some cases I might have mycluster-xyz- and in others I will have mycluster-123-xyz-. The first two options seem to handle this just fine but I don't see how to do this with property collector.

2) When I run my action twice in a row, the results from run 1 seem to appear in the results from run 2. For example:

run 1: looks for "mycluster-xyz-"

run 2: looks for "mycluster-abc-"

when I output the results, run 1 just has the xyz item while run 2 shows me both xyz and abc.

Reply
0 Kudos
0 Replies