Skip to main content

用于多跳功能的树外 netmiko monkeypatch

项目描述

netmiko_multihop 是一个树外 netmiko monkeypatch,它增加了多跳能力。目前支持以下平台作为中间跃点:

  • linux

  • cisco_nxos

  • cisco_ios

如果需要,可以轻松添加其他平台。

安装

通过运行安装 netmiko_multihop 包:

pip3 安装 netmiko-multihop

用法

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()

贡献

执照

该项目在 Apache 许可证版本 2.0 下获得许可

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

内置分布

netmiko_multihop-0.2.1-py3-none-any.whl (7.5 kB 查看哈希

已上传 py3