Skip to main content

A decorator for Netmiko vendor driver extension.

Project description

Netmiko Bridge

English | 简体中文

This is a decorator for Netmiko vendor driver extension.

You can use this module to add yourself vendor driver without modify Netmiko source code.

How to build

First you must install wheel or build with pip.

This example is use build.

use build

pip install --upgrade build

Then you can build this module.

python -m build

How to install

Install via Directory

You can install netmiko_bridge direct with directory.

pip install --upgrade {netmiko_bridge_path}

Install via Binary

After build this module, you can install it to your system.

pip install -f {netmiko_bridge_path}/dist/ --upgrade netmiko_bridge

Install via PyPi

pip install netmiko-bridge

How to use

1. Netmiko source code modify

To use this module, you must do some minimal modify in Netmiko.

In file netmiko/ssh_dispatcher.py, please add this code before def ConnectHandler(*args: Any, **kwargs: Any) -> "BaseConnection":, like

import netmiko_bridge
@netmiko_bridge.connect_handler_bridge(platforms, vendor_module = "your_custom_driver_module_package", vendor_getter_attr = "your_custom_vendor_getter_attr_name")
def ConnectHandler(*args: Any, **kwargs: Any) -> "BaseConnection":
    """......"""

You can also use the default value on the ConnectHandler decorator

import netmiko_bridge
@netmiko_bridge.connect_handler_bridge(platforms)
def ConnectHandler(*args: Any, **kwargs: Any) -> "BaseConnection":
    """......"""

This the bash script help you to modify the source code, and it can match more netmiko version.

_python_lib_path=/usr/lib64/python3.6/site-packages
_netmiko_fix_file=${_python_lib_path}/netmiko/ssh_dispatcher.py
if [ -f "${_netmiko_fix_file}" ]; then
  _netmiko_fixed=$(grep -c "@netmiko_bridge.connect_handler_bridge" ${_netmiko_fix_file})
  if [ "${_netmiko_fixed}" -eq "0" ]; then
    sed -i "s/def ConnectHandler/import netmiko_bridge\n@netmiko_bridge.connect_handler_bridge(platforms)\ndef ConnectHandler/" ${_netmiko_fix_file}
  fi
fi

2. VendorGetter Instance

Then you can build yourself vendor driver module like this

from netmiko_bridge.vendor_getter import VendorGetter
from netmiko.cisco_base_connection import CiscoBaseConnection


class Custom(CiscoBaseConnection):
    """Your Custom Vendor Support"""

    def __init__(self):
        pass


vendor_getter = VendorGetter()
# you can add the mapper use the
vendor_getter.add_vendor({
    "custom_device": Custom
})

To build vendor module, you can reference module netmiko_bridge_vendor.

3. Use netmiko

Now you can use Netmiko with yourself vendor device driver.

from netmiko.ssh_dispatcher import ConnectHandler

conn = ConnectHandler(device_type='custom_device')

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

netmiko_bridge-0.1.1.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

netmiko_bridge-0.1.1-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

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