VMware Cloud Community
maslow
Enthusiast
Enthusiast

Filter applicable networks for a reservation policy during requesting new VM

Hello,

currently I am trying to deploy a VM from one blueprint on vRA 7.3 where I am able to select applicable networks during request.

Made up easy, my setup looks like this:

- I have two independent vCenters that are not linked
- I have a Windows template in both vCenters that are exactly the same and also have the same name
- I have several networks within each vCenter with different names
- In vRA I configured network profiles for each network
- In vRA I configured a reservation policy for each vCenter
- In vRA I configured a reservation for each vCenter and applied the network profile to each available network and applied each vCenter its own reservation policy
- In vRA I configured just one Blueprint and left the reservation policy empty
- In vRA I created the custom property VirtualMachine.Network0.Name linked to the script action com.vmware.vra.networks/getApplicableNetworks as external value and attached it to my blueprint
- In vRA I created a custom
property __ReservationPolicyID linked to the script action com.vmware.vra.reservations/getApplicableReservationPolicies and attached it to my blueprint

 

So far so good,

now during a new request I am able to select by dropdown a reservation policy to place the new VM either in vCenter A or B. But on the network selection dropdown I am getting displayed all networks from all reservations within the user's current business group. So I checked the code of the script action com.vmware.vra.networks/getApplicableNetworks and it does exactly that 🙂

What I want to do is modify this script action, so it does only return the networks from the reservation policy currently selected in the request. As I have a reservation policy for each vCenter and each reservation is bound to one of those policies, I would end up with only the networks from one vCenter getting displayed.

The problem is, that I do not know how to modify the code to achieve this 😕 I couldnt figure out what the objects/variables look like in the code or which methods are availabe and what they actually do 😞 I am also looking for some kind of API or Documentation.

 

//For example: what is returned in to the variable and what does it look like? How can I filter the reservations to only get the one matching the selected one in the request?
var reservations = System.getModule("com.vmware.vra.reservations").getReservationsForUserAndComponent(user, tenant, host, blueprint, component);

12 Replies
qc4vmware
Virtuoso
Virtuoso

Sounds like you will need to create an XaaS blueprint to handle the dynamic nature of your form.  This will also require a little bit of Orchestrator work in the form of a workflow and possibly a customized action.

Reply
0 Kudos
maslow
Enthusiast
Enthusiast

Thx for the reply, but actually you dont need a XaaS blueprint or additional workflows. Basically all you need to do is attach two properties to your blueprint.

Like I wrote, one is for the vCenter placement of the VM (__ReservationPolicyID with script action com.vmware.vra.reservations/getApplicableReservationPolicies) and the network to choose (VirtualMachine.Network0.Name with script com.vmware.vra.networks/getApplicableNetworks). The only difference to the existing two script actions is that the getApplicableNetworks script action does not have an input parameter. As soon as you add your modified script action with input paramter (in this case it would have to be the property __ReservationPolicyID to filter the reservations by reservationpolicyid) as custom property to the blueprint, the values for the dropdown are refreshed during request.

So at the beginning nothing is selected for the vCenter Placement dropdown, and so the Network dropdown is empty. Once you select a reservation policy for the vCenter placement, the Network dropdown is automatically refreshed with the applicable networks. I already tested this with some easy example code and an example property. Only difficulty for me is to filter the filled variable with all the reservations with the reservation policy input parameter, so only ONE reservation is returned by the script action getApplicableNetworks. As I wrote, at the moment all networks from all reservations are returned. So I need filter/if/else whatever to just select one reservation by the given input parameter reservation policy 🙂

qc4vmware
Virtuoso
Virtuoso

From your description it sounds like you do actually need at least a custom action.  I default to XaaS for anything like you are describing for the max amount of control.  I find coaxing vRA to be pretty limiting although admittedly its getting better all the time!  Good luck.

Paul

Reply
0 Kudos
maslow
Enthusiast
Enthusiast

That is actually what I was writing about: creating a custom action in vRO. So I would like to clone getApplicableNetworks and adjust the code just that it has an input parameter (I know how to do that) and that the reservations are filtered by my input value so that only one reservation is selected. Thats all I want to do 😞

Any idea for the code? I dont think it will be more than 1 or 2 lines actually ... if you know how to do it 😄

Reply
0 Kudos
qc4vmware
Virtuoso
Virtuoso

This will likely do what you need:

var applicableNetworks = new Array();

for each(var res in reservations) {

var extensionData = res.getExtensionData();

System.debug(res.name + ":" + res.id);

if(extensionData) {

var networks = extensionData.get("reservationNetworks");

if(networks) {

for each(var network in networks.getValue()) {

var path = network.getValue().get("networkPath");

applicableNetworks.push(path.label);

}

}

}

}

Reply
0 Kudos
maslow
Enthusiast
Enthusiast

