Example: Creating the Junos Snapshot Administrator in Python Configuration Files
This example demonstrates how to create some basic Junos Snapshot Administrator in Python (jsnapy) configuration files. The examples in this topic us specific numbers of spaces sometimes before any other text is entered on a line. These spaces are required for proper formatting of the YAML file.When usernames and passwords need to be typed in these examples, replace the word user with a valid username and the <password> text with a valid password.
Requirements
Junos Snapshot Administrator in Python Release 1.0 is installed on the server.
Overview
This topic describes, how to create multiple jsnapy configuration files:
A configuration file that connects to one specific host and runs one specific test
A configuration file that connects to one specific host, runs two tests, and sends the results by e-mail
A configuration file that connects to a group of hosts, runs one test, and stores the snapshot in an SQLite database
Junos Snapshot Administrator in Python configuration files consist of two mandatory sections: hosts and tests, and two optional sections: sqlilte and mail. The configuration files that direct jsnapy to connect (using Junos PyEZ and NETCONF) to a single host define the host IP address and credentials within the configuration file, while the configuration files that direct jsnapy to connect to multiple hosts use the include feature of YAML files to read in a list of hosts and credentials from a separate YAML file. The tests to be performed against the hosts are always defined in separate YAML test files whose names are specified within the tests section of the configuration files. Multiple test files can be specified.
For more information regarding test files, see the following:
-
Understanding Junos Snapshot Administrator in Python Test Files
-
Creating the Junos Snapshot Administrator in Python Test Files
SQLite configuration is done within the configuration file, while e-mail configuration is done in a separate mail configuration file, the name of which is specified in the configuration file. See <understanding mail config> and <creating mail config> for information about setting up jsnapy to use e-mail.
Comments can be inserted into the file at any location by starting the comment with the pound sign (#).
One Host, One Test
Procedure
Step-by-Step Procedure
Two sections are required for this configuration file:
hosts and tests. For this example, use a text editor to create a new
file named configuration_one_host_one_test.yml
.
Create the hosts section.
hosts:
Specify the IP address and login credentials.
- device: 192.0.2.12 username: user passwd: <password>
Create the tests section.
tests:
Specify the test file to use.
- test_exists.yml
Results
The resulting configuration file can be shown in the
terminal using the cat
command.
user@jsnapy-server:~> cat configuration_one_host_one_test.yml hosts: - device: 192.0.2.12 username: user password: <password> tests: - test_exists.yml
One Host, Two Tests with E-mail
Procedure
Step-by-Step Procedure
Three sections are required for this configuration file:
hosts, tests and mail. For this example, use a text editor to create
a new file named configuration_one_host_two_tests_e-mail.yml
.
Create the hosts section.
hosts:
Specify the IP address and login credentials.
- device: 192.0.2.11 username: user passwd: <password>
Create the tests section.
tests:
Specify the test file to use.
- test_not_less.yml - test_not_more.yml
Specify the e-mail configuration file.
mail: send_mail.yml
Results
The resulting configuration file can be shown in the
terminal using the cat
command.
user@jsnapy-server:~> cat configuration_one_host_two_tests_e-mail.yml hosts: - device: 192.0.2.11 username: user password: <password> tests: - test_not_less.yml - test_not_more.yml mail: send_mail.yml
Multiple Hosts, One Test with SQLite Database Storage
Procedure
Step-by-Step Procedure
Three sections are required for this configuration file:
hosts, tests, and sqlite. Use a text editor to create a new file named configuration_multiple_hosts_one_test_sqlite
.
Create the hosts section.
hosts:
Specify the file in which the host IP addresses and login credentials are contained.
- include: devices.yml group: MX
Create the tests section.
tests:
Specify the test file to use.
- test_diff.yml
Create the sqlite section.
sqlite:
-
Configure the sqlite parameters.
- store_in_sqlite: yes check_from_sqlite: yes database_name: jsnapy.db
Results
The resulting configuration file can be shown in the
terminal using the cat
command.
user@jsnapy-server:~> cat configuration_multiple_hosts_one_tests_sqlite.yml hosts: - include: devices.yml group: MX tests: - test_diff.yml sqlite: - store_in_sqlite: yes check_from_sqlite: yes database_name: jsnapy.db