Skip to main content

Out of tree netmiko monkeypatch for multihop capability

Project description

netmiko_multihop is an out of tree netmiko monkeypatch which adds multihop capability. Currently following platforms are supported as intermediate hop:

  • linux

  • cisco_nxos

  • cisco_ios

Other platforms can be added easily if required.

Installation

Install the netmiko_multihop package by running:

pip3 install netmiko-multihop

Usage

import  netmiko_multihop
from netmiko import ConnectHandler


jumphost1 = {
    'device_type': 'linux',
    'ip': <ip_jumphost1>,
    'username': <ssh_username_jumphost1>,
    'password': <ssh_password_jumphost1>,
    'port': 22,
}

jumphost2 = {
    'device_type': 'linux',
    'ip': <ip_jumphost2>,
    'username': <ssh_username_jumphost2>,
    'password': <ssh_password_jumphost2>,
    'port': 22,
}

target1 = {
    'device_type': 'cisco_nxos',
    'ip': <ip_target1>,
    'username': <ssh_username_target1>,,
    'password': <ssh_password_target1>,
    'port': 22,
}

target2 = {
    'device_type': 'cisco_ios',
    'ip': <ip_target2>,
    'username': <ssh_username_target2>,
    'password': <ssh_password_target2>,
    'port': 22,
}

# If the next hop is reachable via vrf on the current hop, add the vrf parameter to the destination configuration.
# Eg.: Target1 is reachable via vrf mgmt from target2.
#      You want to jump from target1 to target2.
#      Add the parameter vrf='mgmt' to target2 configuration before you jump from target1 to target2.

ssh = ConnectHandler(**jumphost1)
# now we are on jumphost1
# this is where the magic starts. as jump_to returns the object instance we can jump multiple hops at once

ssh.jump_to(**jumphost2).jump_to(**target1)
# now we are on target1
print(ssh.send_command("show inventory"))
# lets get back a single jump
ssh.jump_back()
# now we are on jumphost2
ssh.jump_to(**target2)
# now we are on target2
print(ssh.send_command("show inventory"))
ssh.jump_back()

Contribute

License

This project is licensed under the Apache License Version 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

netmiko_multihop-0.2-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file netmiko_multihop-0.2-py3-none-any.whl.

File metadata

  • Download URL: netmiko_multihop-0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.28.0 setuptools/65.3.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for netmiko_multihop-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9da66ed224d4d8aeb94751c8a581f0badde0b2440b713f0e9c7c0d5c635085ea
MD5 0e97c6f6533e4306d05a3b4e80b58ff5
BLAKE2b-256 96a7b24f811b640517b0a24d5dd0a8a894b3f5327c4382f1fd8881860b85712b

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