hehe that is just the code snippet from the getApplicableNetworks ... so I think you didnt understand what I want 🙂

I need something like this assuming that my InputParameter for the scriupt action is the ResourcePolicyID selected during request:

//VMware code

var reservations = System.getModule("com.vmware.vra.reservations").getReservationsForUserAndComponent(user, tenant, host, blueprint, component);

//pseudo code

var correctReservation = null;
for each(var res in reservations) {

if(res.ResourcePolicyID == InputParameter){

correctReservation = res;

}

}

 

//now it continues with your code snippet and just fetches the networks from ONE reservation not all 🙂

for each(var res in reservations) {
    var extensionData = res.getExtensionData();
    if(extensionData) {
        var networks = extensionData.get("reservationNetworks");
        if(networks) {
            for each(var network in networks.getValue()) {
                var path = network.getValue().get("networkPath");
                applicableNetworks.put(path.label, path.label);
            }
        }
    }
}

Reply
0 Kudos
rwk1982
Enthusiast
Enthusiast

Our Setup:

Datacenters (DC01, DC02)

The DC Value in the blueprint comes from the "Vrm.DataCenter.Location" Property

Each DC have unique Networks, but also can have Networks from the other DC

I created NetworkProfiles for each Network with the naming convention:

DC01_xxx -> Network only in DC01

DC02_xxx -> Network only in DC02

xxx -> Network exists in both DCs

The vRO Action is based on the default "getApplicableNetworks" with an Input Paramter "in_DC" (see vRA_NetworkSelect.txt).

Drink coffee.. Do stupid things faster with more energy...
Reply
0 Kudos
maslow
Enthusiast
Enthusiast

Yeah kind of that 🙂

Do you know how this would work for reservations to filter by the reservationpolicyid that comes in as parameter?

//code from getApplicableNetworks
var reservations = System.getModule("com.vmware.vra.reservations").getReservationsForUserAndComponent(user, tenant, host, blueprint, component);
 

Is there a method or attribute like res.reservationpolicyid I could use?

var correctReservation;
for each (var res in reservations) {

if(res.reservationpolicyid == inputReservationPolicyID){
correctReservation = res;
}

}

 

return correctReservation;

Reply
0 Kudos
maslow
Enthusiast
Enthusiast

Yeah just made it 😄 Here is my code (inputPolicyID is the inputparamter for the script action):

 

var blueprint = System.getContext().getParameter("__asd_composition_blueprintId");
var component = System.getContext().getParameter("__asd_composition_componentId");
var user = System.getContext().getParameter("__asd_requestedFor");
var tenant = System.getContext().getParameter("__asd_tenantRef");

var host = vCACCAFEHostManager.getDefaultHostForTenant(tenant , true);
var reservations = System.getModule("com.vmware.vra.reservations").getReservationsForUserAndComponent(user, tenant, host, blueprint, component);

var applicableNetworks = new Properties();

for each(var res in reservations) {

    if(inputPolicyID == res.getReservationPolicyId()){
        var extensionData = res.getExtensionData();
        if(extensionData) {
            var networks = extensionData.get("reservationNetworks");
            if(networks) {
                for each(var network in networks.getValue()) {
                    var path = network.getValue().get("networkPath");
                    applicableNetworks.put(path.label, path.label);
                }
            }
        }
    }
}

return applicableNetworks;

maslow
Enthusiast
Enthusiast

Maybe if someone else got stuck with finding the correct methods and so on, this is a link to the vRO API that helped me solve my issue: http://www.vroapi.com/Plugin/vCACCAFE/7.3.0
Reply
0 Kudos
nhtps
Contributor
Contributor

Hi Maslow,

Wondering what is parameter type for input parameter inputPolicyID, is that vCACCAFE:Reservation?

Thanks,

Naeem Haider

Reply
0 Kudos
pizzle85
Expert
Expert

This will take in a subtenantId and a location and return a sorted list of networks the custom has in the reservation for that compute resource. This assumes you only have one reservation per compute resource.

var groupNetworks = new Array();

if (!location || !subtenantId) {

     return groupNetworks

}

var host = System.getModule("edu.ufl.vcac").returnVcacCafeHost();

var reservations = vCACCAFEEntitiesFinder.getReservations(host);

if (!reservations) {

     throw 'No reservations returned for host ' + host.name;

}

for each (res in reservations) {

     if (res.subTenantId == subtenantId) {

          if (res.name.toLowerCase().indexOf(location.toLowerCase()) > -1) {

               var extensionData = res.getExtensionData();

               if(extensionData) {

                    var networks = extensionData.get("reservationNetworks");

                     if(networks) {

                          for each(var network in networks.getValue()) {

                               var path = network.getValue().get("networkPath");

                               groupNetworks.push(path.label);

                          }

                     }

                }

           }

      }

}

return groupNetworks;

Reply
0 Kudos