Using custom property in vRA/vCAC deploy VM in specific datacenter using local templates -Post02

We discussed out of the box option in post:01. we all know it was not a practical approach. So only option best option is to use vCO (vRO). It is so easy to achieve, you would be surprised to see it. You just need to pass what datacenter string user is selecting. In my case it will be Mumbai or Pune

image

Using this input a “If else” statement is used to pass value back to vCAC template. Here is how the code looks below

System.log("Workflow started from workflow stub " + externalWFStub + " on vCAC host " + vCACHost.displayName);
System.log("Got vCAC virtual machine " + vCACVm.virtualMachineName);
System.log("Matching virtual machine entity " + virtualMachineEntity.keyString);
propertyNames = new Array();
propertyValues = new Array();
//var vmTemplate = vCACVmProperties.get("Datacenter.Location");
var DCName = vCACVmProperties.get("Vrm.DataCenter.Location");
System.log("This is coming from inbuild " + " " + DCName);

//Mumba DC is selected
if(DCName=="Mumbai"){
System.log ("Mumbai");
propertyNames.push("CloneFrom");
propertyValues.push("template_mum");
propertyNames.push("VMware.VirtualCenter.OperatingSystem");
propertyValues.push("windows8Server64Guest");
System.log("Set template: template_mum");
}

//Pune DC is selected
else if(DCName=="Pune"){
System.log ("Pune");

System.log ("Pune is the DC location");
propertyNames.push("CloneFrom");
propertyValues.push("template_pnq");
propertyNames.push("VMware.VirtualCenter.OperatingSystem");
propertyValues.push("windows8Server64Guest");
System.log("Set template: template_pnq");
}

In line “7” we are querying which datacenter user has selected. This is grabbed in variable DCName as represented below line.

var DCName = vCACVmProperties.get("Vrm.DataCenter.Location");

You might ask what is “Vrm.DataCenter.Location”, well it is reserved property in vCAC/vRA.

Now we have string available, I have used “if else” loop and updated custom properties. Custom properties & values are represented from line “10” to “29”. These values are passed into foreach loop for inbuilt workflow create/ update property on virtual machine Entity back to vCAC.  Then finally we use state change workflow and this time we select “BuildingMachine” state. This allows values to be updated before virtual machine provisioning starts. At the end of post, Please find attached VCO Workflow. Hope you find it useful.

Well if this is first time you are playing with VCO then follow the steps below. These only for First timers.

Copy workflow template provided in Library > vRealize Automation > Infrastructure > Extensibility to your folder/location

  1. Edit workflow, go to the schema and edit Update Property script
  2. Remove all except first three lines
  3. Create attribute as in parameter by name false and of type boolean
  4. Go to OUT tab, create two string attributes of type array
    • propertyNames
    • propertyValues

 2015-04-04_22-00-07

Go to visual Binding and ensure parameters are mapped as shown below.

2015-04-04_22-00-14

Then go to scripting tab. Copy and paste the script mentioned above (in the code tag). You may have to change the datacenter location string. I have explain it in below image what needs to be changed.

2015-04-05_21-51-12

 Now you are done with “Update Properties” where we have decide what needs to be replaced, when particular datacenter is selected.

2015-04-05_21-50-40

These properties needs to updated back into blueprint. To do this we have a In-built workflow “Create / Update property on virtualMachine Entity“. Since we are updating multiple properties we will loop this workflow into foreach loop.

So first drag foreach workflow, and select Create / Update property on virtualMachine Entity then Edit workflow, go to Visual Binding, ensure things are mapped as shown below

2015-04-04_21-59-33

Finally use state change workflow. However you must select life cycle stage as Building machine. Here is more information on various life cycle available. Also check here to understand how to use state change workflow. Building machine will change template based on CloneFrom property before even machine starts building.

Well, I tried my best to explain the step by step procedure in as much detail as possible, but there could be few gaps to make it simpler. If you are reading this blog post and you feel lost, comment in the post or use linkedin to reach me, I will strive to assist.

Download Workflow from here