VMware Cloud Community
tivs
Enthusiast
Enthusiast

difference between getAllSnapshotsOfVM()” and “getAllSnapshotResultInDatastoreBrowser(false,false,false,true)”;

What is the difference between “getAllSnapshotsOfVM()” and “getAllSnapshotResultInDatastoreBrowser(false,false,false,true)”;     Where  can I find more information and examples on VMware orchestrator -->snapshots

0 Kudos
4 Replies
evil242
Enthusiast
Enthusiast

I have this question too.  I am trying to rework a workflow to delete old snapshots of one VM.  I tried using getAllSnapshotsOfVM in place of getAllSnapshotResultInDatastoreBrowser and the workflow failed.

Damion Terrell  .   +  (He/Him)  +  . *  .  +   @   + .    *  .    +      .                    
Core IT Service Specialist * . + * . + . + . + * +
UNM – IT Platforms – VIS + . . . . . . . . .
. + . + * . + * .
* . . + . . . . + . + * + .
“You learn the job of the person above you, * + . + * @
and you teach your job to the person below you..” . * +
0 Kudos
iiliev
VMware Employee
VMware Employee

Well, these 2 scripting actions do different things:

  • getAllSnapshotsOfVM returns a list of all snapshots of a given virtual machine
  • getAllSnapshotResultInDatastoreBrowser returns a list of all snapshot files on all datastores (not specific for a given virtual machine).

Could you give more information about what is not working for you? Eg. attach your workflow and show the exact error you are receiving.

0 Kudos
evil242
Enthusiast
Enthusiast

I should pay attention a little more to responses, apologies for not getting back sooner to this.  I dove into this and got something working.  At this point, I forgot what the error was, but here is what I did:

I have revamped a provided workflow Library > vCenter > Virtual Machine Management > Snapshot > Remove old Snapshots.

The workflow unfortunately searches for snapshots in a Datastore:

var searchResults = System.getModule("com.vmware.library.vc.vm.snapshot").getAllSnapshotResultInDatastoreBrowser(false,false,false,true) ;

And then searches through

ss = snapshotProperties.get(searchResults[i].folderPath+files[j].path);

I switched to passing in a single VM with a snapshot and using:

var searchResults = System.getModule("com.vmware.library.vc.vm.snapshot").getAllSnapshotsOfVM(VMtoClean);

I then used

function getSnapshotsOfVM(tree) {

localsnapshotslist.push([tree.snapshot, tree.createTime]); // store a tupple of the snapshot and its creation time

var trees = tree.childSnapshotList;

if (trees != null) {

for (index in trees) {

if (trees[index] != null)

getSnapshotsOfVM(trees[index]);

}

}

}

to find the snapshots

var snapshotTrees = VMtoClean.snapshot.rootSnapshotList;

for (i in snapshotTrees) {

getSnapshotsOfVM(snapshotTrees[i]);

}

And then evaluate age

for each (var s in localsnapshotslist) {

System.log("Looking at " + s[0].id);

//System.log("Found " + searchResults[i].file + " snapshot files");

//System.log("Found " + searchResults[i].folderPath+files[j].path + " snapshot path");

if(s[0]){

if(instanceObject==null){

instanceObject = VcPlugin.convertToVimManagedObject(s[0] , instance);

}

dateNow = instanceObject.currentTime();

timeForDateNow = dateNow.getTime();

timeForDateModif = s[1].getTime();

diff = timeForDateNow-timeForDateModif;

days = diff/86400000;

if(days>numbrOfDay){

snapmessage = snapmessage + "- * - Snapshot "+ s[0].name + " created on " + s[1] + " is " + Math.floor(days) + " days old" + ENDL;

System.log("The snapshot "+ s[0].id +" of the VM "+s[0].config.name+" had "+Math.floor(days)+" days");

snapshots.push(s[0]);

//System.log("The snapshot "+searchResults[i].folderPath +files[j].path+" of the VM "+ss.config.name+" had "+Math.floor(days)+" days");

//snapshotProperties.remove(searchResults[i].folderPath+files[j].path);

}

}

}

I still use the call  (removeChildren = false, ConsolodateDisk = true) to remove the snapshot:

var task = activeSnapshot.removeSnapshot_Task(removeChildren,ConsolodateDisk);

var actionResult = System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(task) ;

I then use the workflow Library > vCloud Automation > Extensibility > Force Data collection, which includes the javascript:

var modelName = 'ManagementModelEntities.svc';

var entitySetName = 'DataCollectionStatuses';

//Read a list of entities

var entities = vCACEntityManager.readModelEntitiesByCustomFilter(host.id, modelName, entitySetName, null, null);

for each (entity in entities) {

var entityKey = entity.keyString;

System.log("Updating entity with key: " + entityKey);

var links = null;

var headers = null;

var updateProperties = {

"LastCollectedTime":null

};

vCACEntityManager.updateModelEntityBySerializedKey(host.id, modelName, entitySetName, entityKey, updateProperties, links, headers);

}

Screen Shot 2016-08-01 at 4.56.37 PM.png

Damion Terrell  .   +  (He/Him)  +  . *  .  +   @   + .    *  .    +      .                    
Core IT Service Specialist * . + * . + . + . + * +
UNM – IT Platforms – VIS + . . . . . . . . .
. + . + * . + * .
* . . + . . . . + . + * + .
“You learn the job of the person above you, * + . + * @
and you teach your job to the person below you..” . * +
0 Kudos
evil242
Enthusiast
Enthusiast

In addition here are the inputs and attributes:

Screen Shot 2016-08-01 at 4.57.36 PM.pngScreen Shot 2016-08-01 at 5.02.07 PM.png

Damion Terrell  .   +  (He/Him)  +  . *  .  +   @   + .    *  .    +      .                    
Core IT Service Specialist * . + * . + . + . + * +
UNM – IT Platforms – VIS + . . . . . . . . .
. + . + * . + * .
* . . + . . . . + . + * + .
“You learn the job of the person above you, * + . + * @
and you teach your job to the person below you..” . * +
0 Kudos