VMware Cloud Community
tschoergez
Leadership
Leadership
Jump to solution

Apply filter to getAllVmFolders()

Hi,

for the getAllVmFolders() method of VcPlugin and SDKConnection there are the two Parameters available:

additionalPropertyFilters (array of String)

query(String)

Can anybody give an example, how to use these?

(In my case I have several SDKConnections and several Datacenter in there and I need only Folders from one special Datacenter)

thanks in advance!

Cheers ,

joerg

Reply
0 Kudos
1 Solution

Accepted Solutions
kspirov
VMware Employee
VMware Employee
Jump to solution

Hello and happy new year! I am sorry to hear for the difficulties, caused by this example.

1. The solution is the following - just write the same search pattern without // and it will work.

The problem is in //  - // - selects nodes in the document from the current node that match the selection no matter where they are. The using of // is bad idea for production, this means all object tree will be traversed (on bean level) and will make a lot of remote calls.

2. The VCO team will do the following for vCO 4.2

1) The lack of documentation problem will be fixed

2) This concrete use case will be prevented on code level, because it is totally unacceptable.

3. Important: If you called such workflow, you will have difficulties to terminate it, because the XPath method call is beyond the Rhino level. If the workflow is with server restart behavior - resume workflow run, please make sure you changed it to "do not resume workflow run" before restarting.

Finally about the first parameter - it is just a hint, the system will give the same results with and without it.  It  allows to specify the properties, that will be added to the default property filter. This will prevent additional calls to the remote server. If you pass null (or empty array) it will still load some properties by default. You can see them by looking for [FiltersManager] in the console outpuit. It is a good idea to specify in the array the same properties that participate in XPath search.

Kind regards

Konstantin Spirov, vCO team member

View solution in original post

Reply
0 Kudos
6 Replies
admin
Immortal
Immortal
Jump to solution

Hi Joerg,

i have the same question! Smiley Happy There is nothing to find for the filter descriptions.

best regards

Christian

Reply
0 Kudos
Andreas_Diemer
Enthusiast
Enthusiast
Jump to solution

Hi Jörg,

i just wrote in http://communities.vmware.com/thread/293157?tstart=0 a little bit about the filtering.

In http://www.vmware.com/pdf/PortingGuide201.pdf on page 20 a sample structure is described.

For XPath I got my informations from here: http://blogs.sun.com/rajeshthekkadath/entry/xpath_identifying_xpath_of_a

As i mentioned i will need a little time for myself to figure it out Smiley Happy (next blown weekend)

Till sunday...

-


Regards,

don't forget: award points to helpful answers

visit &

------ for correct and / or useful answers please award points visit http://www.vcoteam.info & http://mighty-virtualization.blogspot.com
Reply
0 Kudos
Andreas_Diemer
Enthusiast
Enthusiast
Jump to solution

Hi Jörg,

it takes a long time to get this - and it is only the second (not helpful) half:

The second (XPath) parameter could be used to filter the result at vCO side Smiley Sad. For this there is no real advantage in performance. It is like filtering the array on your own by script.

var Pattern = 'yourVMname';
var XPath = "xpath://name[starts-with(.,'"  + yourVMname +"')]";
var VMs  = VcPlugin.getAllVirtualMachines(null, XPath);

The snippet returns an array with all VMs starting with "Pattern".

Actual I'm testing which XPath are supported (and does make sense Smiley Wink).

For the first parameter, which is used at vCenter side, I've got no information till now - sorry. This one will reduce time & bandwidth.

Regards, Andreas

------ for correct and / or useful answers please award points visit http://www.vcoteam.info & http://mighty-virtualization.blogspot.com
tschoergez
Leadership
Leadership
Jump to solution

Hi Andreas,

I got the same information last week, unfotunately my code

var searchName = 'VC';

var str = "xpath://name[starts-with(.,'"  + searchName +"')]";

var vms  = VcPlugin.getAllVirtualMachines(null, str);

...crashes the vCO-Server (it hangs in a neverending loop with lot of following errors in Server.log):

