Skip to main content

nornir_sql

Project description

Welcome to Nornir SQL inventory plugin!

If your device inventory is spread across SQL database tables and you would like to use it as Nornir inventory, you may consider looking on this project.



Installation

Install from pipy

pip install nornir-sql

Install from GitHUB

pip install git+https://github.com/viktorkertesz/nornir_sql.git

Install from GitHUB clone for development

git clone https://github.com/viktorkertesz/nornir_sql.git
cd nornir_sql
pip install -e .[dev]

Simple example

from nornir import InitNornir

host_query = """\
SELECT ciname AS name, ip AS hostname, region AS 'data.region'
FROM host_table
WHERE status='deployed'
"""

inventory = {
    "plugin": "SQLInventory",
    "options": {
        "sql_connection": "sqlite:///inventory.db",
        "hosts_query": hosts_query,
    }
}

nr = InitNornir(inventory=inventory)
print(nr.inventory.hosts['FW1']['region'])

Configuration

This plugin is based on SQLAlchemy and supports all databases that SQLAlchemy does.

These configuration options can be used:

  1. sql_connection: SQLAlchemy connection string
    Format: {driver}://[user]:[password]@{DBSERVER}/{DATABASE}
    SQLite example:
    sqlite:///somedb.db
    MSSQL example with domain user authentication:
    mssql+pymssql://ACME\\dbuser:verysecret@DBSRV1/INFRA
  2. hosts_query: Select statement which returns hosts inventory elements.
    The select must return at minimum the name field!
    Field names must match the expected Nornir inventory elements!
    The data elements are expected in data.[element] format. Quotation is needed!
    If groups are returned, the following groups_query also has to be specified!
  3. groups_query: Select statement which returns groups inventory elements.
    Same requirements apply as for the hosts_query.
  4. defaults: This is a dictionary which contains inventory elements. These will be applied to hosts.

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_sql-0.0.2.tar.gz (263.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nornir_sql-0.0.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file nornir_sql-0.0.2.tar.gz.

File metadata

  • Download URL: nornir_sql-0.0.2.tar.gz
  • Upload date:
  • Size: 263.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.26.0

File hashes

Hashes for nornir_sql-0.0.2.tar.gz
Algorithm Hash digest
SHA256 36094c486e69d2af9b3a504ad59b40c9b919226f69bb38ac83377b78d2b9ca43
MD5 0f169a73c90952314c28250d5eb7a157
BLAKE2b-256 3a558c9ab8df14309dd184e5f7c0d8cd226194869eba9e761a8007df08a32226

See more details on using hashes here.

File details

Details for the file nornir_sql-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: nornir_sql-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.26.0

File hashes

Hashes for nornir_sql-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bec988052959dd773c9d2d25dddd5b685cfb9de7e5922082401173e96fcbacd8
MD5 78710c5b4bd6bde4bba7d78644fa023c
BLAKE2b-256 263be1b3fc8c46e7f328cb229965c9ff343a7dae656254c68c5880aab924cc28

See more details on using hashes here.

Supported by

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