Quantcast
Channel: VMware Communities : All Content - vRealize Automation Tools
Viewing all articles
Browse latest Browse all 9859

Resource Actions / mapToVCVM Bug !

$
0
0

All,

 

I've been working through a bug lately with this action.

 

- Create Resource Action through the vRA ASD Resource Actions tab

- Execute actions against items in your vRA Inventory

- Action doesnt execute on the resource you selected in the inventory

 

What is happening is before the form loads, vRA runs a orchestrator action (com.vmware.vcac.asd.mappings.addToVCVM) to find the Vc:VirtualMachine object you've initiated an action against so it's properties are available to the form....well that code looks like this:

 

var type = 'VC:VirtualMachine';
var vmMoRefId = vmProperties.get('EXTERNAL_REFERENCE_ID');


var foundVms = System.getModule("com.vmware.vcac.asd").findVcObjectsByMoRefId(type,vmMoRefId);


if (!foundVms || foundVms.length == 0) {
  System.warn('No VMs with MoRefId ' + vmMoRefId + ' were found');  return null;
} else {  if (foundVms.length > 1) {       System.warn('More than one VM with MoRefId ' + vmMoRefId + ' was found');  }  return foundVms[0];
}

 

This code

 

System.getModule("com.vmware.vcac.asd").findVcObjectsByMoRefId

 

Loops through all vCenter connections you have in vRO, looking for VM's that match the moid of the item in vRA you ran the action against.

 

The problem occurs in the last block of code when if more than one VM is found with the morefid, it simply warns the console, then returns the first one in the array!!!!! Consider the example where you multiple vCenters added to vRO, there is potentially overlap of morefid's (in fact i ran some queries i have over 300 overlaps). What this means is when you run an action and a morefid is shared with another VM in your vCenter world, this code doesn't actually check that the item you searched for, was the correct one. It is running the action on a random VM that matches the vmoid which may or may not be the one that you selected in the items list.

 

I've modified this code to actually check the VM we select is the one we searched for:

 

var type = 'VC:VirtualMachine';
var vmMoRefId = vmProperties.get('EXTERNAL_REFERENCE_ID');


var foundVms = System.getModule("com.vmware.vcac.asd").findVcObjectsByMoRefId(type,vmMoRefId);


if (!foundVms || foundVms.length == 0) {
  System.warn('No VMs with MoRefId ' + vmMoRefId + ' were found');  return null;
} else {  if (foundVms.length > 1) {  System.warn('More than one VM with MoRefId ' + vmMoRefId + ' was found');  }  var MachineName = vmProperties.get("MachineName").toLowerCase();  var ret = null;  for each(var item in foundVms)  {       System.log("\tChecking: " + item.name);       if(MachineName.indexOf(item.name.toLowerCase()) > -1)       {            System.log("\t\tMatch VM Name: " + item.name);            ret = item;            break;       }  }  if(ret == null)       throw("Couldn't find the VM in vCenter");  return ret;
}

 

 

Any word on if this a known bug? Or if its resolved in a later release of the workflows that I may not be running?

 

Thanks,

 

James


Viewing all articles
Browse latest Browse all 9859

Trending Articles