vRA 8 - Get vRA VM Property

 Inputs:- 

machineID (string)

vraHost (vra:HOST)

propertyReference(string) (name of the property)


var url = "/iaas/api/machines";
var restClient = vraHost.createRestClient();
System.log("Machine ID for this property: "+machineID)
var request = restClient.createRequest("GET", url + "/" + machineID);
request.setHeader("Content-Type", "application/json")
var response = restClient.execute(request);
statusCodeAttribute = response.statusCode;
System.log("REST Response Status Code: " + statusCodeAttribute);
responseAsString = response.contentAsString;
//System.log("REST Response Content: " + responseAsString);
var machine = JSON.parse(response.contentAsString)
System.log(JSON.stringify(machine))
System.log("Property Reference: "+propertyReference)
var propertyValue = machine[propertyReference]
if (propertyValue) {
    return propertyValue
}


else {
    var custompropertyValue = machine.customProperties[propertyReference]
    if (custompropertyValue){
    return custompropertyValue
    }
}

Post a Comment (0)
Previous Post Next Post