2010-12-20 17:17:04.159+0100 WARN [VimSession] invokeWebServiceOperation() [vcoscript@https://vc41.vmlab.local:443/sdk/Main#1ddeda00].createFilter --> InvalidProperty : 'network'
2010-12-20 17:17:04.159+0100 WARN [FiltersManager] createPropertyFilter() --> [vcoscript@https://vc41.vmlab.local:443/sdk/Main#1ddeda00, Nb filters used 143] --> Property name 'network' was not found by VirtualCenter
2010-12-20 17:17:04.159+0100 WARN [FiltersManager] createPropertyFilter() --> Empty filter, aborting
2010-12-20 17:17:04.159+0100 ERROR [VimNetwork] getNetworks() --> Property 'network' not exists
2010-12-20 17:17:04.173+0100 INFO [LicenseTester] This vCenter server is licensed for vCenter Orchestrator Server
2010-12-20 17:17:04.177+0100 WARN [VimSession] invokeWebServiceOperation() [vcoscript@https://vc41.vmlab.local:443/sdk/Main#1ddeda00].createFilter --> InvalidProperty : 'network'
2010-12-20 17:17:04.178+0100 WARN [FiltersManager] createPropertyFilter() --> [vcoscript@https://vc41.vmlab.local:443/sdk/Main#1ddeda00, Nb filters used 143] --> Property name 'network' was not found by VirtualCenter
2010-12-20 17:17:04.178+0100 WARN [FiltersManager] createPropertyFilter() --> Empty filter, aborting
2010-12-20 17:17:04.178+0100 ERROR [VimNetwork] getNetworks() --> Property 'network' not exists
2010-12-20 17:17:04.179+0100 ERROR [VimSession] getAccountManager() -->
java.lang.NullPointerException
at com.vmware.vmo.plugin.vi4.VimSession.getAccountManager(VimSession.java:1710)
at com.vmware.vmo.plugin.vi4.VimHost.getAccountManager(VimHost.java:234)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

......

(only way is to restart the vCO service complete)

For xpath, I'm pretty sure you know this great tutorial:

http://www.w3schools.com/xpath/default.asp

For the first parameter: It seems to be an array of Strings, where you can define the properties of the objects you want to get, if you dont need every sinlge information.

(I got an example with "runtime.powerState", but because of the error above I cannot test it yet).

Regards,

joerg

Reply
0 Kudos
kspirov
VMware Employee
VMware Employee
Jump to solution

Hello and happy new year! I am sorry to hear for the difficulties, caused by this example.

1. The solution is the following - just write the same search pattern without // and it will work.

The problem is in //  - // - selects nodes in the document from the current node that match the selection no matter where they are. The using of // is bad idea for production, this means all object tree will be traversed (on bean level) and will make a lot of remote calls.

2. The VCO team will do the following for vCO 4.2

1) The lack of documentation problem will be fixed

2) This concrete use case will be prevented on code level, because it is totally unacceptable.

3. Important: If you called such workflow, you will have difficulties to terminate it, because the XPath method call is beyond the Rhino level. If the workflow is with server restart behavior - resume workflow run, please make sure you changed it to "do not resume workflow run" before restarting.

Finally about the first parameter - it is just a hint, the system will give the same results with and without it.  It  allows to specify the properties, that will be added to the default property filter. This will prevent additional calls to the remote server. If you pass null (or empty array) it will still load some properties by default. You can see them by looking for [FiltersManager] in the console outpuit. It is a good idea to specify in the array the same properties that participate in XPath search.

Kind regards

Konstantin Spirov, vCO team member

Reply
0 Kudos
tschoergez
Leadership
Leadership
Jump to solution

YEAH!

That was the missing link. Now the filter from my examples above work as expected!

For the documentation: It would be great to have some real world examples:

getAllDatastores which are inaccessible, or which are type nfs

getAllVirtualMachines which are Powered on

....

to 3.) Yep, I learned this the hard way 🙂

I do not understand the idea of the first parameter completely yet, but now at least I can continue playing around!

Thank you very much, Konstantin!

Cheers,

Joerg

Reply
0 Kudos