-
Notifications
You must be signed in to change notification settings - Fork 2
/
removeSnapshotORSnapshots.js
57 lines (39 loc) · 1.75 KB
/
removeSnapshotORSnapshots.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 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)