diff options
author | Viacheslav <v.gletenko@vyos.io> | 2021-08-16 17:03:23 +0300 |
---|---|---|
committer | rebortg <github@ghlr.de> | 2021-08-19 20:31:39 +0200 |
commit | de8d5228fb4d99d808eb5ba53a798570542b2022 (patch) | |
tree | 8a4fbed382a60d2c21c1f8f92694362570bb2c64 /docs/automation/vyos-netmiko.rst | |
parent | b0497191f7db7a5a37448ed7ba1f74321d0e2abc (diff) | |
download | vyos-documentation-de8d5228fb4d99d808eb5ba53a798570542b2022.tar.gz vyos-documentation-de8d5228fb4d99d808eb5ba53a798570542b2022.zip |
automate: Add netmiko and napalm examples
(cherry picked from commit d687f9e5623843b075522b3484d58e5ab6c7dc86)
Diffstat (limited to 'docs/automation/vyos-netmiko.rst')
-rw-r--r-- | docs/automation/vyos-netmiko.rst | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/docs/automation/vyos-netmiko.rst b/docs/automation/vyos-netmiko.rst new file mode 100644 index 00000000..3627e5c3 --- /dev/null +++ b/docs/automation/vyos-netmiko.rst @@ -0,0 +1,72 @@ +:lastproofread: 2021-06-28 + +.. _vyos-netmiko: + +Netmiko +======= + +VyOS supports configuration via netmiko_. +It requires to install ``python3-netmiko`` module. + +Example +------- + +.. code-block:: none + + #!/usr/bin/env python3 + + from netmiko import ConnectHandler + + vyos_router = { + "device_type": "vyos", + "host": "192.0.2.1", + "username": "vyos", + "password": "vyospass", + "port": 22, + } + + net_connect = ConnectHandler(**vyos_router) + + config_commands = [ + 'set interfaces ethernet eth0 description WAN', + 'set interfaces ethernet eth1 description LAN', + ] + + # set congiguration + output = net_connect.send_config_set(config_commands, exit_config_mode=False) + print(output) + + # commit configuration + output = net_connect.commit() + print(output) + + # op-mode commands + output = net_connect.send_command("run show interfaces") + print(output) + +Output + +.. code-block:: none + + $ ./vyos-netmiko.py + configure + set interfaces ethernet eth0 description WAN + [edit] + vyos@r4-1.3# set interfaces ethernet eth1 description LAN + [edit] + vyos@r4-1.3# + commit + [edit] + vyos@r4-1.3# + Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down + Interface IP Address S/L Description + --------- ---------- --- ----------- + eth0 203.0.113.1/24 u/u WAN + eth1 192.0.2.1/30 u/u LAN + eth2 - u/u + lo 127.0.0.1/8 u/u + ::1/128 + vtun10 10.10.0.1/24 u/u + [edit] + +.. _netmiko: https://github.com/ktbyers/netmiko
\ No newline at end of file |