簡體   English   中英

如何使用PyEZ獲取Juniper路由器的mac地址表? 運行時拋出錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM