VMware Cloud Community
TimDScott
Enthusiast
Enthusiast
Jump to solution

VM Visibility - vRO / vRA

Hi All,

We've developed a set of workflows that take a VC:VirtualMachine as one of the inputs. This is fine when using the flows within vRO, but we also have a requirement to use them within vRA.

The workflows have been published as XAAS blueprints within vRA, when a user selects the VC:VirtualMachine they are able to see all of the machines in all the vCenters configured within vRO. We need to limit this to display only the machines they are entitled to see, so for example a user from vRA business group a can select machines a1, a2, a3, a user from business group b can select machines b1, b2, b3.

We've had a look at the VCAC:VirtualMachine type, but that seems to display all machines as well. Is there a built-in type we can use that will do this, or will we have to "roll our own"?

Any advice would be appreciated!

Thanks,

Tim.

Reply
0 Kudos
1 Solution

Accepted Solutions
stevedrummond
Hot Shot
Hot Shot
Jump to solution

I quickly put together a workflow/xaas blueprint that should help you get started.

Unpack the attached ZIP and go into vRO and Import Package from Folder, selecting the folder vmtn.ownerOrBusGroupVMs and clicking Import.

You will then want to import the XaaS Blueprint xaas_blueprint.json using the vRA API. Alternatively you can make the XaaS blueprint yourself from the workflow, however you will need to make two adjustments (also true if you refresh the form or borrow the logic):

  1. The field businessGroupName must be bound to the field value Request Info -> Business Group -> Name
  2. The field Machines must be a dual list to properly support the filter and remembering existing selections

Once in the workflow you will obviously need to match up the selected machine names with their VC:VirtualMachine objects to call your existing workflow.

You can alter the PAGE_SIZE variable in the getVirtualMachineNames action as you see fit for performance. I just remembered you may also want to sort the results by whatever criteria you desire.

Hope this helps.

View solution in original post

Reply
0 Kudos
14 Replies
stevedrummond
Hot Shot
Hot Shot
Jump to solution

Have you tried populating the Presentation field Predefined List of Values? I don't know if that works for traditional tree-pick types.

What I would actually suggest is having the XaaS blueprint be a wrapper for your standard workflows. It's presentation should present the user a dropdown (or multi-picker if array) of machine names as strings. The user selects that and submits the request, where the wrapper workflow logic looks up the VC:VirtualMachine and passes it to your business logic workflow.

You will use the presentation fields to present the user a list of machine names from within their business group or any other criteria you want. Additionally since you are not using objects your presentation will be exponentially faster and you can even add filter boxes.

Reply
0 Kudos
TimDScott
Enthusiast
Enthusiast
Jump to solution

Thanks Steve, that's kind of what I had in mind, I think the main things I am struggling with are:

  • The proper way to detect the tenant/business group of the user that's creating the request.
  • Building a list of machines that are either owned by the user OR sit within the users tenant/business group
Reply
0 Kudos
stevedrummond
Hot Shot
Hot Shot
Jump to solution

I quickly put together a workflow/xaas blueprint that should help you get started.

Unpack the attached ZIP and go into vRO and Import Package from Folder, selecting the folder vmtn.ownerOrBusGroupVMs and clicking Import.

You will then want to import the XaaS Blueprint xaas_blueprint.json using the vRA API. Alternatively you can make the XaaS blueprint yourself from the workflow, however you will need to make two adjustments (also true if you refresh the form or borrow the logic):

  1. The field businessGroupName must be bound to the field value Request Info -> Business Group -> Name
  2. The field Machines must be a dual list to properly support the filter and remembering existing selections

Once in the workflow you will obviously need to match up the selected machine names with their VC:VirtualMachine objects to call your existing workflow.

You can alter the PAGE_SIZE variable in the getVirtualMachineNames action as you see fit for performance. I just remembered you may also want to sort the results by whatever criteria you desire.

Hope this helps.

Reply
0 Kudos
TimDScott
Enthusiast
Enthusiast
Jump to solution

Thanks so much Steve, I'll give it a whirl and let you know how it goes!

Reply
0 Kudos
stevedrummond
Hot Shot
Hot Shot
Jump to solution

TimDScott​ did it work for you?

Reply
0 Kudos
TimDScott
Enthusiast
Enthusiast
Jump to solution

stevedrummond​ I've had to switch focus for a while, will get back onto this soon and will let you know, thanks again!

Reply
0 Kudos
TimDScott
Enthusiast
Enthusiast
Jump to solution

stevedrummond​ hi Steve, I've installed the sample code you put together, perhaps I didn't explain myself properly in the first place, but what I need to do is have an action that is used in a vro workflow presentation layer, that detects the business group that has been selected in vRA when requesting a catalog item:

pastedImage_1.png

Then builds a list of all managed machines within that business group, this will then be returned by the action as a string array for selection by the user in a drop down list, it should have all the managed machines that they can see within the infrastructure/managed machines page.

pastedImage_0.png

A search may be useful to help filter the drop-down. We may have a requirement to list just the machines owned by the logged-in user too, but that may be a different action used on a different blueprint.

Thanks,

Tim.

Reply
0 Kudos
stevedrummond
Hot Shot
Hot Shot
Jump to solution

Hey TimDScott​,

That's exactly what the action getVirtualMachine names is doing. It will return a list of vCenter virtual machines (vRA refers to them as Infrastructure.Virtual) either by owner or businessGroup (it currently does not do both at once, but that's very easy to change). The return type is currently string because its easier for the filter to work this way but you can easily change it to be array/string.

You can change the logic/inputs/outputs as required as the action given is just an example of how to do it. The XaaS workflow itself is just an example of how to piece the actions together, particularly if you want to use a filter/search box.

