Skip to content

Instantly share code, notes, and snippets.

@YagmurOzden
Created December 24, 2021 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YagmurOzden/2b3417e9c934eb6428a720df01ac8d6a to your computer and use it in GitHub Desktop.
Save YagmurOzden/2b3417e9c934eb6428a720df01ac8d6a to your computer and use it in GitHub Desktop.
Deletes the selected snapshot or all snapshots in the selected virtual machine. (VMware vRO workflow, vSphere, snapshot, VM, Virtual Machine)
// VMware vRealize Orchestrator action sample
// vRA 8.4
//workflow input type: VM (VC:VirtualMachine)
// snapshotname (string)
// removeAllSnapshotsOfVM
//workflow output type:
function removeSnapshotOfVM(vm,snapshots){
if (vm.runtime==null || vm.runtime.connectionState == VcVirtualMachineConnectionState.connected){
System.log(vm.name+" is connected to the server.")
if(snapshots.length >0){
for (i in snapshots){
//looks for the snapshot we want to delete in the snapshot list. Deletes that snapshot when found
if(snapshotname==snapshots[i].name){
System.log( snapshots[i].name+ " = "+ snapshots[i].name.toString()+" the selected snapshot will be removed");
snapshots[i].removeSnapshot_Task();
}
//if the variables are not the same.That means the snapshot we want to delete is not in the snapshot list of VM
else if (snapshotname!=snapshots[i].name){
System.log(snapshotname+" == "+snapshots[i].name);
System.log(i+" No snapshot according to the input entered")
}
}
}else{
throw("there is no snapshot to delete");
}
}else{
throw(vm.name+" is not connected. ");
}
}
function removeSnapshotsOfVM(vm,snapshots){
for (i in snapshots){
System.log(vm.name+" "+snapshots[i].name+" deleted.")
snapshots[i].removeSnapshot_Task();
System.log("-------------------")
}
}
if (removeAllSnapshotsOfVM==true)
removeSnapshotsOfVM(vm,snapshots);
else if(removeAllSnapshotsOfVM==false)
removeSnapshotOfVM(vm,snapshots);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment