summaryrefslogtreecommitdiff
path: root/docs/automation/vyos-netmiko.md
blob: 2e947b6a971e2da73680c4faba191e384fb9a9f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
lastproofread: '2026-04-13'
---

(vyos-netmiko)=

# Netmiko

VyOS can be configured using [Netmiko]. To use Netmiko, install the
`python3-netmiko` module.

## Example

The following script connects to a VyOS device, applies configuration changes,
commits them, and runs an operational mode command to verify the updated
configuration.

```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 configuration
output = net_connect.send_config_set(config_commands, exit_config_mode=False)
print(output)

# commit configuration
output = net_connect.commit()
print(output)

# operational mode commands
output = net_connect.send_command("run show interfaces")
print(output)
```

Output

```none
$ ./vyos-netmiko.py
configure
set interfaces ethernet eth0 description WAN
[edit]
vyos@r4-1.5# set interfaces ethernet eth1 description LAN
[edit]
vyos@r4-1.5#
commit
[edit]
vyos@r4-1.5#
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