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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file netmiko_bridge-0.1.1.tar.gz
.
File metadata
- Download URL: netmiko_bridge-0.1.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e6ddc9e38ca098e5fdf884d59ff48a29bef4e70ac4d83922833f1b9e5564ef4 |
|
MD5 | 16ba744e3dee9c359074308653ebaaff |
|
BLAKE2b-256 | 3e2b734be4797cf77ea82fcb0f4d3280f9dc055012cd21668c41dba45bf405c1 |
File details
Details for the file netmiko_bridge-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: netmiko_bridge-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bad16bde30382dbd58cc0cd41f99cee948c37219d2b3015271277d6be23754de |
|
MD5 | 35df746e1ae8ba64641b9994e5826a30 |
|
BLAKE2b-256 | dec01c20940143b6cbde3f137fcbe175a95e262113f9a3b8b7d44e26cc8f37ef |