Since version 0.19, Skydive allows you to automate Skydive actions using a new type of object called
Let’s imagine you want to test the connectivity between 2 containers. If you had to do it manually, you would:
- create a capture on the interface of each container
- generate some traffic using the packet injector
- use a Gremlin query to check for flows corresponding to the generated traffic
- delete the captures
In this blog post, we will see how you can script these actions using workflows.
- from the Skydive command line shell (using
skydive client shell)
- from inside a browser (using the new
Workflowstab in the Web interface)
- from a program written in NodeJS
In this blog post, we will use the first 2 methods to develop and execute our workflow.
Seriously, did you really expect to avoid an
Hello World ! example in such a blog post ? For this example, we will use
the Skydive command line shell. When starting it, we will be welcomed with the following prompt:
node command. Let’s now write
A more complicated example
In this example, we will create a simple API between 2 nodes.
First, let’s create a file
create-capture.js with the following content:
Then let’s execute this function:
If everything is fine, you should have the output:
(itself returned by the
client.captures.create function). The reason is that, to create the capture, an HTTP call to the Skydive
API is done. The actual API will only be done when the Promise is realized with the call to the
We provide two functions to this
- the first one will be called if the call is successfull
- the other one will be called if an error occurred
Promises are particularly usefull when you need to chain calls and that’s exactly what we are going to do with the real workflow we want to implement in this blog post.
Our first workflow
A Skydive workflow is composed of:
- a name and an optional description of what the workflow does
- the parameters to pass to this workflow
Workflows can be uploaded to the Skydive API through a YAML file. Let’s create the corresponding file
create-capture.yml for our previous example.
If we now go the the Skydive WebUI and click on the
Workflows tab on the top right, you should be see our new workflow:
If you select this new
CreateCapture workflow, two input fields - corresponding to the parameters of our workflow - will appear.
As our parameters have the
node type, they will appear as node selectors. Select a source node and a destination, then click on
Execute. The capture should have been successfully created.
Wrapping everything together
and the YAML for this workflow could be written like this:
You can notice that we wait for 2 seconds between the capture creation and the packet injection to give Skydive some time to create the capture on the agent. We also wait a bit before querying the flows to let them enter the agent’s flow table.
The flow query is done using
Gremlin syntax and returns a promise that, when realized, will make a single request to the Skydive
analyzer with the full Gremlin request.
Our workflow returns an object with:
- State: that can be either
- Flows: the ICMP flows that were found
Let’s upload our complete workflow:
Finally, let’s run our workflow using the WebUI will give the following output:
In this blog post, we saw how to develop our own workflow. A few workflows are already bundled into Skydive such as FlowMatrix which is the flow matrix utility described in a previous blog post, originally written in Python as an external tool that was converted into a Skydive workflow. The list of available workflows is small as the feature was added recently but expect more to appear soon. Don’t hesitate to submit your workflow as a pull request, your help will me really much appreciated.