Hi rfrilling
Start by duplicating the workflow so that you can edit it.
In the duplicate workflow edit the Get snapshots scriptable task. At the end of the scriptable task you will see the following code:
if(days>numbrOfDay){
snapshots.push(ss);
System.log("The snapshot "+searchResults[i].folderPath +files[j].path+" of the VM "+ss.config.name+" had "+Math.floor(days)+" days");
snapshotProperties.remove(folderPath + files[j].path);
}
This if statement is controlling whether a snapshot is selected based on its age. To add an extra condition to check based on a keyword you can use the Snapshot name or description value and use the search method to see if your keyword is present and exclude any snapshots where the keyword is present.
The search method will return a value of -1 if the keyword is not found, so in your requirements you can use the -1 value returned by search to identify that the snapshot should be removed.
Using the snapshot name as an example your updated code would look like this, I've included the block of code above the snapshot date check as well as I'm capturing the snapshot name after the if statement which checks the snapshot value is not null:
if(ss){
//If a snapshot is found capture the snapshot name
var snapshotName = ss.name;
if(instanceObject==null){
instanceObject = VcPlugin.convertToVimManagedObject(ss , instance);
}
dateNow = instanceObject.currentTime();
timeForDateNow = dateNow.getTime();
timeForDateModif = files[j].modification.getTime();
diff = timeForDateNow-timeForDateModif;
days = diff/86400000;
//Now add a new condition to the if statement to check the date AND if the keyword is not present using a case insensitive search
//If the snapshot is old enough and does not contain the keyword in its name then add it to the array of snapshots to be removed
if((days>numbrOfDay) && (snapshotName.search(/keyword/i) == -1)){
snapshots.push(ss);
System.log("The snapshot "+searchResults[i].folderPath +files[j].path+" of the VM "+ss.config.name+" had "+Math.floor(days)+" days");
snapshotProperties.remove(folderPath + files[j].path);
}
The above code would replace the existing lines in the scriptable task, so the final Get snapshots scriptable task would look like this:
snapshots = new Array();
var searchResults = System.getModule("com.vmware.library.vc.vm.snapshot").getAllSnapshotResultInDatastoreBrowser(false,false,false,true) ;
var instance = new VcManagedObjectReference();
instance.type = "ServiceInstance";
instance.value = "ServiceInstance";
var instanceObject = null;
var dateNow;
var timeForDateNow;
var timeForDateModif;
var diff;
var days;
var ss;
var folderPath;
for (var i in searchResults) {
var files = searchResults[i].file;
for (var j in files) {
folderPath = searchResults[i].folderPath;
folderPath = folderPath.charAt(folderPath.length - 1) === '/' ? folderPath : folderPath + '/';
ss = snapshotProperties.get(folderPath + files[j].path);
if(ss){
var snapshotName = ss.name;
if(instanceObject==null){
instanceObject = VcPlugin.convertToVimManagedObject(ss , instance);
}
dateNow = instanceObject.currentTime();
timeForDateNow = dateNow.getTime();
timeForDateModif = files[j].modification.getTime();
diff = timeForDateNow-timeForDateModif;
days = diff/86400000;
if((days>numbrOfDay) && (snapshotName.search(/keyword/i) == -1)){
snapshots.push(ss);
System.log("The snapshot "+searchResults[i].folderPath +files[j].path+" of the VM "+ss.config.name+" had "+Math.floor(days)+" days");
snapshotProperties.remove(folderPath + files[j].path);
}
}
}
}
Hope this helps, let me know if you have any questions.