In part 1 I covered the steps to configure replication for a VM using vSphere Replication. Part 2 will cover how to find the SRM Protection Folder, Create a new Protection Group and add the VM to the Protection Group.
Creating a Protection Group
The SRM plugin provides two workflows for creating a protection group:
- Create Protection Group for Array Based Replication
- Create Protection Group for vSphere Replication
As I am using vSphere Replication the second workflow is appropriate for my environment. Looking at the workflow it contains a single action to create a protection group. The workflow needs the following inputs:
- protectionFolder – type SRM:ProtectionFolder
- name – type String
- description – type String
- vms – type Array/SRM:UnassignedReplicatedVm
The name and description will not pose any difficulties but the protectionFolder and vms inputs will require some additional work.
Finding the SRM Protection Folder
When you attempt to run the Create Protection Group for vSphere Replication workflow you can see that the SRM:ProtectionFolder is the top level folder named Protection Groups
Looking at the SRM Protection Folder object on vroapi.com we can see that the method getProtectionRootFolder() can be used to return the SRM:ProtectionFolder object when run against an SRM:Site object.
In part 1 we retrieved both the local and remote vSphere Replication site objects, but not the SRM sites. Looking at the api documentation there is only one method available to return SRM site objects, which is the Server.FindAllForType method. Luckily the SRM site has a deploymentId attribute which contains the vCenter Instance UUID value. We know from finding the VR:Site values that they too have the vCenter Instance UUID value as an attribute, so we can match our VR:Site to the SRM:Site using this value. So, we can reuse the localSite value we retrieved in the earlier workflow, find the matching SRM:Site and use it to find the SRM:ProtectionFolder object.
Unassigned Replicated VMs
Unassigned replicated VMs are any VMs that have been configured for vSphere Replication but have not been added to a Protection Group in SRM. Checking the object on vroapi.com reveals that there are no methods that return this kind of object. Reverting to the API explorer within vRO and searching for unassigned shows that there is actually a method ListUnassignedReplicatedVms that we could use, but it requires an input of a deploymentId that we would need to locate first and we have no details on what this deploymentId value is.
Luckily there is another option available. Checking the workflows provided by the SRM plugin in the SRM Samples folder we find a workflow named Convert VM to UnassignedReplicatedVM. This workflow takes inputs of an SRM:Site object and a VC:VirtualMachine object, it provides an output of an SRM:UnassignedReplicatedVm object. We already have both of the required inputs, so this workflow fits our needs perfectly.
Adding the VM to the Protection Group
The final step for this stage of the process is to add the VM to our newly created protection group. Although the workflow name doesn’t highlight it, the Create Protection Group for vSphere Replication workflow actually adds the VMs we provide as an input to the group after it is created. Therefore we don’t need to perform any additional steps to achieve our desired outcome.
Now we know how we will find the required input values we can create our workflow. This workflow builds on the base created in part 1, and will be added as a sub workflow to the parent workflow we created.
Updates to Configure Replication workflow
We need to make a small adjustment to the workflow we created to configure replication for the VM in part 1. We now know that we need to pass the vm and localSite values as outputs from the workflow, so that the values can be reused as inputs in our workflow to create the protection group. To do this I’m going to add a scripting element to the end of the workflow and create two new output parameters. The updated workflow looks like this
The Set Output parameters scripting element contains just two lines of code to assign the localSite and vm attribute values to the outLocalSite and outVM output parameters respectively.
Create Protection Group workflow
This workflow will require only a small amount of custom code as most of the steps will be provided by the SRM plugin workflows. For the first stage of the workflow I’m going to create new actions to retrieve the SRM Site and then to retrieve the SRM Protection Folder. The actions will contain the following code:
Next we add the Convert VM to UnassignedReplicatedVM workflow to the schema and configure the inputs/outputs.
Before we can create our protection group we need to convert the UnassignedReplicatedVM into an array, as this is the format the Create Protection Group for vSphere Replication requires. I’m going to use a scripting element to just declare a new array and push the UnassignedReplicatedVM value into it.
We also need to set a name and description for our group. I’m going to use the name of the VM as the protection group name for simplicity and predefine the description as ‘Created via vRO’. I’m adding a second scripting element to get the name property from the VM.
Finally we add the Create Protection Group for vSphere Replication workflow and configure the inputs/outputs and add a scripting element to pass out the SRM:Site value as an output parameter. Notice that the output is being assigned to an output parameter, this will allow the value to be reused within later workflows.
The last step is to add the new workflow into our parent workflow so it is executed after replication is configured. The parent workflow now looks like this.
That’s it for part 2.
We have now configured replication for a VM using vSphere Replication, created a protection group in SRM and added our VM to the group. Part 3 will focus on creating the recovery plan in SRM and adding the protection group to the plan.