VMware Cloud Community
qc4vmware
Virtuoso
Virtuoso
Jump to solution

Change Owner of deployment with

Cross posting here as I am not getting very far in the vRO community Change Owner with Request a catalog resource action fails with 400 Bad Request .  Just curious if anyone can verify for me that trying to change owner of a deployment using the Library/vRealize Automation/Requests/Request a resource action workflow is functioning for them in 7.3 .  I have two environments and I can't get it to work in either.  Works fine from the gui.  Using the embedded vRO.  Tested in both a clustered and simple install.  Both fail identically.

1 Solution

Accepted Solutions
qc4vmware
Virtuoso
Virtuoso
Jump to solution

Here is a code snippet of what I ended up using... I found this in another discussion or someones blog... can't remember.  You need to set reconfigOp to the operation for change owner obviously and set newOwner to the desired new owner.

//Operation is a thing that the workflow started with, unsure what it would be. You can probably skip it if you already have a way to find your resource request.

var requestTemplate = vCACCAFERequestsHelper.getRequestForResourceAction(reconfigOp)

//This is the part you were missing, and is one of those hilarious vra-isms:

var jsonData = vCACCAFERequestsHelper.getResourceActionRequestData(requestTemplate);

var json = JSON.parse(jsonData);

//Change provider-NewOwner

json["provider-NewOwner"] = {"type":"entityRef", "classId":"principal", "id":newOwner, "label":""};

//This puts everything back in the right format:

vCACCAFERequestsHelper.setResourceActionRequestData(requestTemplate, JSON.stringify(json));

//And this actually says go do the work:

var changeOwnerRequest = System.getModule("com.vmware.library.vcaccafe.request").requestResourceActionWithRequestTemplate(reconfigOp, requestTemplate);

View solution in original post

0 Kudos
10 Replies
daphnissov
Immortal
Immortal
Jump to solution

vRO 7.3 shipped with a broken café plug-in that resulted in NullPointer exceptions when trying to look at the inventory tree. I am not sure if this is the cause or contributes to your issue, but regardless it's best to update with the newer plug-in to see if that helps.

“NullPointer Exception” when viewing the requests from the CAFE plugin inventory in vRealize Orchest...

qc4vmware
Virtuoso
Virtuoso
Jump to solution

Thanks!  Downloading this now.  Hopefully it will fix both issues!  I'll report back.

0 Kudos
qc4vmware
Virtuoso
Virtuoso
Jump to solution

This did fix the issue with the requests list.  They now show up in the inventory.  It did not fix the error with changing the owner on the deployment though.  Any chance you could spare a minute to test it and let me know if it works for you?

0 Kudos
kmarkov
VMware Employee
VMware Employee
Jump to solution

The type which is expected by the API call has changed. Apparently, up to version 7.2 it was perfectly fine to specify the new owner in plain text. Now it is necessary to provide entity reference.

So, if for the inputs parameter of the 'Request a resource action' before it was possible to set it like this:

var newOwner = "configurationadmin@vsphere.local";

inputs = new Array();

inputs.push({ name: "provider-NewOwner", value: newOwner});

Now you need to do it like this:

var newOwner = "configurationadmin@vsphere.local";

var newOwnerLiteral = new vCACCAFEEntityReference("principal" , newOwner);

inputs = new Array();

inputs.push({ name: "provider-NewOwner", value: newOwnerLiteral.getValue()});

michael_stefani
Enthusiast
Enthusiast
Jump to solution

Has anyone had any luck with that new formatting?  I've tried and am still getting the 400 bad_request error

0 Kudos
kmarkov
VMware Employee
VMware Employee
Jump to solution

Hi,

I managed to get it working in several environments, with the code given above. However, in order to get it working, you cannot directly invoke the 'Request a resource action' workflow. You would need to create a new wrapper workflow, and before invoking 'Request a resource action', you would have to prepare the request parameters by using the script I provided in the previous post.

Let me know if this helps, or alternatively, I could prepare a simple sample to illustrate how this works (at least for me).

michael_stefani
Enthusiast
Enthusiast
Jump to solution

Sorry, I swear I was trying all kinds of combinations and couldn't get it working.  I started over from scratch with those few lines of code in a scriptable task and it worked like a charm.  Thanks a bunch.  I'm having the same problem with the Change Lease action and I'm guessing they're related. 

0 Kudos
FidelisCare
Contributor
Contributor
Jump to solution

Thanks, kmarkov​ !  This is what I needed.  Where in the documentation do you find this kind of info?  I have the vrealize-automation-73-programming-guide.pdf, but for example I can't figure out how I would have even known to specify "provider-NewOwner" without help from posts like yours.  Is this info somewhere in here? VMware API Explorer - VMware {code}

0 Kudos
kmarkov
VMware Employee
VMware Employee
Jump to solution

To be honest, I found it out through reverse engineering. Not really sure if this is mentioned in some of the docs. I had a working solution (on 7.2), and it stopped working after migrating to 7.3. So, I had to do some testing, before I figured it out.

0 Kudos
qc4vmware
Virtuoso
Virtuoso
Jump to solution

Here is a code snippet of what I ended up using... I found this in another discussion or someones blog... can't remember.  You need to set reconfigOp to the operation for change owner obviously and set newOwner to the desired new owner.

//Operation is a thing that the workflow started with, unsure what it would be. You can probably skip it if you already have a way to find your resource request.

var requestTemplate = vCACCAFERequestsHelper.getRequestForResourceAction(reconfigOp)

//This is the part you were missing, and is one of those hilarious vra-isms:

var jsonData = vCACCAFERequestsHelper.getResourceActionRequestData(requestTemplate);

var json = JSON.parse(jsonData);

//Change provider-NewOwner

json["provider-NewOwner"] = {"type":"entityRef", "classId":"principal", "id":newOwner, "label":""};

//This puts everything back in the right format:

vCACCAFERequestsHelper.setResourceActionRequestData(requestTemplate, JSON.stringify(json));

//And this actually says go do the work:

var changeOwnerRequest = System.getModule("com.vmware.library.vcaccafe.request").requestResourceActionWithRequestTemplate(reconfigOp, requestTemplate);

0 Kudos