vRealize Automation Center

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(vcacHost.id, 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

Advertisements

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.