“archive_days” is the amount of days a vRA resource will be held in vRA after having the lease expire. By default, a VM that is deployed or imported inherits the archive days from the blueprint. Even if the blueprint is modified, the existing VM will hold the original amount of days to hold the vRA object. I wrote this action to make this customizable on a per VM basis from vRO. For a recent client’s Decommission process, they wanted the ability to set the hold time by asking the user how long to hold a VM.
var vmStatus = null; // Get Resource ID query = "select * from cat_resource where binding_id = '" + targetVmID + "';"; vmRecord = cafeDB.readCustomQuery(query); //if (vmRecord.length != 0) { vmStatus = vmRecord[0].getProperty("status"); } if (vmRecord.length != 0) { vmRecordID = vmRecord[0].getProperty("id"); vmParentID = vmRecord[0].getProperty("parentresource_id"); vmRecordName = vmRecord[0].getProperty("name"); vmStatus = vmRecord[0].getProperty("status"); System.log("Current VM Status : " + vmStatus); // Get Parent Record //query = "select * from cat_resource where id = '" + vmParentID + "';"; //vmParentRecord = cafeDB.readCustomQuery(query); System.log(vmRecordName + " : " + vmRecordID); // Set Archive Days update = "UPDATE cat_resource SET archive_days = '" + archiveDays + "' WHERE binding_id = '" + targetVmID + "';" cafeDB.executeCustomQuery(update); // Mark Parent VM Record as DELETED update = "UPDATE cat_resource SET archive_days = '" + archiveDays + "' WHERE id = '" + vmParentID + "';" cafeDB.executeCustomQuery(update); System.log("Archive days set in CAFE DB"); } else { System.error("Target VM: " + targetVmID + " NOT found"); }
Leave a Reply