VMware Cloud Community
dgberrid
Enthusiast
Enthusiast

Search for vCAC VirtualMachine based on vCAC Virtual Machine Properties as well as vCAC Entities Properties

Is there a way to find a vCAC VirtualMachine based on the linked VirtualMachine Properties as well as the linked vCAC Entity Properties? From what I have been able to gleen from poking around the vCAC Model I see that both vCAC VirtualMachines and there vCAC Entities have linked sets of Properties and the properties are different for both. I've attempted to diagram the situation below...

vCAC VirtualMachine   <---------> vCAC VirtualMachine Entity

          |                                                          |

          |                                                          |

         V                                                         V   

 Properties                                                Properties

          |                                                          |

          |                                                          |

         V                                                         V

Search Prop X                                         Search Prop Y

I have developed a working solution in vRO to query the property entity set for all property entities with a similar property and from this set I get the linked VirtualMachine from each property entity and further filter based on the VirtualMachine's linked properties. This is very convuluted. Is there a simpler way to do this? Maybe using Server.findAllForType with a slick xpath query?   

0 Kudos
2 Replies
jasnyder
Hot Shot
Hot Shot

It's not super clear from your description which way you want to start and where to end up.  Which properties from the vCAC:VirtualMachine object are you saying you're searching and how are you doing that?

For the entity searches, there are some OOTB actions that sort of dance around what I think you're doing.  These are com.vmware.library.vcac.getVirtualMachinePropertiesByPropertyName and com.vmware.library.vcac.getPropertyFromVirtualMachine.  There may be some others in that module that would help, or maybe you're already using them.

Any time I've had the pleasure of working with the management model entities it's always convoluted, and if you attempt to recurse links it ends up going circular on you.  So I'm guessing it probably isn't going to get much cleaner than you have.  But if you can provide some extra info on the use case, I'll see what I can work out.  I'm not sure I'm tracking on the left side of your diagram, where are those properties and how are you accessing them?  The right side I assume is using the ManagementModelEntities.svc model and the VirtualMachines and VirtualMachineProperties entity sets.

And are you saying the properties on the left have the same key/value pairs or just something "similar" as you said.

Also important is what version of vCAC/vRA are you using?

0 Kudos
dgberrid
Enthusiast
Enthusiast

Sorry about the confusion. After a little more time working on this I've come to find out my diagram is wrong. The properties I referenced in the diagram above from the same property set 'VirtualMachineProperties' and the Entity was a VirtualMachineProperties Entity, not a VirtualMachine Entity.

The use case I was trying to solve for was as follows...

"We build a cluster of three VMs. The name of the cluster is determined dynamically at run time from a cmdb. The scripts that add all three servers to the cluster are run on all three servers and requires each server to 'know' what cluster they are to be added. One of the servers is interacting with the cmdb to determine the next cluster name. This node has a property X which tells the orchestrator code that this node is the one getting the next cluster name.The others must be able to access the cluster name which is added to the vCAC properties of the node interacting with the cmdb."

To do the last part the other nodes need to know what VMs are part of the deployment they are members of so they can search for a VM in their deployment that has the property X and grab the cluster name off of that VMs vCAC properties.

I was able to find all VMs in a deployment by searching for all VirtualMachineProperties with the same __Cafe.Root.Request.Id using the 'readModelEntitiesByCustomFilter' which is a method hanging off of the vCACEntityManager. I got the idea for this from here...

Finding Virtual Machines based on a property

The VirtualMachineProperties table contains all VM properties and has the following schema...

Id, PropertyName, PropertyValue, IsHidden, IsRuntime, IsEncrypted, Link-->VirtualMachine

So once I had all of the VirtualMachineProperties entries that had a PropertyName of __Cafe.Root.Request.Id and a PropertyValue of (whatever the request id was) I followed the link to each of the VirtualMachines retrieving the VirtualMachineProperties tied to that VM to determine which one was the Primary and grab the cluster name off of it.

My initial question was about how can I used the 'readModelEntitiesByCustomFilter' to search for VirtualMachines that have a particular property X AND a a particular __Cafe.Root.Request.Id? Something like this...

var searchProps = {prop1: X;

                                __Cafe.Root.Request.Id: blahGuid}

var vms = vCACEntityManager.readModelEntitiesByCustomFilter(vcachost.id, 'ManagementModelEntities.svc', "VirtualMachine", searchProps ,null);

I now know this will not work because the two properties 'prop1' and '__Cafe.Root.Request.Id' are not in the properties of the VirtualMachine. They exist in the VirtualMachineProperties table and are linked back to the VirtualMachine!

What a headache!!

0 Kudos