Asynchronous SSH handler based on Netmiko for managing network devices.
Project description
netmikio
A lightweight package for asynchronous SSH-handling based on Netmiko for managing network devices.
Built on top of netmiko by Kirk Byers.
Important Note
While netmikio provides an asynchronous interface for interacting with network devices, it is important to understand that it is not fully asynchronous. The underlying netmiko
library is synchronous and blocking by design. This package uses asyncio to offload blocking operations to a thread pool, allowing you to manage multiple SSH connections concurrently, but the operations themselves are still blocking.
However, this package is particularly useful when you have other asynchronous tasks running in parallel, such as handling I/O operations, making API calls, or managing multiple coroutines. By integrating SSH operations within an asyncio event loop, you can still benefit from the concurrency provided by Python’s async ecosystem.
If you require true non-blocking, asynchronous SSH communication, consider using a library like asyncssh
, which is built specifically for fully async SSH connections.
Features
- Asynchronous interface for SSH operations using Python's asyncio with blocking operations offloaded to a thread pool.
- Short and simplified method names similar to Netmiko.
- Handles connection management, timeouts, and authentication errors in an asynchronous context.
How Does It Work?
netmikio
follows a similar approach to netmiko
but introduces shorter, simplified method names:
send_com()
: Send a command and retrieve the output.send_com_timing()
: Send a command with timing support.send_conf_set()
: Send a configuration command set.
Example: Sending the command show power inline
to multiple devices asynchronously
from netmikio import aioConnectHandler
import asyncio
async def my_func(dev):
"""
Send a command and gather the output.
"""
async with aioConnectHandler(**dev) as ssh: # Connect asynchronously like in Netmiko but with 'async'.
output = await ssh.send_com('show power inline') # Send command and retrieve output asynchronously.
print(f"{dev['host']}:\n{output}\n")
async def main():
"""
Main function where tasks are created and executed.
"""
devices = [
{
'device_type': 'cisco_ios',
'host': 'sw1.test.local',
'username': 'admin',
'password': '12345678'
},
{
'device_type': 'cisco_ios',
'host': 'sw2.test.local',
'username': 'admin',
'password': '12345678'
}
]
tasks = [my_func(dev) for dev in devices] # Create tasks for each device.
await asyncio.gather(*tasks) # Run the tasks asynchronously.
if __name__ == '__main__':
asyncio.run(main()) # Execute the main function.
Output:
sw1.test.local:
Available:240.0(w) Used:137.8(w) Remaining:102.2(w)
Interface Admin Oper Power Device Class Max
(Watts)
--------- ------ ---------- ------- ------------------- ----- ----
Gi0/1 auto on 13.9 AIR-AP1542D-B-K9 3 30.0
Gi0/2 auto on 13.9 AIR-AP1542D-B-K9 3 30.0
Gi0/3 auto on 26.6 AIR-AP2802E-B-K9 4 30.0
Gi0/4 auto on 13.9 AIR-AP1542D-B-K9 3 30.0
Gi0/5 auto off 0.0 n/a n/a 30.0
Gi0/6 auto on 13.9 Ieee PD 4 30.0
Gi0/7 auto on 13.9 AIR-AP1542I-B-K9 3 30.0
Gi0/8 auto off 0.0 n/a n/a 30.0
Gi0/9 auto on 13.9 AIR-AP1542D-B-K9 3 30.0
Gi0/10 auto on 13.9 AIR-AP1542I-B-K9 3 30.0
Gi0/11 auto on 13.9 AIR-AP1542I-B-K9 3 30.0
Gi0/12 auto off 0.0 n/a n/a 30.0
sw2.test.local:
Available:240.0(w) Used:99.3(w) Remaining:140.7(w)
Interface Admin Oper Power Device Class Max
(Watts)
--------- ------ ---------- ------- ------------------- ----- ----
Gi0/1 auto on 13.9 AIR-AP1542I-B-K9 4 30.0
Gi0/2 auto on 13.9 AIR-AP1542I-B-K9 3 30.0
Gi0/3 auto on 29.8 AIR-AP1562D-B-K9 4 30.0
Gi0/4 auto on 13.9 AIR-AP1542I-E-K9 3 30.0
Gi0/5 auto on 13.9 AIR-AP1542I-B-K9 3 30.0
Gi0/6 auto on 13.9 AIR-AP1542D-B-K9 3 30.0
Gi0/7 auto off 0.0 n/a n/a 30.0
Gi0/8 auto off 0.0 n/a n/a 30.0
Gi0/9 auto off 0.0 n/a n/a 30.0
Gi0/10 auto off 0.0 n/a n/a 30.0
Gi0/11 auto off 0.0 n/a n/a 30.0
Gi0/12 auto off 0.0 n/a n/a 30.0
thamuppet - Anton Hultberg
antonhultberg@gmail.com
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 netmikio-1.0.2.tar.gz
.
File metadata
- Download URL: netmikio-1.0.2.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b8a51eea69abf5e893c1a2d5187b169c3c731e07cdd1dfcb3b3eafe7ed44a64 |
|
MD5 | 119b44eb12f20d6914a9910b9fd4d83a |
|
BLAKE2b-256 | 7e6a7af2aee67a8047f8ef241abb9b8e46f889826e6af7fa88e255c3b96bfd98 |
File details
Details for the file netmikio-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: netmikio-1.0.2-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c02cd2b0dca789bd8e89140cb7626909320bd40e0e62e9daf71a4b48da6b67b |
|
MD5 | 601159e8c48cb2c3b00709950041443c |
|
BLAKE2b-256 | e046d9cbdc64a2f94ccb4ca0c8a4a505818db717616e7cc2711a06673871c2c1 |