VMware Cloud Community
reggieswan
Contributor
Contributor

How to pass vRA 8 Project Name to vRO action

Trying to figure out how I can pass the name of a project to a vro action using powercli

Reply
0 Kudos
4 Replies
DanielStastka
Enthusiast
Enthusiast

You can discover Project Name in different way:

  • Over Rest-API for All Projects => /iaas/projects
  • Over Rest-API with Filter => /iaas/projects?$filter=name+eq+%27" + projectname + "%27
  • Service Broker: Add "Project" Field as General Form by Custom Form and handed over Input-Field in vRO Action

Dany

reggieswan
Contributor
Contributor

Thanks for the response Dany I'm interested in the Service Broker option. Are you able to provided maybe a step by step on how to do that?

Reply
0 Kudos
DanielStastka
Enthusiast
Enthusiast

I try it:

First you must have a Action to get Name of Project by GUID. (The Code have more Information and Search Project by Name OR id). You can Play with Code:

Action: GetProjectNameByProjectId

Input: type: string, name:project

Return: string

 

 

var vraHost = VraHostManager.findHostsByType("vra-onprem").filter(
    function (host) {
        return host.name == 'Default'
    }
)[0];

var filter = "?$filter=id+eq+%27" + project + "%27+or+name+eq+%27" + project + "%27";
var restClient = vraHost.createRestClient();
var request = restClient.createRequest("GET", "/iaas/projects" + filter, "{}");
var response = restClient.execute(request);

var vRaProjects = JSON.parse(response.contentAsString).content.sort(
    function (a, b) {
        return b.name;
    }
).map(
    function (pj) {
        
            return {name: pj.name, customProperties: pj.customProperties, id:pj.id, description: pj.description}
        
    }
);
var returnValue="";
for each (vRaProject in vRaProjects){
   
    System.log("name:"+vRaProject.name);
    System.log("description:"+vRaProject.description);
    System.log("id:"+vRaProject.id);
    System.log("costcenter:"+vRaProject.customProperties.project_costcenter);

    returnValue = vRaProject.name
}
return returnValue;

 

 

 

Second Action (dropdown_usr_env). This is a selector of different environments (Very Simple Sample) as DropDown. Only Team "stastka" have more environments.

input: type: string, name: projectid 

return type string as Array

 

if(projectid!="")
{
    projectName = System.getModule("ch.vra").GetProjectNameByProjectId(projectid);
}

var tempArray = [];
tempArray.push("PROD"); 
if(projectName=="stastka")
{
    tempArray.push("DEV"); 
    tempArray.push("TEST"); 
    tempArray.push("DEBUG");
    tempArray.push("MONITORING");
}
return tempArray;

 

 

  • In the blueprint you have defined Input "usr_dp_env", 
  • On Service Broker, => Content => Catalog Item
  • on top click "Enable" to Enable Custom Forms
  • Insert Input usr_dp_env
  • Configure External Source and Search the action
  • Configure Input Field projectid with Project
  • CustomForms.png

I hope thats helps to understand

Reply
0 Kudos
Flynch00
Enthusiast
Enthusiast

Hi guys,

 

For me there is no needs to use REST API to request Project Name from Project ID (which is a native Field input). You can do that with only 2 lines using the VraEntitiesFinder.

 

//Retrieve vRA Host - Works only if there is 1 vRA Endpoint
var vraHost = Server.findAllForType("VRA:Host",null)[0];

//Return the Project Name
return VraEntitiesFinder.getProject(vraHost, projectId).name;