VMware Cloud Community
spride
Enthusiast
Enthusiast

Get vCAC:VirtualMachine from VC:VirtualMachine and vCAC:VCACHost

Seems like this would be something simple to do, but for some reason I'm not connecting the dots.  If I

have an Array of VC:VirtualMachine objects and a vCAC:VCACHost object, how can I easily/quickly get

the vCAC:VirtualMachine objects for those VMs?  Thanks.

4 Replies
sbeaver
Leadership
Leadership

You might already have an action to do that called "getvCACvmFromVCvm"  In case you do not have this action here is the code for your review.

var vCACvms = Server.findAllForType("vCAC:VirtualMachine");

var uuid = vcvm.config.uuid

var vcName = vcvm.name

for each (var vCACvm in vCACvms){

//System.log(vCACvm)

  if (vcName == vCACvm.VirtualMachineName){

  System.log("Resolved vCAC VM: " + vCACvm.VirtualMachineName);

  System.log(vCACvm);

  return vCACvm;

  break;

  }

}

Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**
qc4vmware
Virtuoso
Virtuoso

This is how I do it:

var Uuid = vCenterVm.config.instanceUuid;

var vCACVms = Server.findAllForType("vCAC:VirtualMachine", "VMUniqueID eq '" + Uuid + "'");

System.log(vCACVms.length + " match uuid: " + Uuid);

for each (var vCACVm in vCACVms) {

    System.log("Resolved vCAC VM: " + vCACVm.virtualMachineName);

}

if (vCACVms.length > 1 ) throw "Too many matches for UUID: " + Uuid + ", there can be only one!";

return vCACVms[0];

spride
Enthusiast
Enthusiast

Thanks Steve!  I'll give it a shot.  I figured it was something as simple as that.

0 Kudos
spride
Enthusiast
Enthusiast

Thanks Paul.  I'll give this a shot as well.  Appreciate the quick response!

0 Kudos