Is there a way to get a VC:VirtualMachine object (vCenter VM) that corresponds to a given vCloud:VM (vCloud Director VM)? It would be beneficial for a workflow I'm working on where I'm trying to use the Copy files from vCO to Guest.
Here is a more efficient way: Get a vCenter Virtual Machine from a vCloud VM
Just to get people thinking... I've started with a scriptable task to combine the vCloud:VirtualMachine ID & vCloud:VirtualMachine Name into it's equivalent in vCenter. (I probably don't need to have all those outputs, but it makes it easier to see what things are set to post run). The idea is once I have the vCloud VM name as a string, I will (somehow) be able to get a full list of VMs, then parse through each of them comparing their name to the vCloud_VM_String and when I have a match, I've got my winner.
Any thoughts?
Inputs:
vCloud_VM (vCloud:VM)
Outputs:
tmpName (String)
String tmpID (String)
UID_Start (number)
UID (String)
vCloud_VM_String (String)
Script:
tmpName = vCloud_VM.name;
tmpID = vCloud_VM.id;
UID_Start = tmpID.lastIndexOf(":");
UID = tmpID.substring(UID_Start+1,tmpID.length);
vCloud_VM_String = tmpName+" ("+UID+")";
I feel silly giving myself credit for the answer, but I think I have a very inefficient way of doing this. Building on my earlier script, I've thrown together a workflow that accomplishes the job.
The first script (get VCD:VM Str Name) is basically the same as my second post. I then invoke the getAllVirtualMachinesByFolderIncludingSubFolders action, with a hard coded (ugh, I know that's bad) folder corresponding to the root vCloud Director folder in vCenter - this results in a very large array of VC:VirtualMachines. I get the total number of VMs in that array, set a counter to the array.length, then start going through them one by one. The Compare this VC:VM script looks like this:
thisVC_VM = VC_VMs[num_VC_VMs];
VC_VM_String = thisVC_VM.name;
if (vCloud_VM_String == VC_VM_String){
System.log("----------------FOUND THE VM--------------");
found = true;
found_VC_VM = thisVC_VM;
}
If found is true, we exit out of the loop and dump the resulting VC:VirtualMachine to workflow out. If found is false, and there's more VC:VMs in the array (e.g. counter is greater than zero), decrease and go again. If for some reason the counter drops to zero and we still haven't found anything (I have no idea if that'll ever actually happen), I set an error message and exit with an exception.
The downsides: I loop through every. single. VM. This is painful at best, and incredibly slow at worst. If I could somehow get the vCloud:VirtualMachine's parent folder, I could limit my VC:VirtualMachine array and make things easier, but I'm not sure how to do that. Other than this massive inefficiency, I'm fairly happy with it. Any suggestions would be greatly appreciated.
Here is a more efficient way: Get a vCenter Virtual Machine from a vCloud VM