Resolve vRA/vCAC VM to vCenter VM

I wrote this post some time ago but I felt that it didn’t include some other use cases where you would want to resolve a vCenter virtual machine. I also previously used code that was provided by the vRO appliance that I wasn’t too keen on (logging was a bit light and there was code to search using the BIOS UUID, which we don’t care about). I have therefore updated this post to reflect the following use cases:

  • Find the vCenter VM by its instance Uuid when using the Event Broker;
  • Find the vCenter VM by its instance Uuid on a specific vCenter Server;
  • Find the vCenter VM by its name, on a specific vCenter Server and a specific folder;
  • Find the vCenter VM by its MoRef id on a specific vCenter Server;

Hopefully, there should be enough code provided here to help you achieve your goal no matter what your scenario. However, if you need something different, then feel free to contact me and I will try to help.

You can find the package containing all the code here.

Find the vCenter VM by its instance Uuid when using the Event Broker

If you want to perform configuration tasks against a vCenter VM during the deployment process or even for Day 2 operations, then you will need to resolve the vRA managed VM to a vCenter VM (of type VC:VirtualMachine) in your vRO workflows. Assigning vSphere Tags or Custom Attributes is a good use case for this.

The vRA/vCAC entity in the database has a property (VMUniqueID), which matches the vCenter Virtual Machine’s instance Uuid. We can therefore use this value to locate the vCenter VM. But in order to get this property, we first need to resolve the vCAC Entity. We can do this using the machine id that is sent by the Event Broker.

If you are unsure how to use the Event Broker, then I recommend you read this blog post, which covers it in detail: https://theithollow.com/2016/02/08/vrealize-automation-7-subscription.

We should now have a workflow that is ready to be used by the Event Broker Subscription, with an input of type ‘Properties’ (The name of the variable doesn’t matter). Our first action on the Workflow will retrieve the vCAC Entity id. Don’t worry if you find any of this difficult to follow as I’ll provide the workflow solution as part of the package included in the link at the beginning of this post.

getVirtualMachineIdFromEbsPayload

Now that we have the virtual machine id from the event broker, we need to query for the vcac virtual machine entity (this is the vm object within the vRA IaaS database). The following Actions may require the vCAC Host to be provided as an input and also make use of additional helper actions. All of these will be provided in the package included in the link at the beginning of this post.

getVirtualMachineEntitybyVirtualMachineId

Now that we have the vCAC virtual machine entity, we need to retrieve the value for the ‘VMUniqueID’ property, which is the vCenter VM instance uuid.

getVmUniqueIdFromVirtualMachineEntity

At this stage we should finally have the vCenter VM instance uuid. We now need to make use of a final action that will use the vCenter vRO plugin, to search all the vCenter Server endpoints, for the virtual machine.

findVcVmByInstanceUuid

Here is what the workflow would look like. Remember, this is a sub-workflow that you would add to your master event broker subscribed workflow.

Get VC Virtual Machine from vRA EBS

You can now perform any scripting that you want against this VM and the changes will be reflected on the VM in vCenter.

Find the vCenter VM by its instance Uuid on a specific vCenter Server

I use these actions quite regularly in standard (non-event broker) workflows. When I am working with backup, DR or other solutions that require the vCenter VM, I like to locate these on the target vCenter Server and not search through all the endpoints. The reason for this is that 1) it’s quicker (not really a good enough reason though) and 2) I may have VMs across multiple vCenters with the same instance uuid.

The first action I have will dynamically discover the vCenter endpoint based on a site identifier. I include a site identifier in the vCenter Server hostname, which I use for the lookup. You may want to modify this action so that it better suites your requirements for dynamic discovery.

getVcenterSdkBySiteId

findVcVmByInstanceUuidOnVcenterSdk

Find the vCenter VM by its name, on a specific vCenter Server and a specific folder

I had a requirement to search for a vCenter VM on the same vCenter Server when performing same site recoveries with EMC backups or Zerto. The issue I had was that there would be an existing VM with the same instance uuid and even the same hostname, but the VMs would be located in different folders (the target folder and the temporary recovery folder). Once a restore had been completed, I needed to move the VM from the temporary recovery folder to the target folder and also run some additional workflows to restore tags, custom attributes, etc.

This action searches by the VM name, which is safe enough when targeting a specific folder. This helps locate the recovered VM that might have been restored with a different instance uuid. You could also modify this Action to search by the instance uuid if you so wish by adapting code from the previous sections.

Note that you can get the code to discover the vCenterSdk in the previous section ‘Locate the vCenter VM by its instance Uuid on a specific vCenter Server’, above.

findVcVmByInstanceUuidOnVcenterSdkInFolder

Find the vCenter VM by its MoRef Id on a specific vCenter Server

I had yet another requirement to search for a vCenter VM by its MoRef ID. This was because I was working with Zerto, which stores the MoRef Id as part of the Zerto vm id. I needed to be able to discover the vCenter VM using this MoRef.

Note that you can get the code to discover the vCenterSdk in the previous section ‘Locate the vCenter VM by its instance Uuid on a specific vCenter Server’, above.

findVcVmByMorefIdOnVcenterSdk

That was a lot of content and I hope you find useful. A link to the package containing all the code and workflows is included at the beginning of this post. As always, please contact me through Drift and I’ll do what I can to help!

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Rama Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Rama
Guest
Rama

You are the best.. thank you for your great work and sharing.