Using Junos Snapshot Administrator in Python
You can use Junos Snapshot Administrator in Python (jsnapy) on a device running Junos OS to capture and save a runtime environment snapshot, compare two snapshots, or capture a snapshot and immediately evaluate it.
When you take a snapshot, you provide a snapshot name.
Jsnapy uses the snapshot name, target device name from the configuration.yml
or device.yml file, and test file test section strings to generate
snapshot filenames that uniquely identify that snapshot. For example,
say you are collecting data from device junos-device.example.com,
you define the snapshot name SNAP1
, and
your test file has two test sections named ospf-checks
and bgp-checks
. When you take a snapshot,
Junos Snapshot Administrator creates the following output files:
junos-device.example.com_SNAP1_ospf_checks.xml
junos-device.example.com_SNAP1_bgp_checks.xml
The snapshot files are stored on the jsnapy server in the location
specified by the snapshot_path
parameter in the YAML file /etc/jsnapy/jsnapy.cfg
. By default, the location is /etc/jsnapy/snapshots
.
The following sections outline the Junos Snapshot Administrator commands:
Taking a Snapshot
To take a snapshot of a device, enter the following on the jsnapy server’s command line:
user@jsnapy-server$ jsnapy --snap snapshot-name -f configuration-filename
The command parameters are:
snapshot-name
—String used in the output filenames to uniquely identify that snapshot.configuration-filename
—Snapshot configuration filename.
For example, prior to a maintenance upgrade, user bsmith
takes a snapshot of the device. The snapshot name is preupgrade
and the configuration filename is config-snapshot.conf. Since bsmith did not specify
his password in the configuration file config-snapshot.yml, upon connecting,
the device prompts for the user’s password.
bsmith@server$ jsnap --snap preupgrade -f config-snapshot.yml
Connecting to device junos-device.example.com ................ Enter Password for username <bsmith> : Connecting to device junos-device.example.com ................ Tests Included: test_version_check Taking snapshot of COMMAND: show version Tests Included: check_chassis_fpc Taking snapshot of COMMAND: show chassis fpc
Comparing Two Snapshots
To compare two existing snapshots using the test criteria, enter the following on the jsnapy server’s command line:
user@jsnapy-server$ jsnapy --check snapshot1 snapshot2 -f configuration-filename
The command parameters are:
snapshot1
–String used in the output filename to uniquely identify the first snapshot. Often this is entered as PRE, preupgrage, pre-change, or some name to denote that this snapshot came first.snapshot2
—String used in the output filename to uniquely identify the second snapshot. Often this is entered as POST, postupgrage, post-change, or some name to denote that this snapshot came second.configuration-filename
–Snapshot configuration file name.
For example, prior to and immediately following a maintenance
upgrade, user bsmith takes a snapshot of the device. The snapshot
names are preupgrade
and postupgrade
. To compare these two snapshots using the criteria defined in the
configuration file config-snapshot.yml, bsmith issues the following command:
bsmith@server$ jsnap --check preupgrade postupgrade -f config-snapshot.yml
The Junos Snapshot Administrator output displays the target router and the test results for each of the active test sections in the configuration file. Sample output is shown here:
*************************** Device: junos-device.example.com *************************** Tests Included: test_version_check ********************* Command: show version ********************* PASS | All "junos-version" was changed between the pre and post snapshot. It is now 15.1R3.3 [ 1 matched ] ------------------------------- Final Result!! ------------------------------- Total No of tests passed: 1 Total No of tests failed: 0 Overall Tests passed!!!
Taking and Evaluating a Snapshot
To take a snapshot and immediately evaluate it based on a pre-defined set of criteria, enter the following on the jsnapy server’s command line:
user@jsnapy-server$ jsnap --snapcheck snapshot-name -f configuration-filename
The command parameters are:
snapshot-name
—String used in the output filenames to uniquely identify that snapshot.configuration-filename
—Snapshot configuration filename.
For example, a user wants to confirm the number of software packages installed on the router junos-device.example.com. To do this, he runs the following command on the jsnapy server’s command line:
user@jsnapy-server$ jsnapy --snapcheck postupgrade -f config-software-check.yml
The Junos Snapshot Administrator output displays the target router and the test results for each of the active test sections in the configuration file. Sample output is shown here:
Connecting to device junos-device.example.com ................ Taking snapshot of COMMAND: show version *************************** Device: junos-device.example.com *************************** Tests Included: test_version_check *************************** Command: show version *************************** PASS | All "//package-information/name" exists at xpath "//software-information" [ 59 matched ] ------------------------------- Final Result!! ------------------------------- Total No of tests passed: 1 Total No of tests failed: 0 Overall Tests passed!!!