VMware Cloud Community
Halukkocaman
Enthusiast
Enthusiast
Jump to solution

SnapShot Workflow

Hi All,

I'm trying to create a workflow that would take a snapshot and remove the snapshot (not all snapshots) after x amount of min, hours or days. So far I copy the "Create a Snapshot" workflow and add a Scriptable task for the wait time to remove the snapshot but I cannot figure it out how to remove only one snapshot instead of all. Scriptable task for the time works fine. In the create snapshot process you have to give name and description to snapshot so I'm wondering if removing snapshot can be bind with them. 

pastedImage_1.png

Thank you,

Tags (3)
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Yes, you have to create a new action item. Here are the steps:

  • Open vRO Java client and switch to 'Design' perspective (using the drop down on the top, right next to label 'vmware vRealize Orchestrator' at top left)
  • Open the 'Actions' tab on the left pane.
  • Right-click on the root node and select 'New module...' command. Provide some name eg. com.haluk.myactions
  • Right-click on the newly created folder node and select 'Add action...' command. Name it eg. removeSnapshot
  • At this point, the newly created action should open in the action editor. Make sure you are on 'Scripting' tab.
  • Near the top left corner, there is the action return type. Click on the 'void' link, type 'VC:Task' (without quotes) in the filter box, and accept the selected VC:Task type.
  • Under the return type, click on 'Add parameter' button. This should add an action input parameter named arg0 of type string.
  • Click on the arg0 and the string links, and change the name to snapshot and type to VC:VirtualMachineSnapshot.
  • In the action script editor, enter the following code

if (snapshot == null) {

    throw "ReferenceError: snapshot cannot be null"

}

return snapshot.removeSnapshot_Task(false);

  • Click 'Save and Close' button.

That's it. The new action is created and you should be able to use it in your workflow.

View solution in original post

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

Hi,

'Create a snapshot' workflow has an output parameter snapshot (of type VC:VirtualMachineSnapshot) containing the created snapshot object. And the snapshot scripting type has a method removeSnapshot_Task() which you can use to remove the snapshot, using a code like:

snapshot.removeSnapshot_Task(false);

One small issue is that the output parameter snapshot cannot be accessed directly as an input in your scriptable task, but you can fix this by moving the snapshot output parameter as attribute.

Reply
0 Kudos
Halukkocaman
Enthusiast
Enthusiast
Jump to solution

I'm not sure where should I add the code? should a add another Scriptable task after the  "Time to Wait" task?

pastedImage_0.png

Reply
0 Kudos
sakthivelramali
Enthusiast
Enthusiast
Jump to solution

Hi

Find the below ,more details related to snapshot workflow.it will easy to understand.

www.vmwarebits.com/content/vcenter-orchestrator-workflows-create-and-delete-snapshots-folder-vms

Thanks

Thanks Sakthivel R
Reply
0 Kudos
Halukkocaman
Enthusiast
Enthusiast
Jump to solution

Yes I saw this one too but this workflow removes all the snapshot on the virtual machine. I would like to remove the snapshot I take with the workflow. For example if  I have snapshot1, and snapshot2 on the machine already and I'm running this workflow to create a new snapshot named snapshot3 and schedule to remove it in 48 hours. After 48 hours only snapshot3 should be deleted not all of them.

Thank you,

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Yes, it could be another Scriptable task after the  "Time to Wait" task. Or you can create a new action removeSnapshot, put the code inside it, and use it the same way as you do with the createSnapshot action.

Also note that snapshot.removeSnapshot_Task(false); call returns a VC:Task object so you may want to wait for it to complete the same way you wait for createSnapshot using vim3WaitTaskEnd action.

Reply
0 Kudos
Halukkocaman
Enthusiast
Enthusiast
Jump to solution

When I add an Action element and search "Remove", only remove actions related to snapshot is "removeallsnapshot" or "removeOldestSnapshot" I don't see just remove snapshot. Do I have to create a new action item? if so can you please walk me through the creation and what I need to be added in it.

Thank you,

Haluk

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Yes, you have to create a new action item. Here are the steps:

  • Open vRO Java client and switch to 'Design' perspective (using the drop down on the top, right next to label 'vmware vRealize Orchestrator' at top left)
  • Open the 'Actions' tab on the left pane.
  • Right-click on the root node and select 'New module...' command. Provide some name eg. com.haluk.myactions
  • Right-click on the newly created folder node and select 'Add action...' command. Name it eg. removeSnapshot
  • At this point, the newly created action should open in the action editor. Make sure you are on 'Scripting' tab.
  • Near the top left corner, there is the action return type. Click on the 'void' link, type 'VC:Task' (without quotes) in the filter box, and accept the selected VC:Task type.
  • Under the return type, click on 'Add parameter' button. This should add an action input parameter named arg0 of type string.
  • Click on the arg0 and the string links, and change the name to snapshot and type to VC:VirtualMachineSnapshot.
  • In the action script editor, enter the following code

if (snapshot == null) {

    throw "ReferenceError: snapshot cannot be null"

}

return snapshot.removeSnapshot_Task(false);

  • Click 'Save and Close' button.

That's it. The new action is created and you should be able to use it in your workflow.

Reply
0 Kudos
Halukkocaman
Enthusiast
Enthusiast
Jump to solution

Ilian, thank you for fast respond.

I create the action element and added to me workflow.

pastedImage_0.png

pastedImage_1.png

When I run the workflow it give me the error message below.

pastedImage_2.png

Here is removeSnapshot action element looks like in the workflow

pastedImage_3.png

pastedImage_4.png

pastedImage_5.png

pastedImage_6.png

Looks like I have to bind the Snapshot in to something but only option is NULL or Create parameter/attribute in workflow.

Reply
0 Kudos
MikaelPareChabo
Enthusiast
Enthusiast
Jump to solution

Hi,

You need to bind a snapshot parameter to the "remove snapshot" action. If you look in the existing workflow " Library / vCenter / Virtual Machine management / Snapshot / Create a snapshot", you would find the "vim3WaitTaskEnd" has an Output to an "Out parameter".

Transfert this "Out parameter" to an attribute and use it as an Input in your "removesnapshot" action.