Good morning,
I have some blueprints with Reservation Policies and now I want to have a network field that pulls the networks attached to Reservations with that same Reservation Policy.
I actually managed to do so by creating an action and tying it up with the VirtualMachine.Network0.Name vRA property.
The thing is, although the network field is filled in with the expected networks (see attached image, I have 4 networks but only 2 attached to the reservation tied to this blueprint´s Reservation Policy), I´m unable to complete the Request. I´m receiving the following message inside catalina.out:
2017-10-19 10:10:10,487 vcac: [component="cafe:composition-service" priority="ERROR" thread="tomcat-http--2" tenant="vsphere.local" context="XbaBuYWK" parent="XbaBuYWK" token="3oCq1BKz"] com.vmware.vcac.composition.service.impl.PropertyDefinitionGatewayImpl.getValues:43 - Error retrieving property definition for property with id [VirtualMachine.Network0.Name]
It seens that although the field has the correct information, it is going empty to the request, and I have no idea why.
Attached I´m also sending an image of the VirtualMachine.Network0.Name configured inside the Property Dictionary (sorry for it being in Portuguese: "Cadeia de caracteres" = "String" and "Lista suspensa" = "Dropdown list").
Below the full code for the action (return type is Properties).
// Captura do blueprint, tenant e instancia do vRA na qual a requisicao esta sendo feita
var tenant = System.getContext().getParameter("__asd_tenantRef");
var host = vCACCAFEHostManager.getDefaultHostForTenant(tenant , true);
var blueprintName = System.getContext().getParameter("__asd_composition_blueprintId");
if (blueprintName != null)
{
// Captura Reservation Policy da maquina componente do Blueprint
var compositeClient = host.createCompositionClient();
var compositeBlueprint = compositeClient.getCompositionCompositeBlueprintService();
var blueprint = compositeBlueprint.getBlueprint(blueprintName);
var components = blueprint.components; //HashMap - um array de vCACCAFEComponentDeclaration
for each (var component in components)
{
var field = component.getComponentFieldValue("reservation_policy") // Objeto vCACCAFEComponentFieldValue
if (field != null)
{
var fieldFacets = field.getFacets(); // Hashmap - um array de vCACCAFEConstantValue
for each (var facet in fieldFacets)
{
var value = facet.getValue(); // Objeto vCACCAFEEntityReference
var reservationPType = value.getClassId(); // Tipo da Reservation Policy
var reservationPLabel = value.getLabel(); // Nome da Reservation Policy
}
}
}
// Captura ID da Reservation Policy
var reservationClient = host.createReservationClient(); //Objeto vCACCAFEReservationClient
var reservationPolicyService = reservationClient.getReservationReservationPolicyService(); //Objeto vCACCAFEReservationReservationPolicyService
var reservationPolicyRoot = reservationPolicyService.getAllReservationPolicies(); //Objeto vCACCAFEPagedResources
var reservationPolicies = reservationPolicyRoot.getContent(); // Array de vCACCAFEReservationPolicy
for each (reservationPolicy in reservationPolicies)
{
if (reservationPolicy.name == reservationPLabel && reservationPolicy.reservationPolicyTypeId == reservationPType)
{
var reservationPId = reservationPolicy.id;
break;
}
}
// Captura Reservations que possuam esta Reservation Policy
var reservationService = reservationClient.getReservationReservationService(); //Objeto vCACCAFEReservationReservationService
var reservationRoot = reservationService.getAllReservations(); //Objeto vCACCAFEPagedResources
var reservations = reservationRoot.getContent(); //java.util.Collection - Um array de vCACCAFEReservation
var blueprintReservations = new Array;
for each (var reservation in reservations)
{
if (reservation.reservationPolicyId == reservationPId)
{
blueprintReservations.push(reservation);
}
}
// Captura as redes existentes nas Reservations selecionadas
var reservationNetworks = new Properties();
for each (blueprintReservation in blueprintReservations)
{
var reservationData = blueprintReservation.extensionData //Objeto vCACCAFELiteralMap
// var reservationData = reservation.extensionData;
var networks = reservationData.get("reservationNetworks");
for each(var network in networks.getValue())
{
//var path = network.getValue().get("networkPath");
var networkId = network.getValue().get("networkPath").getValue().getId();
var networkName = network.getValue().get("networkPath").getValue().getLabel();
reservationNetworks.put(networkId, networkName);
}
}
}
return reservationNetworks;
If anyone could give some light into it, I´d be very thankful.
And then you notice that the return variable is declared within the main IF and because of that it doesn´t exist when the action is run during request submission.
Declared the return variable at the beggining and now it´s working just fine.
Here´s the complete code:
// Captura do blueprint, tenant e instancia do vRA na qual a requisicao esta sendo feita
var tenant = System.getContext().getParameter("__asd_tenantRef");
var host = vCACCAFEHostManager.getDefaultHostForTenant(tenant , true);
var blueprintName = System.getContext().getParameter("__asd_composition_blueprintId");
var reservationNetworks = new Properties();
if (blueprintName != null)
{
// Captura Reservation Policy da maquina componente do Blueprint
var compositeClient = host.createCompositionClient();
var compositeBlueprint = compositeClient.getCompositionCompositeBlueprintService();
var blueprint = compositeBlueprint.getBlueprint(blueprintName);
var components = blueprint.components; //HashMap - um array de vCACCAFEComponentDeclaration
for each (var component in components)
{
var field = component.getComponentFieldValue("reservation_policy") // Objeto vCACCAFEComponentFieldValue
if (field != null)
{
var fieldFacets = field.getFacets(); // Hashmap - um array de vCACCAFEConstantValue
for each (var facet in fieldFacets)
{
var value = facet.getValue(); // Objeto vCACCAFEEntityReference
var reservationPType = value.getClassId(); // Tipo da Reservation Policy
var reservationPLabel = value.getLabel(); // Nome da Reservation Policy
}
}
}
// Captura ID da Reservation Policy
var reservationClient = host.createReservationClient(); //Objeto vCACCAFEReservationClient
var reservationPolicyService = reservationClient.getReservationReservationPolicyService(); //Objeto vCACCAFEReservationReservationPolicyService
var reservationPolicyRoot = reservationPolicyService.getAllReservationPolicies(); //Objeto vCACCAFEPagedResources
var reservationPolicies = reservationPolicyRoot.getContent(); // Array de vCACCAFEReservationPolicy
for each (reservationPolicy in reservationPolicies)
{
if (reservationPolicy.name == reservationPLabel && reservationPolicy.reservationPolicyTypeId == reservationPType)
{
var reservationPId = reservationPolicy.id;
break;
}
}
// Captura Reservations que possuam esta Reservation Policy
var reservationService = reservationClient.getReservationReservationService(); //Objeto vCACCAFEReservationReservationService
var reservationRoot = reservationService.getAllReservations(); //Objeto vCACCAFEPagedResources
var reservations = reservationRoot.getContent(); //java.util.Collection - Um array de vCACCAFEReservation
var blueprintReservations = new Array;
for each (var reservation in reservations)
{
if (reservation.reservationPolicyId == reservationPId)
{
blueprintReservations.push(reservation);
}
}
// Captura as redes existentes nas Reservations selecionadas
for each (blueprintReservation in blueprintReservations)
{
var reservationData = blueprintReservation.extensionData //Objeto vCACCAFELiteralMap
// var reservationData = reservation.extensionData;
var networks = reservationData.get("reservationNetworks");
for each(var network in networks.getValue())
{
//var path = network.getValue().get("networkPath");
var networkId = network.getValue().get("networkPath").getValue().getId();
System.log(networkId);
var networkName = network.getValue().get("networkPath").getValue().getLabel();
System.log(networkName);
reservationNetworks.put(networkId, networkName);
}
}
}
return reservationNetworks;
And then you notice that the return variable is declared within the main IF and because of that it doesn´t exist when the action is run during request submission.
Declared the return variable at the beggining and now it´s working just fine.
Here´s the complete code:
// Captura do blueprint, tenant e instancia do vRA na qual a requisicao esta sendo feita
var tenant = System.getContext().getParameter("__asd_tenantRef");
var host = vCACCAFEHostManager.getDefaultHostForTenant(tenant , true);
var blueprintName = System.getContext().getParameter("__asd_composition_blueprintId");
var reservationNetworks = new Properties();
if (blueprintName != null)
{
// Captura Reservation Policy da maquina componente do Blueprint
var compositeClient = host.createCompositionClient();
var compositeBlueprint = compositeClient.getCompositionCompositeBlueprintService();
var blueprint = compositeBlueprint.getBlueprint(blueprintName);
var components = blueprint.components; //HashMap - um array de vCACCAFEComponentDeclaration
for each (var component in components)
{
var field = component.getComponentFieldValue("reservation_policy") // Objeto vCACCAFEComponentFieldValue
if (field != null)
{
var fieldFacets = field.getFacets(); // Hashmap - um array de vCACCAFEConstantValue
for each (var facet in fieldFacets)
{
var value = facet.getValue(); // Objeto vCACCAFEEntityReference
var reservationPType = value.getClassId(); // Tipo da Reservation Policy
var reservationPLabel = value.getLabel(); // Nome da Reservation Policy
}
}
}
// Captura ID da Reservation Policy
var reservationClient = host.createReservationClient(); //Objeto vCACCAFEReservationClient
var reservationPolicyService = reservationClient.getReservationReservationPolicyService(); //Objeto vCACCAFEReservationReservationPolicyService
var reservationPolicyRoot = reservationPolicyService.getAllReservationPolicies(); //Objeto vCACCAFEPagedResources
var reservationPolicies = reservationPolicyRoot.getContent(); // Array de vCACCAFEReservationPolicy
for each (reservationPolicy in reservationPolicies)
{
if (reservationPolicy.name == reservationPLabel && reservationPolicy.reservationPolicyTypeId == reservationPType)
{
var reservationPId = reservationPolicy.id;
break;
}
}
// Captura Reservations que possuam esta Reservation Policy
var reservationService = reservationClient.getReservationReservationService(); //Objeto vCACCAFEReservationReservationService
var reservationRoot = reservationService.getAllReservations(); //Objeto vCACCAFEPagedResources
var reservations = reservationRoot.getContent(); //java.util.Collection - Um array de vCACCAFEReservation
var blueprintReservations = new Array;
for each (var reservation in reservations)
{
if (reservation.reservationPolicyId == reservationPId)
{
blueprintReservations.push(reservation);
}
}
// Captura as redes existentes nas Reservations selecionadas
for each (blueprintReservation in blueprintReservations)
{
var reservationData = blueprintReservation.extensionData //Objeto vCACCAFELiteralMap
// var reservationData = reservation.extensionData;
var networks = reservationData.get("reservationNetworks");
for each(var network in networks.getValue())
{
//var path = network.getValue().get("networkPath");
var networkId = network.getValue().get("networkPath").getValue().getId();
System.log(networkId);
var networkName = network.getValue().get("networkPath").getValue().getLabel();
System.log(networkName);
reservationNetworks.put(networkId, networkName);
}
}
}
return reservationNetworks;