Access VyOS from Python SSH modules.


#1

Hi,

I would like to get vyos operational parameters (intefaces up/down, routing table, …) remotely from some python ssh API (pexpect or paramiko)

Using cli-shell-api (http://vyos.net/wiki/Shell_API), I can get configuration sections with the method
"showCfg "

But cannot find how to get operational parameters

Sending the following command:

command = """ cli-shell-api showCfg interfaces """

returns

ethernet eth0 { address dhcp duplex auto hw-id 00:0c:29:e4:ee:28 smp_affinity auto speed auto } ethernet eth1 { address dhcp duplex auto hw-id 00:0c:29:e4:ee:32 smp_affinity auto speed auto } ethernet eth2 { address 192.168.12.1/24 duplex auto hw-id 00:0c:29:e4:ee:3c smp_affinity auto speed auto } loopback lo { address 1.1.1.1/32 }

But I need this:

[code]Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
Interface IP Address S/L Description


eth0 192.168.0.133/24 u/u
eth1 - u/u
eth2 192.168.12.1/24 u/u
lo 127.0.0.1/8 u/u
1.1.1.1/32
::1/128[/code]


#2

Something like this should work

child = pexpect.spawn('ssh user@device')

child.expect('password:')
child.sendline('password')
child.expect('\$')
child.sendline('show interfaces')
child.expect('\$')

print child.before

#3

Awesome Microlinux! thank you very much.


#4

This is another option with python

from Exscript.protocols import SSH2
from Exscript import Account

#
account = Account("vyos","password")
#
conn = SSH2()
conn.connect('ip_vyos')
conn.login(account)
#
conn.execute('cat /config/config.boot')
print conn.response
#
conn.send('quit\r')
#
conn.close()