Skip to main content

No project description provided

Project description

nornir-network-backup

This is a beta version. Extra options and documentation will follow soon !

This python library installs the nnb command which will generate configuration backups of network equipment via SSH (routers, switches, ..). This tool will replace RANCID which - surprisingly - still is commonly being used.

This tool uses the Nornir framework and connects to network devices using the Netmiko library.

Features:

  • Uses the Nornir framework and expects the same files as nornir (config.yaml, hosts.yaml, groups.yaml)
  • Generates backup config files for each device (ex. show running-config)
  • Includes "meta" data on top of each backup config (ex. hostname, serial number, hardware type, ..)
  • Takes facts from the devices and store them in separate files
  • Parse facts using textfsm and store the results as yaml
  • Define all fact commands in the nornir config files, different facts per group can be defined
  • Store the .diff file for each backup config file
  • Generate summary reports to keep track of historical backup info
  • Include reports that can give summaries based on the gathered fact data

REQUIREMENTS

The following python libraries are required:

  • nornir

  • nornir-utils

  • nornir-netmiko

    If you want to used different Nornir runner or inventory plugins then you may need those as well.
    The nornir_salt RetryRunner plugin for example allows automatic re-tries if a connection fails.

INSTALLATION

The library can be installed as a standard python library using pip, poetry, ..

pip3 install nornir_network_backup

USAGE

Checkout this repo to have a complete example with all the parameters to get you started immediately. This also has Dockerfile so you can start taking backups immediately.

Once this library is installed it will allow you to start backups using the nnb backup command.
You can then refer to a nornir group or individual nornir hosts. If the host you want to backup does not exist in the nornir inventory then you will have to specify the driver manually and it will still allow you to run the backup for the unknown host.

The following examples assume

Examples:

# take a backup for 2 hosts, both hosts will be lookuped up in the nornir inventory
nnb backup -h host1 -h 1.2.3.4 -u someuser -p somepass

# take a backup for a group of hosts, the group should be defined
nnb backup -g cisco -u someuser -p somepass

# show all hosts that will backed up
nnb backup --all --dry-run

Credentials

You can provide credentials in different ways:

  • defined the nornir config files
  • as CLI argument
  • by setting environment variables NORNIR_USERNAME and NORNIR_PASSWORD
  • by running the nnb command and prepending the environment variables

Function

  • take the running config of 1 or more hosts and save it to a file
    • the file will be overwritten every day
    • optional take a diff of the previous file and save it as well
  • run "show" commands and save each output to a separate file in a facts folder
    • files will be overwritten every time
    • all files in a single facts folder
    • save a file with meta data: info about the last backup time, commands executed, failed + successful commands
    • the commands may change depending on vendor or hw type or software
    • commands which can be parsed with textfsm will be saved as YAML, if they cannot be parsed then it will be .config text files
  • it should be possible to run the backup file for a single host
  • or run agains a complete file
  • generate an overall report with:
    • last run time
    • hosts succeeded
    • hosts failed
    • hosts skipped

Output folder structure

|- backup folder
|  |-- facts folder
|  |-- reports folder  

Commands

nnb backup
nnb backup-single-host

Usage

poetry run nnb backup-single-host

Environment Variables

Used by nornir_utils.plugins.inventory.load_credentials transform function, in case username + password are not defined by CLI

NORNIR_USERNAME

NORNIR_PASSWORD

TEXTFSM

Facts command output can be parsed by NTC Textfsm. It depends on the configuration settings if Textfsm parsing is done.
The path to the NTC textfsm templates should be valid and include the index file. If Textfsm is enabled and no templates_folder path is provided then it's expected that the environment variable NTC_TEMPLATES_DIR is set.

user_defined:
  textfsm:
    enabled: True
    templates_folder: /home/mwallraf/ntc-templates/ntc_templates/templates/

Options:

enabled: Use textfsm or not

templates_folder: path to the NTC textfsm templates, this should be a folder containing an index file. If the folder is not set then the environment variable NTC_TEMPLATES_DIR should exist and have a valid path.

CAVEATS

Sometimes fact commands may fail and netmiko may generate unexpected timeouts. In that case you can make sure that certain commands are never executed for device groups by prepending the command with a ^ (carret).

Example:

pbxplug: data: cmd_facts: - show voice voice-port all - show isdn active - show voice voice-port pri all - show voice voice-port pri all reset - ^show cellular equipment - ^show cellular network

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nornir_network_backup-0.1.2a4.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

nornir_network_backup-0.1.2a4-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

Details for the file nornir_network_backup-0.1.2a4.tar.gz.

File metadata

  • Download URL: nornir_network_backup-0.1.2a4.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.10 Linux/5.4.0-186-generic

File hashes

Hashes for nornir_network_backup-0.1.2a4.tar.gz
Algorithm Hash digest
SHA256 626749d5aedacc01ced3545f40a66b05df954b9d8785242cb0278ee1feb802e5
MD5 c5d2b2be503dd7cfba1f6e31765134ce
BLAKE2b-256 d274af742fe9aa61ce6274f9e420e67a71b911d6bb5019fb2327021951bd279f

See more details on using hashes here.

Provenance

File details

Details for the file nornir_network_backup-0.1.2a4-py3-none-any.whl.

File metadata

File hashes

Hashes for nornir_network_backup-0.1.2a4-py3-none-any.whl
Algorithm Hash digest
SHA256 e44c25ec0a396f12e616359d71c1ea315ef7fd59a569ded805d6886f4fc94723
MD5 881cce521f72020628e5703410ce9ec4
BLAKE2b-256 c9f4cacc666f27b58729802127e0b83d878e5600343b87af0d6baa7c2bd41978

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page