• Diniz Martins

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.


Recent Posts

See All

Managing Junos using Rest API

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-PythonEZ (PyEZ) | Connection

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

JunOS | Tips & Tricks

Sharing some tips and tricks below: Exit from the CLI environment and create a UNIX-level shell. To return to the CLI, type exit from the shell. Find big size file into shell: Deleting whole configura