Trying to figure out how I can pass the name of a project to a vro action using powercli
You can discover Project Name in different way:
Dany
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?
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;
I hope thats helps to understand
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;