I would like to find out if a VM has a snapshot.... If it does, I need the workflow to terminate and send and email. If it does not have a snapshot then it can continue with the workflow. I've got everything working except the decision part, In this case it will say there is a snapshot when there actually isn't and terminate the workflow........ workflow and script is documented below. Any help is much appreciated!
Get Snapshot Script:
Snapshot = new Array();
var vms = VcPlugin.getAllVirtualMachines();
for(i in vms){
var vm = vms[i];
if(vm.runtime.connectionState.value=="connected" && !vm.config.template){
var vmLayout = vm.layoutEx;
if(vmLayout!=null){
var layoutFiles = vmLayout.file;
var layoutSnapshots = vmLayout.snapshot;
for(l in layoutSnapshots){
var layoutSnapshot = layoutSnapshots[l];
var dataKey = layoutSnapshot.dataKey;
for(m in layoutFiles){
if(layoutFiles[m].key==dataKey){
if(layoutFiles[m].size/1024/1024>snapshotSize){
var snapshot = VcPlugin.convertToVimManagedObject(vm,layoutSnapshot.key);
Snapshot.push(snapshot);
System.log("Name : " +layoutFiles[m].name + " - Size : " + layoutFiles[m].size);
}
}
}
}
}
}
}
Have snapshot decision:
if(Snapshot.length>0){
return false;
}else{
return true;
}