The following script show how to using Junos PyEZ "XcvrTable" and "Counter" widget to get the number of transceivers on the Junos router on a fast way.
In this case, I used a router Juniper model MX 480 with version 19.1R3.5.
Just open your Linux server, type python2.7 and run the commands below:
>>> from pprint import pprint
>>> from jnpr.junos import Device
>>> from jnpr.junos.op.xcvr import *
>>> from collections import Counter
>>> from pprint import pprint as pp
>>> dev = Device (host='192.168.0.1' ,user='usr' ,password='pwd')
>>> dev.open ()
Device(192.168.0.1)
>>> xcvr_db = [XcvrTable(dev)]
>>> for t in xcvr_db: t.get()
...
XcvrTable:192.168.0.1: 57 items
>>> types_info = [x.type for x in xcvr_db[0]]
>>> Counter(types_info)
Counter({'SFP+-10G-SR': 20, 'SFP-SX': 17, 'SFP-T': 16, 'SFP+-10G-LR': 4})
>>> pp( types_info )
>>> dev.close()
After typing "Counter(type_info)" you'll receive the current output of types of transceivers informations.
Note that the number of items in "XcvrTable" is the same as counters output.
Comments