VMware Cloud Community
LetsAutomate
Contributor
Contributor
Jump to solution

Checking if a vm already has a snapshot

Let me apologize in advance if this has been answered but a quick search didn't help me. Also understand I am very new to this with almost zero training so this is probably a newbie question but the community seems very helpful and friendly so I'm reaching out for guidance and advise.

We will be implementing snapshot as a service to our customers. We want to allow only one snapshot per VM. Therefore I need to check if a snapshot exists before allowing the customer to take a new one. I have a simple workflow now to take a single virtual machine and snap it. I am using the built in remove old snapshots to check if a snapshot exists. We use service now as our portal. The hostname comes across as a string and I convert it to a vc:virtualmachine. What I need some help on is in the remove old snapshots I'm reusing the getPropertiesForAllSnapshotTask action element. I want to pass the single vm name and have it get the properties of the snapshot if it exists. As it is an auto generated script I am not able to modify the scripting of the action. Does anyone have a better way or idea on how I can pass a single vm object and know if it has a snap or not? I hope I've explained this well enough to get a discussion started and thanks.

0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Checking if a virtual machine has at least one snapshot is easy. Here is some sample code (the input parameter is the variable vm of type VC:VirtualMachine😞

if (vm.snapshot != null) {

  System.log("This VM has at least one snapshot");

} else {

  System.log("This VM has no snapshots");

}

View solution in original post

0 Kudos
5 Replies
daphnissov
Immortal
Immortal
Jump to solution

Are you using ServiceNow to request from vRA in this case?

0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

Checking if a virtual machine has at least one snapshot is easy. Here is some sample code (the input parameter is the variable vm of type VC:VirtualMachine😞

if (vm.snapshot != null) {

  System.log("This VM has at least one snapshot");

} else {

  System.log("This VM has no snapshots");

}

0 Kudos
LetsAutomate
Contributor
Contributor
Jump to solution

yes that would be correct. It will come from SNOW to vRA.

0 Kudos
LetsAutomate
Contributor
Contributor
Jump to solution

Thank you very much. I have some other tasks at the moment but I'll be sure to give this a try. Appreciate the quick responses from everyone.

0 Kudos
LetsAutomate
Contributor
Contributor
Jump to solution

SO easy. Thank you very much. Really appreciate the assist. I'll mark your answer as correct.

0 Kudos