Changing the owner of a resource in vRealize Automation Center

A previous post, I mentioned the power of deploying blueprints via ASD and I said at the end of the request that you need to change the owner of the virtual machine. This blog shows an example of how to do just that.

The first key thing to mention is when submitted a service blueprint in vRA, certain request information is being sent through as part of the request. Here are some of the values being passed in.

__asd_requestedBy = System.getContext().getParameter(__asd_requestedBy);
__asd_catalogRequestId = System.getContext().getParameter(__asd_catalogRequestId);
__asd_tenantRef = System.getContext().getParameter(__asd_tenantRef);
__asd_subtenantRef = System.getContext().getParameter(__asd_subtenantRef);


 There are other ways you can get these key values, but the one to look out for is the __asd_requestedBy value. This comes in the format of the logged on user who submitted the request and is the user you can use to change the owner ship of the resources to when deploying blueprints via ASD.

As part of the solution, you need to get the catalog resource object. Now typically, this is returned when you submit a catalog request.

You need to do is wait for the catalog item to be ready. Use this OOTB workflow, “wait for catalog item”:

Screen Shot 2015-02-17 at 15.09.45

Waiting for the the catalog item to appear means the resource will be ready to then run the reconfigure resource action against it. What this does is change the owner – the same as if you were to click on the reconfigure action and change the owner.

You also need to get the vCAC VM entity. You can get this using the VCACCAFE bindingid and matching the binding ID on the vCAC:VirtualMachine

Here’s a great blog from Sergio

And the bit of code you are interesting in is:

System.log("Provider binding is: " + catalogResource.providerBinding.getBindingId());
bindingId = catalogResource.providerBinding.getBindingId();
var vm = Server.findForType('vCAC:VirtualMachine', bindingId);
var virtualMachineID = vm.virtualMachineID;

You also need to get the vCAC User. The vRA entity you are changing ownership of is actually the vCAC IaaS user. Here is a way of getting that user:

var model = ManagementModelEntities.svc;
var entitySetName = Users;
var userProperty = new Properties();
var IaaSUser = vCACEntityManager.createModelEntity( , model, entitySetName, userProperty, null, null)
userEntity = System.getModule(com.vmware.library.vcac).getUserEntityByName(vCACHost,userToChangeTo);

You can get the operation ID is the reconfigure resource action. You can get this ID as follows:

var resourceActions = VM.operations;
var count = 0;
while(resourceActions.length < count)
    {System.log("Action available on this catalog resource is:"+ resourceActions[count].name);     
    if(resourceActions[count].name == Operation){
         System.log("Reconfigure action available on this catalog resource");
         var vmOperation = vCACCAFEEntitiesFinder.getCatalogResourceAction(VM,resourceActions[count].Id);
count++; } 

Once you have the vCAC VM and the VCAC User and the reconfigure resource action ID, you can then create the form that is required to change the owner. You can get the inputs by using firebug.

// Build input list for the form

form var FormInputs = new Properties();
FormInputs.put("provider-operationId", VcacConsumerResourceOperation.getBindingId());
FormInputs.put("provider-machineId", VcacVM.virtualMachineID);
FormInputs.put("provider-TARGET_MACHINE_NAME", VcacVM.displayName);
FormInputs.put("provider-Cafe.Shim.VirtualMachine.Owner", VcacUserEntity.getProperty(UserID));

Once you have all of this, you can then use the requestResourceAction from list of default actions. The code example is below and takes the operation vCACCAFE:ConsumerResourceOperation and the FormInputs properties object you ave built from above:

System.log("Getting resource action " + operation.getName() + " request form... ");
var form = vCACCAFERequestsHelper.getRequestFormForResourceAction(operation);

System.log("Expected inputs: ");
var fields = vCACCAFERequestsHelper.getFormKeys(form);
for (var i = 0; i < 0; fields.length; i++) {
    System.log(" - " + fields[i]);

System.log("Filling in resource action request..");
form = vCACCAFERequestsHelper.setFormValues(form, FormInputs);

System.log("Sending resource action request...");
var request = vCACCAFERequestsHelper.requestResourceAction(operation, FormInputs);

System.log("Resource action request " + request.getId() + " sent!");

This is just an explanation and you should be able to build your own workflows around this example. Feel free to leave a comment or any questions.


  1. Hello, this was helpful and simple enough to follow to allow me to change the owner of a deployment, but I’m now trying to change the number of CPUs with a Reconfigure action, and the form doesn’t match what the actual expected inputs are. It only says provider-MachineName, provider-machineId, and provider-operationId. I looked with Firebug, and the input I need to set is provider-Cafe.Shim.VirtualMachine.Reconfigure.CpuCount, but when I try to include that, I get BAD REQUEST. When I only include the three listed, it does a successful NOOP reconfigure. Know what I mean?

  2. Please disregard my previous post. I see that all the necessary properties are included in the provider-operationId string. Sorry!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s