VMware Cloud Community
airinaga
Contributor
Contributor
Jump to solution

Need help with getting snapshot and decision after... Help Please!

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;

}

Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Yes, it is possible.

Perhaps the easiest way is to define a workflow attribute (of type VC:Datastore), select its value using the chooser, and then use it in your workflow the same way you used the input parameter.

Another option would be to set 'Default Value' decorator in the presentation for datastore input parameter and bind it to an scripting action that returns the desired datastore object value.

View solution in original post

Reply
0 Kudos
4 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

I'm not sure what your 'get snapshot script' does, but if you just want to get the snapshot(s) of a given VM take a look at stock getAllSnapshotsOfVM scripting action that comes with vCenter plug-in (in com.vmware.library.vc.vm.snapshot category). Are you sure your code if working correctly? Do you see the log message you are printing when there is a snapshot?

Also, the label of your 'have snapshot decision' code looks a bit misleading - it returns true if there is NO snapshot and false otherwise Smiley Happy (but it seems to be wired correctly on the workflow schema).

airinaga
Contributor
Contributor
Jump to solution

Thank you for your input, I was able to get it working with the GetAllSnapshotsOfVM plugin.. I have another question.. I'm wondering if it is possible to code in a default datastore to the 'Relocate VM' task... For example, instead of having datastore as an input parameter, is it possible to just code it in so I don't have to select a datastore everytime?   Below is the code for the generic 'Relocate VM' task. Any help is always much appreciated.

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Yes, it is possible.

Perhaps the easiest way is to define a workflow attribute (of type VC:Datastore), select its value using the chooser, and then use it in your workflow the same way you used the input parameter.

Another option would be to set 'Default Value' decorator in the presentation for datastore input parameter and bind it to an scripting action that returns the desired datastore object value.

Reply
0 Kudos
carl1
Expert
Expert
Jump to solution

Also, if you use it in multiple workflows, you can use configuration properties (which are really global variables).

Carl L.