VMware Cloud Community
DizzyMurloc
Contributor
Contributor

Get virtual machines from vCACCAFE:BusinessGroup

Hi,

I'm new working with vRO and JS. I'm trying to get all VMs (VC:VirtualMachine) from a BusinessGroup (vCACCAFE:BusinessGroup). There is any way to relate this 2 object types??

Thanks in advance!

0 Kudos
3 Replies
barjinders
VMware Employee
VMware Employee

1) Create a new property on your business group with the value of businessGroup ID. I am passing it as a variable for the sample code. In your case it will be the actual businessGroupID
var businessGroupID = "123456847484923"
 
 
2) Workflow Input: vCACCAFEHost Data Type: vCACCAFE:VCACHost
 
3) Workflow Input: vcacIaaSHost  Data Type: vCAC:VCACHost
 
 
//Get all the resources from the cafe
var resources = vCACCAFEEntitiesFinder.getCatalogResources(vCACCAFEHost);
 
//Declare an array to push your VMs
var bgVMs = [];
 
//Loop through each rescource and if its a VM, check the businessGroupID for match
 
for each (resource in resources) {
var reourceType = resource.resourceTypeRef.getLabel();
if ( reourceType == "Virtual Machine"){
var bindingId = resource.providerBinding.getBindingId();
var virtualMachine = Server.findForType("vCAC:VirtualMachine", bindingId);
var virtualMachineProperties = new Properties;
virtualMachineProperties = <<Write an action that uses vcacIaaSHost to get the vCAC VM Properties>>
//Assuming you name the BG Property as businessGroupId
var vmBusinessGroupId = virtualMachineProperties.get("businessGroupId");
 
//Check if the businessgroup id of the VM in loop and your business group match. If there is a match push the VM in array.
if (vmBusinessGroupId == businessGroupID) {
bgVMs.push(virtualMachine.virtualMachineName);
}
}
}
 
//Log the array. 
System.log(bgVMs.toString());
0 Kudos
qc4vmware
Virtuoso
Virtuoso

There is likely a much better method to do this but you could stitch all of this together first get all the catalog resources for the subtentant of type virtual machine, get the vCACVm for each of the catalog resources, then get the vCenterVm associated with the vCenterVm.  Take a look at the attached actions.

0 Kudos
barjinders
VMware Employee
VMware Employee

There may be a better way of doing this but below solution is a quick and easy way:

1) Create a new property on your business group with the value of businessGroup ID. I am passing it as a variable for the sample code. In your case, it will be the actual businessGroupID
var businessGroupID = "123456847484923"

2) Workflow Input: vCACCAFEHost Data Type: vCACCAFE:VCACHost

3) Workflow Input: vcacIaaSHost  Data Type: vCAC:VCACHost


//Get all the resources from the cafe
var resources = vCACCAFEEntitiesFinder.getCatalogResources(vCACCAFEHost);

//Declare an array to push your VMs
var bgVMs = [];

//Loop through each rescource and if its a VM, check the businessGroupID for match

for each (resource in resources) {
var reourceType = resource.resourceTypeRef.getLabel();
if ( reourceType == "Virtual Machine"){
var bindingId = resource.providerBinding.getBindingId();
var virtualMachine = Server.findForType("vCAC:VirtualMachine", bindingId);
var virtualMachineProperties = new Properties;
virtualMachineProperties = <<Write an action that uses vcacIaaSHost to get the vCAC VM Properties>>
//Assuming you name the BG Property as businessGroupId
var vmBusinessGroupId = virtualMachineProperties.get("businessGroupId");

//Check if the businessgroup id of the VM in loop and your business group match. If there is a match push the VM in array.
if (vmBusinessGroupId == businessGroupID) {
bgVMs.push(virtualMachine.virtualMachineName);
}
}
}

//Log the array. 
System.log(bgVMs.toString());

0 Kudos