0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

EdgeRouter Xをnetmikoから操作する

Posted at

EdgeRouter Xをnetmiko経由で操作してみます。

pipなどでnetmikoをインストールしたあと、pythonで以下のようなプログラムを記述します。

python
from netmiko import ConnectHandler

obj_erx = {
    'username': 'ubnt',
    'ip': '192.168.1.1', 
    'verbose': True, 
    'port': 22, 
    'password': 'ubnt', 
    'device_type': 'vyos'
}

net_connect = ConnectHandler(**obj_erx)

print('\n$show configuration commands | match network\n')
output1 = net_connect.send_command('show configuration commands | match network')
print(output1)

config_commands = [ 
    'set protocols bgp 65001 network 10.10.0.2/32',
    'set protocols bgp 65001 network 10.10.0.3/32',
    'commit',
    'save',
    'exit'
]

output2 = net_connect.send_config_set(config_commands)
print(output2)

print('\n$show configuration commands | match network\n')
output3 = net_connect.send_command('show configuration commands | match network')
print(output3)

BGPのnetworkコマンドを2つ追加するプログラムです。

netmiko1.4.3以降はEdgeRouterに対応しており、device_typeに'ubiquiti_edge'と指定できるのですが、うまく動きませんでした。原因は調査中ですが、ひとまずdevice_typteに'vyos'と指定して動かしています。

実行結果は以下のようになります。

SSH connection established to 192.168.1.1:22
Interactive SSH session established

$show configuration commands | match network

set protocols bgp 65001 network 10.10.0.1/32
configure

[edit]
ubnt@ubnt1# set protocols bgp 65001 network 10.10.0.2/32
[edit]
ubnt@ubnt1# set protocols bgp 65001 network 10.10.0.3/32
[edit]
ubnt@ubnt1# commit
save
exit
[edit]
ubnt@ubnt1# save
Saving configuration to '/config/config.boot'...
Done
[edit]
ubnt@ubnt1# exit
exit
ubnt@ubnt1:~$ 

$show configuration commands | match network

set protocols bgp 65001 network 10.10.0.1/32
set protocols bgp 65001 network 10.10.0.2/32
set protocols bgp 65001 network 10.10.0.3/32

コンフィグ変更の前後で"show configuration commands ~ match network"というコマンドを実行しており、その出力結果に違いが出ていることがわかります。EdgeOSだけではなく、Vyatta, VyOSでも同様のプログラムでコンフィグ変更ができると思います。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?