Triggering a snapshot during a workflow?

I’m developing a provisioning workflow to run in our vmware cloud. I want to trigger a snapshot of the VM once it’s booted. What’s the easiest way to set up a task I can drop in the workflow?

Hey @malberg! The easiest way will be calling the API via a post task to call to snapshot. Give me 2 minutes and I’ll whip something up!

So per the API docs here you can do a task like the local executed shell script below.

Optionally you can send a body payload to configure a name/description as well :slight_smile:

URL='<%=morpheus.applianceUrl%>'
INSTANCE='<%=instance.id%>'
TOKEN='<%=morpheus.apiAccessToken%>'

curl -X PUT "$URL/api/instances/$INSTANCE/snapshot" \
  -H "Authorization: BEARER $TOKEN" \
  -H "Content-Type: application/json"
2 Likes

Damn… took me 6 minutes. I have failed you :frowning:

That worked! Thanks!

1 Like

Followup… I need to revert to that snapshot later on in the workflow.

I guess I can use GET $serverUrl/api/instances/:id/snapshots to get the snapshot listing for the instance, then PUT $serverUrl/api/instances/:id/revert-snapshot/:snapshotId to revert. The list of snapshots is returned as json. is there a best practice for parsing JSON inside a bash task?

You can make the API calls in really any language. If you are utilizing bash, probably best bet is to use jquery or something to easily manipulate JSON returns.