I am trying to make Junos PyEZ work via console port (telnet to a Cisco AS2511-RJ terminal server, which is connected to Juniper SRX-240 console port).
The test script is
dev = Device(host='X.X.X.X', user='XXX', password='XXXXXXXX',
mode='telnet', port='2014', gather_facts=True)
try:
dev.open()
print(dev.facts)
print(dev.cli("show version", format='text', warning=False))
except RuntimeError as rte:
print("Exception: " + str(rte) )
finally:
dev.close()
My problem is that script works only from time to time, but most of the runs are unsuccessful. After unsuccessful attempts, in the log I see something like
Nov 8 21:17:29 srxD-2 login: Login attempt for user <close-session/> from host [unknown]
Nov 8 21:17:29 srxD-2 login[39846]: LOGIN_PAM_AUTHENTICATION_ERROR: Failed password for user <close-session/>
Nov 8 21:17:29 srxD-2 login[39846]: LOGIN_FAILED: Login failed for user <close-session/> from host ttyu0
...........
Nov 8 21:22:41 srxD-2 login: Login attempt for user d-trailer from host [unknown]
...........
So PyEZ seems to not always very well deal with my console's screen scraping. Any ideas why this might be and how to fix it? I am using the current master branch of PyEZ from github for testing.
This has been fixed by adding console_has_banner=True
option, as shown here:
with Device(host='X.X.X.X', user='XXX', password='XXXXXX', mode='telnet',
port='2014', gather_facts=True, console_has_banner=True) as dev:
print(dev.facts)
print(dev.cli("show version", format='text', warning=False))
With this option applied, script now works fine every time.
See more details in this pull request.