VMware Cloud Community
goldeneyez
Contributor
Contributor

XPath (AND) condition query

Hi

I am trying to retrieve Virtual Machines object while using 2 conditions and I would like to implement (AND) condition.

it's XPATH expression

and this is the list of XPath expression that I already tried to use (without success):

<code>

var XPath_query = "xpath:child::config/child::template[ . = true() ] and child::sdkConnection/child::about/child::instanceUuid[ . = '52980cec-f342-41cd-df32-a8f7d7a232d30' ]";

var XPath_query = "xpath:child::config/child::template[ . = true() ] and child::sdkConnection/child::about/child::instanceUuid[contains(.,'52980cec-f342-41cd-df32-a8f7d7a232d30')]";

var XPath_query = "xpath:config/template[ . = true() ] and sdkConnection/about/instanceUuid[ contains(.,'52980cec-f342-41cd-df32-a8f7d7a232d30') ]";

var XPath_query = "xpath:config/template[ . = true() ] and sdkConnection/about/instanceUuid[ contains(string(.),'52980cec-f342-41cd-df32-a8f7d7a232d30') ]";

var XPath_query = "xpath://[ config/template = true() and contains(string(sdkConnection/about/instanceUuid),'52980cec-f342-41cd-df32-a8f7d7a232d30') ]";

var XPath_query = "xpath://[ config/template = true() and contains(sdkConnection/about/instanceUuid,'52980cec-f342-41cd-df32-a8f7d7a232d30') ]";

var XPath_query = "xpath:[ config/template/. = true() and contains(sdkConnection/about/instanceUuid/.,'52980cec-f342-41cd-df32-a8f7d7a232d30') ]";

var XPath_query = "xpath://[ config/template/. = true() and contains(sdkConnection/about/instanceUuid/.,'52980cec-f342-41cd-df32-a8f7d7a232d30') ]";

System.log(XPath_query);

var VcVirtualMachine_Array = Server.findAllForType("VC:VirtualMachine",XPath_query);

System.log("Array Length: " + VcVirtualMachine_Array.length);

</code>

basically what I am trying to achieve is the following:

config/template should be true value

and

sdkConnection/about/instanceUuid should be equal to value of 52980cec-f342-41cd-df32-a8f7d7a232d30

thanks in advanced for the assistance

Reply
0 Kudos
8 Replies
iiliev
VMware Employee
VMware Employee

Hi,

The first variant should work (you can also remove child:: prefixes from it; I think they are redundant in this case).

var q = "xpath:config/template[ . = true() ] and sdkConnection/about/instanceUuid[ . = '52980cec-f342-41cd-df32-a8f7d7a232d30' ]";

It doesn't work for you most likely because the instanceUuid value 52980cec-f342-41cd-df32-a8f7d7a232d30 is not a valid UUID - its last part has 13 characters instead of 12.

Reply
0 Kudos
goldeneyez
Contributor
Contributor

Hi Ilian Iliev

1st thank you for the big assistance here in the forum.

I used fake UUID because I didn't want to reveal the real UUID here in the forum.

anyway. it doesn't work with the real UUID.

so to find out the source of the issue I have come into the conclusion that I need to execute XPath query without (AND) and to see if it accrual works before making complex query.

so I found that the basic 

so what I tried is the following:

var XPath_query = "xpath:sdkConnection/about/instanceUuid[ . = 'daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b' ]";

var XPath_query = "xpath:sdkConnection/about/instanceUuid[ . = daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b ]";

var XPath_query = "xpath:sdkConnection/about/instanceUuid[ contains(.,'daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b') ]";

var XPath_query = "xpath:sdkConnection/about/instanceUuid[ starts-with(.,'daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b') ]";

var XPath_query = "xpath:sdkConnection/about/instanceUuid[ string(.) = 'daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b' ]";

var XPath_query = "xpath:sdkConnection/about/instanceUuid[ . = string('daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b') ]";

var XPath_query = "xpath:sdkConnection/about/instanceUuid[ string(.) = string('daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b') ]";

var VcVirtualMachine_Array = Server.findAllForType("VC:VirtualMachine",XPath_query);

System.log("Array Length: " + VcVirtualMachine_Array.length);

and the output for each query was ZERO length.

thank in advanced for the assistance.

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

I tried the query with the 'and' condition in my 7.3 environment and it does work.

What versions of vRO and vCenter plug-in do you use?

Reply
0 Kudos
goldeneyez
Contributor
Contributor

very strange behavior and I will be glad to get explanation for better understanding the vSphere Plugin for vRO (vRealize Orchestrator).

when I am working with the vimHost/about/instanceUuid then it does works properly:

