Month: September 2014

Getting vRA business group networks in reservation

I was asked the other day on how to get network information that has been put in a reservation.

Here is a script that I wrote:

// Create custom query filter
var props = {"GroupID " : bg.groupID};
var model = "ManagementModelEntities.svc"
var entity = vCACEntityManager.readModelEntitiesByCustomFilter(, model, "ProvisioningGroups", props, null);

var hostReservations = entity[0].getLink(vcacHost, "HostReservations");

for each (v in hostReservations){

	var nicReservations = v.getLink(vcacHost, "HostNicToReservations");
	for each (nicReservation in nicReservations){
	var hostNics = nicReservation.getLink(vcacHost, "HostNic");
		for each (hostNic in hostNics){

			System.log("Network profile in BG is: " + hostNic.getProperty("NetworkName"));


These are the input parameters you need to provide, or you could determine these dynamically.

Screen Shot 2015-02-17 at 21.50.43

We are using the readModelEntitiesByCustomFilter method which is known as a CRUD operation. There are other methods available on the vCACEntityManager. Here is a screen shot showing them:

Screen Shot 2015-03-08 at 20.24.11

vRealize Orchestrator – Creating a naming convention using configuration elements

I often need a naming convention function and I use a very cool and easy script to give me a unique naming convention.

I take inputs from either an ASD form, or a catalogue form made up using drop down lists. For example, DEVWEB or PRODDB

I then match that naming convention in a configuration elememt and get the next availble number. Once I have that number, I just increment it, save it so it is ready to use next time I need to create a unique name.

In this case, the vmBaseName is the DEVWEB or PRODDB value

try {

	if(namingConfigElement.getAttributeWithKey(vmBaseName) == null) {
		System.log("Creating attribute for " +vmBaseName);

	var number = namingConfigElement.getAttributeWithKey(vmBaseName).value;
	var hostName = vmBaseName + number;
	System.log("Generated hostname: "+hostName);	
} finally {

return hostName.toString();

This is what the configuration element looks like:
Screen Shot 2015-02-17 at 21.19.05

So in this example, the next server name would be DEVWEB1.

However I also may want a 3 digit number, beginning with lead zeros, so I use this function:

function pad(num, size) {

	var vmNumber = num+"";
	while (vmNumber.length < size) vmNumber = "0" + vmNumber;
	return vmNumber;


So when I look up the number, I use this line of code

var vmName = vmBaseName + pad(number,"3");

So in this case, the name I get returned is DEVWEB001. A very handy way of getting a virtual machine unique name.

CRUD operation – updating a model entity

Here is a really simple script which updates a blueprint description.

var entity = blueprint.getEntity();
var entityProperties = entity.getProperties();
entityProperties.put("VirtualMachineTemplateDescription", description);

var host = Server.findForType("vCAC:VCACHost", entity.hostId);

vCACEntityManager.updateModelEntity(entity.hostId, entity.modelName, entity.entitySetName, entity.entityKey, entityProperties, entity.getLinks(host), null);

It’s very simple but it demonstrates how to use the updateModelEntity method. In the example abve, you pass in the blueprint value and a description, or you could calculate this on the fly.

The first three lines are key:

var entity = blueprint.getEntity();
var entityProperties = entity.getProperties();
entityProperties.put("VirtualMachineTemplateDescription", description);

It basically gets the blueprint entity, grabs all the properties in to an object and then puts (overrides) the VirtualMachineTemplateDescription properties with a value provided. Just an example but by using LinqPad, you can look through the ODATA objects to update whatever value is associated to the the blueprint.