Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?


Understanding Junos Snapshot Administrator in Python when Running as a Python Module


Junos® Snapshot Administrator in Python (jsnapy) enables you to capture and audit runtime environment snapshots of your networked devices running the Junos OS. Jsnapy can be run from the command line of a network server (jsnapy server) or called as a module from within other python scripts on the jsnapy server. See Junos Snapshot Administrator in Python Overview for details about CLI operation.

Once installed on the network server, jsnapy is ready to be used as a module within other python scripts and programs. No further configuration is needed. Jsnapy retains all of its functionality when used as a module in a python script or program.

In order to use jsnapy as a module inside of another python script, you must first use the python import statement so that the python script has access to jsnapy features. Because the script relies not only on jsnapy but also an understanding of Junos OS devices when working with snapshots, you must create two distinct import statements, each importing a different module from the available Juniper python libraries, jnpr.

Importing he SnapAdmin module gives the script or program access to all of the same jsnapy options available on the command line. When used within the script, the SnapAdmin() function is usually assigned to a variable for use later in the script. Arguments are passed to SnapAdmin() to control the available jsnapy options. The following example assigns SnapAdmin to the variable js and then calls jsnapy with each of the 3 major options, snap, check, and snapcheck.

Assign the SnapAdmin Function to a Variable

Call jsnapy 3 Times

The Device module allows python scripts to be able to connect-to, login, and run commands on Junos OS devices. You supply connection IP address, username, and password arguments when calling the Device module from within python scripts. For example, the following line from a python script creates a variable called device_object for use later in the script.

The variables named as argument values above can come from a variety of sources.

  • You can build the configuration file information into the python script by creating a variable in which to store the data and then specifying all of the host and test information needed to connect to and test that device. For example,

  • You can specify an existing YAML formatted configuration file that contains connection and test information for the target device. For example:

  • You can use a combination of a script defined device object for connection purposes and a list of existing YAML formatted test files to test the device. For example, the following line uses the previously defined device_object along with a list of tests to run and a name for the snapshot file.

A wide variety of options are available when running jsnapy from within other Python scripts or programs. Strong familiarity with Python scripting and Junos OS device interaction is helpful in learning what is possible.