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 Configuration Files

The Junos Snapshot Administrator in Python (jsnapy) configuration files define the scope of a snapshot and specify the names of the files containing the test criteria for either a single snapshot or a comparison of two snapshots. You provide the location of the jsnapy configuration file as an argument to the jsnapy command or as an argument when calling jsnapy from another Python script.

Where to Store a Configuration File

The jsnapy configuration files can be stored anywhere on the jsnapy server’s file system. If the configuration file does not exist in the current working directory from which jsnapy is called, jsnapy looks in the path specified in /etc/jsnapy/jsnapy.cfg under the config_file_path heading. If the file does not exist there, jsnapy looks in the default location (/etc/jsnapy/) for configuration files. If the file does not exist there either, an error is displayed. To use a specific configuration file, you can specify the full path to the configuration file on the command line when calling jsnapy. For example:

Understanding the Sections of a Configuration File

Jsnapy configuration files consist of two mandatory sections: hosts and tests, and two optional sections: sqlilte and mail.

  • The hosts section defines which Junos OS hosts or devices jsnapy connects to when using the configuration file. Jsnapy can connect to a single host or to multiple hosts. Configuration files that direct jsnapy to connect to a single host define the host IP address and login credentials within the configuration file.

    Configuration files that direct jsnapy to connect to multiple hosts use the include feature of YAML files to read a list of hosts and credentials from a separate YAML devices file. Devices files can be large files with many hosts listed. To use fewer hosts, the devices file can be broken up into groups that are referenced using the group: keyword in the hosts section of the configuration file. For more information, seeUnderstanding Junos Snapshot Administrator in Python Device Files. To specify which file contains the list of devices, enter the name of the file or the full path to the file. When only the filename is supplied, the location of the file follows the rules described in Where to Store a Configuration File.

  • The tests section tells jsnapy which test files to use when using the configuration file. The tests to be performed against the hosts are always defined in separate test files whose names are specified within the tests section of the configuration files. Multiple test filenames can be entered, each on its own line. Test filenames can be supplied as a filename or as the full path to the file. When only the filename is supplied, the location of the file follows the rules described in Where to Store a Configuration File. For more information, see Understanding Junos Snapshot Administrator in Python Test Files and Example: Creating the Junos Snapshot Administrator in Python Test Files.

  • The sqlite section defines the parameters for storing and comparing snapshots in an SQLite database. You can specify whether snapshots created with this configuration file should be stored in a specific SQLite database in addition to being stored in the jsnapy server’s file system. You can also specify whether --check and --snapcheck options perform the compare operations on snapshots stored in the SQLite database. The SQLite database can store up to 51 snapshots, and these are indexed by ID numbers 0 through 50. Table 2 describes the configuration elements needed to configure snapshot storage in an SQLite database.

  • The mail section includes the name of the file containing e-mail configuration information. The mail file can be supplied as a filename or as a full path to the file. When only the filename is supplied, the location of the file follows the rules described in Where to Store a Configuration File. The details of what is contained in the mail file are described in Understanding Junos Snapshot Administrator in Python Mail Files.

Elements of a Configuration File

The jsnapy configuration files are YAML files that you build using combinations of keywords and values that are pertinent to your network. Like any YAML file, structure is derived through indentation (one or more spaces), sequence items are denoted by a dash (-), and key-value pairs are separated by a colon (:). Table 1 shows the supported keywords and their meaning.

Table 1: Configuration File Keywords and Descriptions

Keyword

Description

hosts

This keyword denotes the beginning of the hosts section. It must be on a line by itself and must be followed by a colon. (hosts:)

group

This keyword is an optional part of the hosts section. It refers to device group names within an external devices file (when contacting multiple hosts). It must be on a line by itself and must be followed by a colon. (group:) The group name used here must be a case-sensitive match to the group name in the external devices file. To include all hosts in the devices file, use the value all in place of any group name.

device

This keyword is part of the hosts section. It is preceded by a dash and followed immediately by a colon (- devices:). Single hosts can be contacted by specifying their IP address. Multiple hosts can be contacted by specifying a separate devices file (also in YAML format) that contains a listing of multiple device IP addresses.

include

This optional keyword is part of the hosts section. It is preceded by a dash and followed immediately by a colon. It specifies the name of a file that contains multiple device IP addresses and login credentials. It is needed only when you are connecting jsnapy to multiple hosts.

username

This keyword is part of the hosts section. It is followed immediately by a colon. It specifies a username that is used when contacting the device listed directly above it in the configuration or devices file.

passwd

This keyword is part of the hosts section. It is followed immediately by a colon. It specifies the login password used when contacting the device listed immediately above it in the configuration or devices file.

tests

This keyword denotes the beginning of the tests section. It is followed immediately by a colon. It is used to list one or more test files that are used to create or compare snapshots.

sqlite

This keyword denotes the beginning of the sqlite section. It is followed immediately by a colon. The sqlite section is used to define the parameters for storing snapshots in or comparing snapshots from an sqlite database. To complete this section, you must fill in the parameters shown in Table 2.

mail

This keyword activates the e-mail capability. It is followed by a colon. The argument is the name of a file that contains e-mail configuration information; for example, mail: mail.yml. When activated, e-mail is sent regarding the results of --check and --snapcheck operations, but is not sent when using the --snap option.

Table 2 shows the available parameters for filling in the sqlite section of the configuration file.

Table 2: SQLite Configuration Parameters

Parameter

Description

- store_in_sqlite:

Required when using the --snap option. Optional with the --check or --snapcheck options. Set to true to activate.

database_name

Required regardless of option. Specifies the name of the sqlite database in which to store or read the snapshot.

check_from_sqlite

Required for --check or --snapcheck options. Optional for --snap option. Set to true to activate.

compare:

Required if you are comparing two snapshots by snapshot ID number (0-50) with the --check or --snapcheck options. Ignored if you compare by snapshot name using the command line; for example, jsnapy --check PRE POST -f config.yml.

Inserting Comments into a Configuration File

Comments can be inserted into the file at any location by starting the comment with the pound sign (#). This is useful for users who need to manage multiple configuration files so that they can quickly understand what is contained in the file.