How do I get the mac-address table of a Juniper router using PyEZ? It throws an error when running

1.2k views Asked by At

I have created a simple python script to get the vpls mac table from a rouer using an RPC command. Hower it throws an error when running. Does anybody know what I am doing wrong?

root@ubuntu:~# cat vpls3.py

#!/usr/bin/python3
from jnpr.junos import Device
from lxml import etree
import jxmlease

username='lab'
password='lab'

dev = Device(host='10.85.164.172', user=username, password=password, normalize=True)

dev.open()
#invoke the RPC command
sw = dev.rpc.get-vpls-mac-table()
print(etree.tostring(sw, encoding='unicode'))

root@ubuntu:~#

Below is the error:

root@ubuntu:~# python vpls3.py
Traceback (most recent call last):
  File "vpls3.py", line 13, in <module>
    sw = dev.rpc.get-vpls-mac-table()
NameError: name 'vpls' is not defined
root@ubuntu:~#

I have also tried below script:

root@ubuntu:~# cat test1.py

from jnpr.junos import Device
from lxml import etree

# Set device information with IP-address, login user and passwort
dev = Device( user='lab', host='10.85.164.172', password='lab')

# Connect to the device
dev.open()

# Get MACs
macs = dev.rpc.get-vpls-mac-table(normalize=True)

# Print response of device
print (etree.tostring(macs))

# Close the connection
dev.close()

Same error:

root@ubuntu:~# python test1.py Traceback (most recent call last): File "test1.py", line 11, in macs = dev.rpc.get-vpls-mac-table(normalize=True) NameError: name 'vpls' is not defined root@ubuntu:~#

2

There are 2 answers

0
Jimmy Jiménez Salas On

JunOS RPCs translate to Pyez using underscore:

change it to:

sw = dev.rpc.get_vpls_mac_table()

1
Daniel Boirivant On

Thanks! its working now with sw = dev.rpc.get_vpls_mac_table() .