Junos-PythonEZ | XcvrTable & Counter

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='' ,user='usr' ,password='pwd')
>>> dev.open ()

>>> xcvr_db = [XcvrTable(dev)]
>>> for t in xcvr_db: t.get()
XcvrTable: 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.

49 views0 comments

Recent Posts

See All

Recovering Root Password for Juniper Devices can be done in few simple steps. ➪ This procedure is applicable for Juniper MX, M, EX, SRX, ACX, T, and PTX series devices. Step#1: Connect your Juniper de

The Managing Junos Devices using REST API learning byte demonstrates how to manage Junos devices using REST API. Since most programming languages can communicate with REST API , programmers can easily

Junos PyEZ is a microframework for Python that enables you to manage and automate devices running the Junos operating system (Junos OS). Junos PyEZ is designed to provide the capabilities that a user