knipknap / exscript

A Python module making Telnet and SSH easy
MIT License
364 stars 136 forks source link

Error connecting to Zhone appliance #87

Closed lormayna closed 8 years ago

lormayna commented 9 years ago

Hi, I'm trying to connect via SSH to a Zhone appliance. This is the error that I got:

lmainardi@rancid:~$ exscript --no-prompt -v 5 --protocol-verbose=5 -i test.exscript ssh://admin:zhone@10.255.255.6 Building HostAction for 10.255.255.6. Enqueing Action. All actions enqueued. Waiting for the queue to finish. generic: Adding ssh-dss host key for 10.255.255.6: b195c4964102ab2cac916e5636eb1f53 generic: Attempting to authenticate admin. generic: Authenticating with _paramiko_authpassword generic: Attempting to app-authenticate admin. generic: waiting for: ['[\r\n][^\r\n](?:bad secrets|denied|invalid|too short|incorrect|connection timed out|failed)', '(user ?name|user|login): $', '(?:s\/key|otp-md4) (\d+) (\S+)', 'password:? $', '[\r\n](?:[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#\$\%\&\'()_+\,-.\/\:\;\<\=>\?\@[\]\^_`\{\|\}\~\ \\t\\n\\r\\x0b\\x0c]|[\x1b\x07\x00])[\[\<]?\w+(?:(?:(?:[\w+\-]+)\@)?(?:[\w+\-\.]+))?:?(?:(?:(?:(?:[\w\+\-\.]+))?(?:/(?:[\w\+\-\.]+))/?)|~(?:(?:(?:[\w\+\-\.]+))?(?:/(?:[\w\+\-\.]+))/?)?)?[: ]?(?:(?:(?:(?:[\w\+\-\.]+))?(?:/(?:[\w\+\-\.]+))/?)|~(?:(?:(?:[\w\+\-\.]+))?(?:/(?:[\w\+\-\.]+))/?)?)?(?:\((?:[\w\+\-\.]+)\))?[\]\-]?[#>%\$\]] ?[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\!\"\#\$\%\&\\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`{|}\~\ \t\n\r\x0b\x0c]\Z'] generic: Expecting a prompt generic: Expected pattern: <generator object at 0xb730c84c> ZHPOMG01> 10.255.255.6 error: Buffer: '' Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/CustomAction.py", line 112, in execute self._call_function(conn) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/HostAction.py", line 62, in _call_function return self.function(conn) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/util/decorator.py", line 91, in decorated result = function(conn, args, _kwargs) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/util/decorator.py", line 117, in decorated conn.login(flush = flush) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/Connection.py", line 183, in login self.protocol.login(account, flush = flush) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/protocols/Protocol.py", line 582, in login self.authenticate(account, flush = False) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/protocols/Protocol.py", line 606, in authenticate self.app_authenticate(app_account, flush = flush) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/protocols/Protocol.py", line 765, in app_authenticate self._app_authenticate(account, password, flush) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/protocols/Protocol.py", line 674, in _app_authenticate raise TimeoutException(msg) TimeoutException: Buffer: ''

Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/CustomAction.py", line 112, in execute self._call_function(conn) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/HostAction.py", line 62, in _call_function return self.function(conn) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/util/decorator.py", line 91, in decorated result = function(conn, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/util/decorator.py", line 117, in decorated conn.login(flush = flush) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/Connection.py", line 183, in login self.protocol.login(account, flush = flush) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/protocols/Protocol.py", line 582, in login self.authenticate(account, flush = False) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/protocols/Protocol.py", line 606, in authenticate self.app_authenticate(app_account, flush = flush) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/protocols/Protocol.py", line 765, in app_authenticate self._app_authenticate(account, password, flush) File "/usr/local/lib/python2.7/dist-packages/Exscript-v2.1-py2.7.egg/Exscript/protocols/Protocol.py", line 674, in _app_authenticate raise TimeoutException(msg) TimeoutException: Buffer: ''

10.255.255.6 finally failed. 10.255.255.6 job is done. Destroying queue... Queue destroyed.

This is the version of exscript:

lmainardi@rancid:~$ exscript --version v2.1

Could you identify this problem?

egroeper commented 9 years ago

Seems like a problem with prompt detection. Perhaps you need to write a driver (mostly a couple of regexes) to support this appliance. What does the prompt look like?

lormayna commented 9 years ago

The prompt is customizable. We are using prompt like "ZHSLMN03> ". I'll write a driver soon :)

lormayna commented 9 years ago

I wrote this:

""" A driver for MALC by Zhone """ import re from Exscript.protocols.drivers.driver import Driver

_user_re = [re.compile(r'login: ', re.I)] _password_re = [re.compile(r'password: $')] _prompt_re = [re.compile(r'[A-Z]{4,5}\d{2}>\s$'),

class ZhoneMALCDriver(Driver): def init(self): Driver.init(self, 'arbor_peakflow') self.user_re = _user_re self.password_re = _password_re self.prompt_re = _prompt_re

Let me know if this is ok and how to "enable" on the code for testing.

egroeper commented 9 years ago

Not sure if you got my email reply to your mailing list request regarding this issue. For completeness I will answer here, too.

Your driver is pretty specific, but could work. The problem is, that it doesn't use the os detection feature and I'm not sure, if the prompt of your device can be used to distinguish it from other devices (if reliable os detection is possible). If you would implement os detection (and it would work correctly), everything would work fine. For now you could simply override os detection to test your driver and exscript for your usecase:

def check_head_for_os(self, string):
    return 100

This would cause your driver to be used everytime for every device.

If os detection is not possible, you need to manually set the driver. Unfortunately I currently don't know how and if this is possible, when using exscript in interpreter mode. I need to have a look at that, too.

egroeper commented 9 years ago

I just merged a pull request, that enables the exscript interpreter to force the use of a specific driver #89. Therefore the hack mentioned earlier should no longer be necessary.

You need to adjust the driver name from _arborpeakflow to something matching your driver, like 'zhonemalc'.

If you name your driver file "zhone_malc.py" It should no simply be possible to call:

exscript --load-driver=zhone_malc.py --use-driver=zhonemalc test.exscript
lormayna commented 8 years ago

I'm sorry if I replyed only now.

I got this error:

lmainardi@dcons-mi01-01-ginevra:~ $ exscript --load-driver=zhone_malc.py --use-driver=zhonemalc test.exscript telnet://10.255.255.6 Searching drivers in zhone_malc.py... Traceback (most recent call last): File "/usr/local/bin/exscript", line 584, in failed = run() File "/usr/local/bin/exscript", line 125, in run Exscript.protocols.drivers.add_driver(obj) File "/usr/local/lib/python2.7/dist-packages/Exscript/protocols/drivers/init.py", line 38, in add_driver driver = cls() TypeError: init() takes exactly 2 arguments (1 given)

I already copied the driver in the drivers directory:

lmainardi@dcons-mi01-01-ginevra:~ $ ls -la /usr/local/lib/python2.7/dist-packages/Exscript/protocols/drivers/ | grep zho -rw-r--r-- 1 root staff 472 mar 25 12:45 zhone_malc.py

egroeper commented 8 years ago

@lormayna I don't understand your problem. Interesting point to know: load-driver needs to point to the python file directly. Copying the driver in the driver directory wouldn't help.

I just put your driver (or what I reconstructed from your post here) in a gistt: https://gist.github.com/egroeper/90fa12c370f11aeafb29

The file there works fine here on my machine.

Are you sure you are using the correct version of your driver?

lormayna commented 8 years ago

Problema solved :)