Reply
0 Kudos
cloudyred
Enthusiast
Enthusiast
Jump to solution

Edit:

Assuming you are using a vRO action to return the VM list as input to a field of an XAAS form / or indeed for it can be used to find an object for a custom property field on an IAAS blueprint.

I believe what you are looking for is simpler in vRA 7.5 and above. Before the business group wasn't passed to vRO but now it is in the Context.

```

var systemContext = System.getContext();

// conditional statement needed to workaround VMware vRA issue that calls form actions after submit

if (systemContext.contains("__asd_subtenantRef")) {

var userId = systemContext.getParameter("__requestedForUserId");

var businessGroupId = System.getContext().getParameter("__asd_subtenantRef")

if(businessGroupId == null) {

return [];

}

```

Also, best practice not to pass a list of VC:VM objects from vRO to vRA, just a list of names, ids maybe.

TimDScott
Enthusiast
Enthusiast
Jump to solution

Thanks Steve, will give it another look!

Reply
0 Kudos
TimDScott
Enthusiast
Enthusiast
Jump to solution

cloudyred​ thanks for  the code snippet, just for test purposes, I created an action based upon your code as below:

var output = [];

try

{

     var systemContext = System.getContext();

     var userId = systemContext.getParameter("__requestedForUserId");

     var businessGroupId = System.getContext().getParameter("__asd_subtenantRef")

     if(businessGroupId == null) {

          output.push("No BG");

     }

     else

     {

          output.push(businessGroupId);

     }

     if(userId == null)

     {

          output.push("No User Id");

     }

     else

     {

     output.push(userId);

     }

}

catch (e)

{

     output.push(e)

}

return output;

Created a workflow with a single string input, presentation calls the action.

Run the "Create a service blueprint" workflow to create the xaas blueprint in vRA.

When the action is called from vRA, I get the following:

pastedImage_5.png

So looks like the business group/user id can't be found in the system context?

(This is v7.6)

Reply
0 Kudos
stevedrummond
Hot Shot
Hot Shot
Jump to solution

vRA does not pass anything through to the vRO context when running the actions for XaaS (at least with vRA 7.6 GA version), that's why you need to do the bindings I mentioned earlier.

I see cloudyred mentioned both XaaS and IaaS custom properties in their reply but I think the code was tested only on IaaS custom property, where vRA does send through those details to the vRO context (because you have no other way of binding them unlike XaaS).

You can see all the properties by just returning System.getContext().parameterNames()

Reply
0 Kudos
cloudyred
Enthusiast
Enthusiast
Jump to solution

Yes, sorry, that is IAAS BP only. I hadn't read the thread properly.

var myContext = System.getContext();

var parameterNames = myContext.parameterNames();

var paramterValues = parameterNames.map(myContext.getParameter);

System.log(parameterNames.join(" , "));

return parameterNames.concat(paramterValues);

pastedImage_0.png

This is something that didn't work in vRA 7.3 (no subtenantId at least) but appeared since 7.5 so I made the assumption that was what you were looking for.

Steve is right saying that this action doesn't return any data for getContext() when called in vRO presentation layer or if used directly in a field in an XAAS form using external values.

Note that there is data for getContext() within the XAAS workflow like in a scriptable task.

__asd_catalogRequestId , __asd_subtenantRef , __asd_requestedBy , __asd_requestedFor , __asd_tenantRef , 90997ab8-66e1-43f5-afbc-29bd45a823d5 , 89787228-11a9-4f50-8368-3f1de9f08795 , ehc_sysadmin@domain.local , ehc_sysadmin@domain.local , tenant_1

I didn't import Steve's code example (which is probably why I went off topic sorry) but it sounds to exactly meet your criteria.

The major difference between your initial attempt and Steve's suggestion seem to be.

Steves approach is:

Rather than having the workflow presentation handle the filtering etc and passing info back and forth between vRA and vRO, use an action to pull back a list of accessible vm names (based on the BG / User )

Finally, bind the vmname selected to the input of your workflow and look up the vm by name possibly inside the wf.

Your initial query was:

"have an action that is used in a vro workflow presentation layer, that detects the business group that has been selected in vRA when requesting a catalog item"

=>As we have mentioned this isn't possible for an action called directly via XAAS or in the presentation.

=>You could simply add an input to your vRO workflow called businessGroup (no parameters specified in vRO presentation) and do the binding steve suggested in the XAAS form.

=>Your existing get vms action in the presentation layer could then use the businessGroup as input.

Steves approach is probably the best practice, just different to what you were expecting.

Personally I would extend this and create a vRO workflow that takes a single vc:vm and does something to it (you already have this). That would be in a folder / package that runs tasks against vcenter vms. Create another workflow with a similar name with XaaS appended but in a folder under vra/xaas. Simply add the child workflow as an element to the xaas wrapper.

--company/

  --vcenter/

    --vm/

        --> wf "vcenter vm do task x"

--vra/

   --xaas blueprints/

     --> wf "vm do task x xaas wrapper"

--iaas/

--vm/

   --> wf "iaas vm do task"

In this way the dev that writes the code against vcenter doesn't have to worry about vRA. Equally the team that publishes items to vRA doesn't have to worry about changes affecting the child workflow. Even if you are responsible for both, it is nice segregation. And you might say want to add a custom property to the vm in vRA while at the same time adding a vSphere tag all in the one xaas wf. Just create some actions to find iaas vm / vc vm based on name / uuid etc so it is all nice and reusable.

Reply
0 Kudos
TimDScott
Enthusiast
Enthusiast
Jump to solution

Great, thanks very much stevedrummondcloudyred​ I've got a follow on question, will post that in a separate thread.

Reply
0 Kudos