xpath:vimHost/about/instanceUuid[ . = 'daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b' ]

Array Length: 65

xpath:vimHost/aboutInfo/instanceUuid[ . = 'daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b' ]

Array Length: 65

when I work with sdkConnection/aboutInfo/instanceUuid it doesn't work properly:

[2018-11-04 12:01:47.721] [I] xpath:sdkConnection/aboutInfo/instanceUuid[ . = 'daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b' ]

[2018-11-04 12:01:49.429] [I] Array Length: 0

[2018-11-04 12:01:49.461] [I] xpath:sdkConnection/about/instanceUuid[ . = 'daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b' ]

[2018-11-04 12:01:51.251] [I] Array Length: 0

[2018-11-04 12:01:51.281] [I] xpath:sdkConnection/about/instanceUuid[ . = daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b ]

[2018-11-04 12:01:52.936] [I] Array Length: 0

[2018-11-04 12:01:52.937] [I] xpath:sdkConnection/about/instanceUuid[ contains(.,'daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b') ]

[2018-11-04 12:01:54.666] [I] Array Length: 0

[2018-11-04 12:01:54.697] [I] xpath:sdkConnection/about/instanceUuid[ starts-with(.,'daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b') ]

[2018-11-04 12:01:56.363] [I] Array Length: 0

[2018-11-04 12:01:56.628] [I] xpath:sdkConnection/about/instanceUuid[ string(.) = 'daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b' ]

[2018-11-04 12:01:58.409] [I] Array Length: 0

[2018-11-04 12:01:58.440] [I] xpath:sdkConnection/about/instanceUuid[ . = string('daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b') ]

[2018-11-04 12:02:01.420] [I] Array Length: 0

[2018-11-04 12:02:01.452] [I] xpath:sdkConnection/about/instanceUuid[ string(.) = string('daa7af3d-d0f6-4dc2-8baf-8e64e9438b8b') ]

[2018-11-04 12:02:03.154] [I] Array Length: 0

Reply
0 Kudos
goldeneyez
Contributor
Contributor

vRO version: 7.2.0.4629841

vSphere vCenter Plugin: 6.5

the vCenter Server versions (not the Plugin within vRO) are: 6.0.something

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

Oh, I see.

vRO 7.2 and older version have a different implementation (different codebase) of vCenter plug-in, possibly with some minor differences in XPath support, so this would explain why a XPath query that works on my 7.3+ does not work on 7.2

Let me check if I can find a 7.2 environment to test it.

Reply
0 Kudos
goldeneyez
Contributor
Contributor

one more question I have is regarding using the Finder Object.

for example the following:

https://www.vmware.com/support/orchestrator/doc/vro-vsphere60-api/html/VirtualMachine.html

according to this document. I supposed to have the ability to make a search base on the following Properties:

isTemplate

vimHost

How to make a search based on

Finder Object:

VC:VirtualMachine

?

Does the following is the correct:

this return everything (ALL VMs exist on all vCenter Servers) and it doesn't filtering the list (I am not getting the expected output I want):

var VcVirtualMachine_Array = Server.findAllForType("VC:VirtualMachine","isTemplate eq true");

System.log(VcVirtualMachine_Array.length);

this return everything (ALL VMs exist on all vCenter Servers) and it doesn't filtering the list (I am not getting the expected output I want):

var VcVirtualMachine_Array = Server.findAllForType("VC:VirtualMachine","isTemplate eq 'true'");

System.log(VcVirtualMachine_Array.length);

this return everything (ALL VMs exist on all vCenter Servers) and it doesn't filtering the list (I am not getting the expected output I want):

var VcVirtualMachine_Array = Server.findAllForType("VC:VirtualMachine","isTemplate eq true()");

System.log(VcVirtualMachine_Array.length);

this return everything (ALL VMs exist on all vCenter Servers) and it doesn't filtering the list (I am not getting the expected output I want):

var VcVirtualMachine_Array = Server.findAllForType("VC:VirtualMachine","isTemplate eq 'true()'");

System.log(VcVirtualMachine_Array.length);

thanks in advanced for the assistance

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

I don't see such type of queries listed on the provided link.

vimHost and sdkConnection are two special extension properties that does not exist in the vCenter object model but instead are injected by the vCenter plug-in. Both properties returns the same value. I'm not sure why one of them work with XPath queries and the other doesn't; perhaps there is some additional registration needed in vCenter plug-in but I'm not that familiar with the plug-in implementation to tell for sure.

So if one of the properties works properly, then use it in your XPath queries. If you want, you can open a support request for the other property.

Reply
0 Kudos