Let’s say you have multiple vRealize Network Insight instances. Maybe a staging instance for trying new searches, alerts, or other configuration – and a production instance. Or you’re migrating from an on-premises instance to a vRealize Network Insight Cloud instance. Or you just want a backup of the hard work you put into curating the applications. As with many things; there’s an API and script for that!

Python SDK & Examples

The Python SDK is a library generated automatically by the OpenAPI specification that vRealize Network Insight has baked in. In addition, it has a ton of example scripts that use the SDK for various things. From importing data sources, exporting flows, running searches, to, you guessed it – creating backups of the applications, including restoring them. You can find the Python SDK on GitHub: https://github.com/vmware/network-insight-sdk-python/ 

Getting the Python SDK

Before you get started, python is a prerequisite. It can be both Python 2 or 3. I’ll be using git in the example output, but you can also download the code in a zip file via the GitHub page. There is also a requirements.txt file that’s used to get the right python modules in place.

Creating an Application Backup

With the SDK in place, we can now run the script named application_backups.py. Let’s look at the built-in help first, to see what parameters are available:

The export command is needed once per terminal session and tells the example scripts where to find the SDK. Most of these parameters are self-explanatory, most of them are for authentication. Pick and choose which parameters you need for your vRNI instance, whether it be an on-premises or Cloud instance. I’ll be using an on-premises instance in the examples. 

There are two parameters that are very interesting: –application_backup_yaml and –application_backup_action. The action can be save or restore, which determine whether it’s a backup (save), or if you’re restoring to vRNI from an existing backup file. Application_backup_yaml points to a YAML file that is stored on disk, which is written too when you run a save action, and read from when you run a restore action.

It’ll rattle off all the applications that are in the source vRNI instance and write the output to apps.yaml. Let’s take a quick look:

I won’t go through the entire file structure, it holds all of the apps including their tiers and definitions. The best part is that it’s text, so you can put it anywhere (including version control!).

Restoring from an Application Backup

If needed, the same script can be used to restore applications from a YAML file as well. It’s just a matter of pointing to the right vRNI instance and changing the application_backup_action to restore. One thing to note is that the script will suffix the application name with -restored. I.e., 3TierApp01-restored. You can change that on line 60 of the application_backups.py script and changing this:

to this:

If you’re fine with the suffix (which can always be changed in vRNI afterwards), you can leave the script alone. Here’s an example of a restore run:

After it’s done running, log into the destination vRealize Network Insight instance and behold your applications!



Share the wealth!