vRA 8 - Delete all the Deployment based on user

 Inputs:

vraHost (vra:Host)

userID (string)

var url = "/deployment/api/deployments";
var contentType = "application/json"
var requestResponse = System.getModule("com.onboarding.vra8").executeRestOp(vraHost, url, contentType, "GET", null);
var alldeployments = JSON.parse(requestResponse).content;
for each(var deployment in alldeployments) {
    if (deployment.createdBy == userID) {
        System.log(deployment.name + " found with id " + deployment.id)
        deploymentId = deployment.id;
        var url = "/deployment/api/deployments/" + deploymentId + "/requests";
        var contentType = "application/json"
        var body = {
            "actionId": "Deployment.Delete",
            "inputs": {},
            "reason": "Deleting from API"
        }
        var requestBody = JSON.stringify(body)
        var requestResponse = System.getModule("com.onboarding.vra8").executeRestOp(vraHost, url, contentType, "POST", requestBody);
        System.log("Deleting the Deployment:- "+requestResponse);
    }
}

Post a Comment (0)
Previous Post Next Post