Get network details from vRA8 deployment

Use Case:- "for post-provisioning or day 2 activities, the developer requires the network details for the deployment."
 
Inputs:-
 
DeploymentID:- String
Search:- string 
 
vraHost = System.getModule("com.rishabh.action").getvRAHost(); (get the vra:host stored on configuration element)
var url = "/deployment/api/deployments/"+deploymentid+"/resources"
var restClient = vraHost.createRestClient();
var request = restClient.createRequest("GET", url);
request.setHeader("Content-Type""application/json")
//System.log("Request Headers: " + request.headers);
var response = restClient.execute(request);
statusCodeAttribute = response.statusCode;
System.log("REST Response Status Code: " + statusCodeAttribute);
responseAsString = response.contentAsString;
System.debug("REST Response Content: " + responseAsString);
var parse = JSON.parse(response.contentAsString)
System.log(JSON.stringify(parse))
//var totalresource  = parse.totalElements
if (search == "net1cidr") {
    return parse.content[2].properties.networkCidr
}
if (search == "net2dns") {
    var dns = parse.content[2].properties.dns.join(",").toString()
    return dns
}
if (search == "net2gw") {
    var gw = parse.content[2].properties.gateway
    return gw
}

else {
    return parse.content[2].properties.prefixLength
}


Post a Comment (0)
Previous Post Next Post