3 Replies Latest reply on Jul 15, 2019 4:56 PM by barjinders

    Get virtual machines from vCACCAFE:BusinessGroup

    DizzyMurloc Lurker

      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!

        • 1. Re:Get virtual machines from vCACCAFE:BusinessGroup
          barjinders Novice
          VMware Employees
          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());
          • 2. Re: Get virtual machines from vCACCAFE:BusinessGroup
            qc4vmware Master

            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.

            • 3. Re:Get virtual machines from vCACCAFE:BusinessGroup
              barjinders Novice
              VMware Employees

              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());