[英]How do I get the mac-address table of a Juniper router using PyEZ? It throws an error when running
我创建了一个简单的python脚本,以使用RPC命令从路由中获取vpls mac表。 但是它在运行时会引发错误。 有人知道我在做什么错吗?
root @ ubuntu:〜#猫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'))
根@ Ubuntu的:〜#
下面是错误:
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:~#
我也尝试过以下脚本:
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()
同样的错误:
root @ ubuntu:〜#python test1.py追溯(最近一次调用为最新):文件“ test1.py”,第11行,在macs = dev.rpc.get-vpls-mac-table(normalize = True)NameError:名称未定义'vpls'root @ ubuntu:〜#
JunOS RPC使用下划线转换为Pyez:
更改为:
sw = dev.rpc.get_vpls_mac_table()
谢谢! 现在可以使用sw = dev.rpc.get_vpls_mac_table()了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.