Using VCO (vRO) to drive automation for vRA (vCAC) using Custom Properties

This post in many ways a repetition of Post1, Post2 and Post3. This post is about achieving same thing using new ways. When I did these posts I was unaware of this method. It took me quite long to get along. There are few basic steps you must complete before you can use this post. There are good number blogs which are covering it.  vCAC Plug for vCO was introduced sometime back and it made thing simpler further to make vRA and vRO talk with each other. Initial steps are very well covered here. By my own admission it is pretty simple to do it. It is pre-requisite before you read below post. As you might have read my previous posts, my aim was to give user choice in selecting Size of VM in T-Shirt Size style e.g. Large, Medium and Small. In previous posts I have used Advanced designer and vRO (that time VCO) can only accept string inputs. With vCAC plugin that is no longer needed.

Below is my workflow which I’m going to explain in much detailed for clarity purpose

image

1) First let’s discuss what are the inputs. Refer screen below. We have three inputs

image

VMName of type VC:VirtualMachine, vCACHost of type vCAC:vCACHost and vCACVirtualMachine of type vCAC:VirtualMachine

Except VC:VirtualMachine, all other object types are new and part of vCAC plugin. Please make a note of it. Another thing to note I no longer need to pass string. These three inputs are going to be input from vCAC.

2) Lets see what attributes I have defined

image

All attributes you see are part of in-built workflow. I have defined two attributed of types numbers to capture vCPU and vRAM.

Let’s see what is under script section. Below code pulls all custom properties available and part of vCAC Virtual Machine.


var vCACMachineEntity = vCACVirtualMachine.getEntity();
var vCACMachineEntityProperties = vCACMachineEntity.getLink(vCACHost,"VirtualMachineProperties");
var vCACVmProperties = new Properties();

for each (var vCACMachineEntityProperty in vCACMachineEntityProperties) {
vCACVmProperties.put(vCACMachineEntityProperty.getProperty("PropertyName"),vCACMachineEntityProperty.getProperty("PropertyValue"));
}

var keys = vCACVmProperties.keys;

for each (var key in keys) {
// System.log("Key: " + key + " Value: " + vCACVmProperties.get(key));

if(key=="VirtualMachine.Size"){
if(vCACVmProperties.get(key)=="Large"){
System.log("Large");
vCPU=4;
vRAM=2048;
}
else if (vCACVmProperties.get(key)=="Medium"){
System.log("Medium");
vCPU=2;
vRAM=1024;
}

else if (vCACVmProperties.get(key)=="Small"){
System.log("Small");
vCPU=1;
vRAM=512;
}
}
}

Line 1-7 we are querying vCAC Virtualmachine to get its custom property. Once we have custom property we are looking for a property name “VirtualMachine.Size” (line 14). This is a custom property defined by me. I am requesting user input against this property. I have restricted the user input to Large, Medium and Small.  I’m querying for what user has entered using vCACVmProperties.get(key)==”Large”) at line 15,20 and 26 using if else loop.Here is how it is going to look for the end user.

image

And I have defined VirtualMachine.Size in custom property using property dictionary.

image

So user selects VM size, I capture it under VirtualMachine.Size. VRO workflow will query custom property and initialized vCPU and vRAM. All the inputs we have defined as being used by this scripts section.

image

Now we finished Script section, next workflow item is vim3WaitToolsStarted. We need to check VMware tool is up and running. After we get confirmation on it, we can initiate graceful VM shutdown

image

Now next workflow item is “Shut down guest OS and wait”, This is pretty much shutdown’s VM gracefully. It needs only one input that is VM

image

Now next workflow item are action item changeVMvCPU & changeVMRAM. Both these action item has inbuilt reconfig task (referred as VC:Task) which is output for both the workflow

image image

This task waits for previous task to complete or there will be conflict between the tasks

image

Final task is Start virtual machine and wait. This is inbuilt workflow. It needs just VM as input.

image

 

Conclusion

You can define your own properties in vRA and can use to carry out your own function. e.g. CMDB function or integrating with 3rd system. This feature is available a year now but it is not being heavily used by Cloud Administrator. My aim is to educate them and start using it to bring agility. Hope you like the post.