Skip to main content

Network Automation Inventory

Project description

Welcome to Worktory’s documentation!

Worktory is a python library created with the single purpose of simplifying the inventory management of network automation scripts.

As the network automation ecosystem grows, several connection plugins and parsers are available, and several times choosing a library or a connection plugin restricts all the devices to the same connection method.

Worktory tries to solve that problem giving the developer total flexibility for choosing the connector plugin and parsers for each device, at the same time that exposes a single interface for every plugin.

Installing

Worktory is available in PyPI, to install run:

$ pip install worktory

Using worktory

Sample Inventory

devices = [
            {
            'name': 'sandbox-iosxr-1',
            'hostname': 'sandbox-iosxr-1.cisco.com',
            'platform': 'cisco_iosxr',
            'username': 'admin',
            'password': 'C1sco12345',
            'groups': ['CORE'],
            'connection_manager': 'scrapli',
            'select_parsers' : 'genie',
            'mode': 'async',
            'transport': 'asyncssh',
            },
            {
            'name': 'sandbox-nxos-1',
            'hostname': 'sandbox-nxos-1.cisco.com',
            'platform': 'cisco_nxos',
            'username': 'admin',
            'password': 'Admin_1234!',
            'groups': ['CORE'],
            'select_parsers' : 'ntc',
            'connection_manager': 'scrapli',
            'mode': 'async',
            'transport': 'asyncssh'
            },
            {
            'name': 'sandbox-nxos-2',
            'hostname': 'sandbox-nxos-1.cisco.com',
            'platform': 'nxos',
            'username': 'admin',
            'password': 'Admin_1234!',
            'groups': ['EDGE'],
            'connection_manager': 'unicon',
            'mode': 'sync',
            'transport': 'ssh',
            'GRACEFUL_DISCONNECT_WAIT_SEC': 0,
            'POST_DISCONNECT_WAIT_SEC': 0,
            },
            {
            'name': 'sandbox-iosxr-2',
            'hostname': 'sandbox-iosxr-1.cisco.com',
            'platform': 'cisco_iosxr',
            'username': 'admin',
            'password': 'C1sco12345',
            'groups': ['CORE'],
            'connection_manager': 'scrapli',
            'select_parsers' : 'genie',
            'mode': 'sync',
            },
        ]

Collecting Running config from async devices

from worktory import InventoryManager
import asyncio
inventory = InventoryManager(devices)

device_configs = {}
async def get_config(device):
    await device.connect()
    config = await device.execute("show running-config")
    device_configs[device.name] = config
    await device.disconnect()

async def async_main():
    coros = [get_config(device) for device in inventory.filter(mode='async')]
    await asyncio.gather(*coros)

loop = asyncio.get_event_loop()
loop.run_until_complete(async_main())

Collecting Running config from sync devices

from worktory import InventoryManager
from multiprocessing import Pool
inventory = InventoryManager(devices)

def get_config(device_name):
    inventory = InventoryManager(devices)
    device = inventory.devices[device_name]
    device.connect()
    config = device.execute("show running-config")
    device.disconnect()
    return ( device.name , config )

def main():
    devs = [device.name for device in inventory.filter(mode='sync')]
    with Pool(2) as p:
        return p.map(get_config, devs)


output = main()

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

Worktory-0.1.1.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

Worktory-0.1.1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file Worktory-0.1.1.tar.gz.

File metadata

  • Download URL: Worktory-0.1.1.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.10 Linux/5.4.0-126-generic

File hashes

Hashes for Worktory-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6cf1167c2256e707ff3f067c54d396116b59a23a4f91f3cf09de6607db2fb14e
MD5 eda77617b540049ca6c1d21c43cf8523
BLAKE2b-256 682b5d2870433d9178b4285407172182c92c3ccbaee18a558097078a6f52c599

See more details on using hashes here.

File details

Details for the file Worktory-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: Worktory-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.10 Linux/5.4.0-126-generic

File hashes

Hashes for Worktory-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 29f5b7828b0854f8bf93f113ebdefd53c9531449d4cc5ef2005deea3fb26d7af
MD5 cebc87dfcab0a964d359eef799881a2e
BLAKE2b-256 9b24a00597a51c592e4301f970261c4a0a2e408d915b7273d0b1daece8027189

See more details on using hashes here.

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