VMware Cloud Community
bdamian
Expert
Expert
Jump to solution

VCPlugin.getAllVirtualMachines with filters

Hi all,

I'm trying to find the correct way to use getAllVirtualMachines with filters. I want to get the list of all vms bloqued by question as is shown in the screenshot:

pastedImage_0.png

I guess that the same result is possible using VcPlugin.getAllVirtualMachines(string[] additionalPropertyFilterrs, String query) but I cannot find the correct grammar for that.

Get all VMs and then check for "vm.runtime.question" is very SLOW.

Any ideas?

Thanks a lot

D.

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
qc4vmware
Virtuoso
Virtuoso
Jump to solution

Try this for your xpath filter

xpath:runtime[question] or xpath:runtime/question

View solution in original post

Reply
0 Kudos
7 Replies
qc4vmware
Virtuoso
Virtuoso
Jump to solution

Try this for your xpath filter

xpath:runtime[question] or xpath:runtime/question

Reply
0 Kudos
bdamian
Expert
Expert
Jump to solution

Thanks but those articles are about vRealize Automation and I need to filter vCenter VMs with the vCenter Plugin.

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
Reply
0 Kudos
bdamian
Expert
Expert
Jump to solution

Hi qc4,

Using

var vms = vcenter.getAllVirtualMachines(null , 'xpath:runtime[question]');

it returns the correct list of VMs, but I guess the filter is applied in the Orchestrator side because is too slow compared with the filter in the vCenter console.

It's been very hard for me to find some example with "filters" instead of xpath.

I'll keep looking...

D.

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

I think filter parameter is just specifying a list of virtual machine object property names to be fetched initially. But I might be wrong.

qc4vmware
Virtuoso
Virtuoso
Jump to solution

If you mean the first option additionalPropertyFilters from what I understand its a hint on what information to search.  Try setting it to ["runtime/question"].  Guidance I've seen is to set this to any fields included in your query.  Might speed things up if the query doesn't take into account any of the other information in the query.

Reply
0 Kudos
qc4vmware
Virtuoso
Virtuoso
Jump to solution

Also, if you can create a view you like in vCenter you can retrieve that via vRO.  I've done it in the past but don't remember exactly how to do it.  Search the api in vRO for "view" and look at what comes up under the VC plugin.  I think its VC:View or VC:ViewManager and associated scriptable objects.  If you are not familiar with the Managed object browser for vCenter take a look at that as you can learn a lot about how the vCenter api puts things together by clicking through that.  Most things in the MOB have a vRO equivalent.  Also, the latest versions of vCenter also have the Code Capture feature which will track what you are doing in vCenter and output equivalent code in PowerCLI which you should be able to translate to vRO pretty easily or make a call out to powershell from vRO.  I used this a ton back in the day when it was known as Onyx but haven't tried this evolution.  Bummer it doesn't also include vRO code (it used to) but it is generally pretty easy to transform it.

If the view works for you you'll just have to write a small wrapper to iterate through all the sdkConnections in vRO to grab from all vCenters.  You might even try that with the filter you've confirmed works.  A lot of the time busting it up into smaller chunks improves performance.

Paul