jedelman8 / pycsco

python modules to simplify the use of working with cisco nexus switches
Other
50 stars 25 forks source link

'socket.timeout: timed out' error is seen when running a 'show' method call #21

Open tdichter opened 8 years ago

tdichter commented 8 years ago

Hi,

I have a switch that I can manually ssh to and run all the cli's.

I installed pysco on my Linux and all seems to work fine with respect to that. However, when I run the 'show' method, I get a socket.timeout error here is the screen shot: Python 2.7.10 (default, Sep 8 2015, 12:40:37) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import json import xmltodict from pycsco.nxos.device import Device switch = Device(ip='10.10.10.10',username='admin',password='default') get_sh_ver = switch.show('show version') Req timeout Traceback (most recent call last): File "", line 1, in File "/root/Desktop/foobar/lib/python2.7/site-packages/pycsco/nxos/device.py", line 99, in show data = self.sw1.send_req() File "/root/Desktop/foobar/lib/python2.7/site-packages/pycsco/nxos/nxapi.py", line 279, in send_req return req.get_resp(self.req_to_string(), self.cookie, self.timeout) File "/root/Desktop/foobar/lib/python2.7/site-packages/pycsco/nxos/nxapi.py", line 133, in get_resp timeout=timeout)) as resp: File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 431, in open response = self._open(req, data) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 449, in _open '_open', req) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 409, in _call_chain result = func(*args) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 1227, in http_open return self.do_open(httplib.HTTPConnection, req) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 1200, in do_open r = h.getresponse(buffering=True) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/httplib.py", line 1132, in getresponse response.begin() File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/httplib.py", line 453, in begin version, status, reason = self._read_status() File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/httplib.py", line 409, in _read_status line = self.fp.readline(_MAXLINE + 1) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/socket.py", line 480, in readline data = self._sock.recv(self._rbufsize) socket.timeout: timed out

Can you please advise what is needed to be done to make it work? Do I need to activate anything on the remote switch to have this working?

Thanks, Tomer

jedelman8 commented 8 years ago

Did you enable NXAPI on the switch? You can do this with the "feature nxapi" command.

On Dec 17, 2015, at 5:54 PM, tdichter notifications@github.com wrote:

Hi,

I have a switch that I can manually ssh to and run all the cli's

I installed pysco on my Linux and all seems to work fine with respect to that However, when I run the 'show' method, I get a sockettimeout error here is the screen shot: Python 2710 (default, Sep 8 2015, 12:40:37) [GCC 447 20120313 (Red Hat 447-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information

import json import xmltodict from pycsconxosdevice import Device switch = Device(ip='10101010',username='admin',password='default') get_sh_ver = switchshow('show version') Req timeout Traceback (most recent call last): File "", line 1, in File "/root/Desktop/foobar/lib/python27/site-packages/pycsco/nxos/devicepy", line 99, in show data = selfsw1send_req() File "/root/Desktop/foobar/lib/python27/site-packages/pycsco/nxos/nxapipy", line 279, in send_req return reqget_resp(selfreq_to_string(), selfcookie, selftimeout) File "/root/Desktop/foobar/lib/python27/site-packages/pycsco/nxos/nxapipy", line 133, in get_resp timeout=timeout)) as resp: File "/usr/cisco/packages/python/python-2710/lib/python27/urllib2py", line 154, in urlopen return openeropen(url, data, timeout) File "/usr/cisco/packages/python/python-2710/lib/python27/urllib2py", line 431, in open response = self_open(req, data) File "/usr/cisco/packages/python/python-2710/lib/python27/urllib2py", line 449, in _open '_open', req) File "/usr/cisco/packages/python/python-2710/lib/python27/urllib2py", line 409, in _call_chain result = func(*args) File "/usr/cisco/packages/python/python-2710/lib/python27/urllib2py", line 1227, in http_open return selfdo_open(httplibHTTPConnection, req) File "/usr/cisco/packages/python/python-2710/lib/python27/urllib2py", line 1200, in do_open r = hgetresponse(buffering=True) File "/usr/cisco/packages/python/python-2710/lib/python27/httplibpy", line 1132, in getresponse responsebegin() File "/usr/cisco/packages/python/python-2710/lib/python27/httplibpy", line 453, in begin version, status, reason = self_read_status() File "/usr/cisco/packages/python/python-2710/lib/python27/httplibpy", line 409, in _read_status line = selffpreadline(_MAXLINE + 1) File "/usr/cisco/packages/python/python-2710/lib/python27/socketpy", line 480, in readline data = self_sockrecv(self_rbufsize) sockettimeout: timed out

Can you please advise what is needed to be done to make it work? Do I need to activate anything on the remote switch to have this working?

Thanks, Tomer

— Reply to this email directly or view it on GitHub.

tdichter commented 8 years ago

thanks for the reply - I actually added that on the switch, and it still didnt work: CSCSwitch(config)# feature nxapi CSCSwitch(config)# end CSCSwitch# copy running-config startup-config [########################################] 100% Copy complete. C9372PX#

Then, repeating the above procedure also showed me the same error:

Python 2.7.10 (default, Sep 8 2015, 12:40:37) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import json import xmltodict from pycsco.nxos.device import Device switch = Device(ip='10.10.10.10',username='admin',password='default') get_sh_ver = switch.show('show version') Req timeout Traceback (most recent call last): File "", line 1, in File "/root/Desktop/foobar/lib/python2.7/site-packages/pycsco/nxos/device.py", line 99, in show data = self.sw1.send_req() File "/root/Desktop/foobar/lib/python2.7/site-packages/pycsco/nxos/nxapi.py", line 279, in send_req return req.get_resp(self.req_to_string(), self.cookie, self.timeout) File "/root/Desktop/foobar/lib/python2.7/site-packages/pycsco/nxos/nxapi.py", line 133, in get_resp timeout=timeout)) as resp: File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 431, in open response = self._open(req, data) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 449, in _open '_open', req) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 409, in _call_chain result = func(*args) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 1227, in http_open return self.do_open(httplib.HTTPConnection, req) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 1200, in do_open r = h.getresponse(buffering=True) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/httplib.py", line 1132, in getresponse response.begin() File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/httplib.py", line 453, in begin version, status, reason = self._read_status() File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/httplib.py", line 409, in _read_status line = self.fp.readline(_MAXLINE + 1) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/socket.py", line 480, in readline data = self._sock.recv(self._rbufsize) socket.timeout: timed out

thanks Tomer

jedelman8 commented 8 years ago

Can you provide the out of "show nxapi" and also verify you can access the NXAPI sandbox environment by going to http://switchip you may need to do "nxapi sandbox" command for this.

On Dec 17, 2015, at 9:08 PM, tdichter notifications@github.com wrote:

thanks for the reply - I actually added that on the switch, and it still didnt work: CSCSwitch(config)# feature nxapi CSCSwitch(config)# end CSCSwitch# copy running-config startup-config [########################################] 100% Copy complete. C9372PX#

Then, repeating the above procedure also showed me the same error:

Python 2.7.10 (default, Sep 8 2015, 12:40:37) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import json import xmltodict from pycsco.nxos.device import Device switch = Device(ip='10.10.10.10',username='admin',password='default') get_sh_ver = switch.show('show version') Req timeout Traceback (most recent call last): File "", line 1, in File "/root/Desktop/foobar/lib/python2.7/site-packages/pycsco/nxos/device.py", line 99, in show data = self.sw1.send_req() File "/root/Desktop/foobar/lib/python2.7/site-packages/pycsco/nxos/nxapi.py", line 279, in send_req return req.get_resp(self.req_to_string(), self.cookie, self.timeout) File "/root/Desktop/foobar/lib/python2.7/site-packages/pycsco/nxos/nxapi.py", line 133, in get_resp timeout=timeout)) as resp: File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 431, in open response = self._open(req, data) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 449, in _open '_open', req) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 409, in _call_chain result = func(*args) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 1227, in http_open return self.do_open(httplib.HTTPConnection, req) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 1200, in do_open r = h.getresponse(buffering=True) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/httplib.py", line 1132, in getresponse response.begin() File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/httplib.py", line 453, in begin version, status, reason = self._read_status() File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/httplib.py", line 409, in _read_status line = self.fp.readline(_MAXLINE + 1) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/socket.py", line 480, in readline data = self._sock.recv(self._rbufsize) socket.timeout: timed out

thanks Tomer

— Reply to this email directly or view it on GitHub.

jedelman8 commented 8 years ago

And please make sure you are using the management interface on the switch. That said, ensure at least port 80 is allowed on this interface.

On Dec 17, 2015, at 9:08 PM, tdichter notifications@github.com wrote:

thanks for the reply - I actually added that on the switch, and it still didnt work: CSCSwitch(config)# feature nxapi CSCSwitch(config)# end CSCSwitch# copy running-config startup-config [########################################] 100% Copy complete. C9372PX#

Then, repeating the above procedure also showed me the same error:

Python 2.7.10 (default, Sep 8 2015, 12:40:37) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import json import xmltodict from pycsco.nxos.device import Device switch = Device(ip='10.10.10.10',username='admin',password='default') get_sh_ver = switch.show('show version') Req timeout Traceback (most recent call last): File "", line 1, in File "/root/Desktop/foobar/lib/python2.7/site-packages/pycsco/nxos/device.py", line 99, in show data = self.sw1.send_req() File "/root/Desktop/foobar/lib/python2.7/site-packages/pycsco/nxos/nxapi.py", line 279, in send_req return req.get_resp(self.req_to_string(), self.cookie, self.timeout) File "/root/Desktop/foobar/lib/python2.7/site-packages/pycsco/nxos/nxapi.py", line 133, in get_resp timeout=timeout)) as resp: File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 431, in open response = self._open(req, data) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 449, in _open '_open', req) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 409, in _call_chain result = func(*args) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 1227, in http_open return self.do_open(httplib.HTTPConnection, req) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/urllib2.py", line 1200, in do_open r = h.getresponse(buffering=True) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/httplib.py", line 1132, in getresponse response.begin() File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/httplib.py", line 453, in begin version, status, reason = self._read_status() File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/httplib.py", line 409, in _read_status line = self.fp.readline(_MAXLINE + 1) File "/usr/cisco/packages/python/python-2.7.10/lib/python2.7/socket.py", line 480, in readline data = self._sock.recv(self._rbufsize) socket.timeout: timed out

thanks Tomer

— Reply to this email directly or view it on GitHub.

tdichter commented 8 years ago

sure jason,

Here is the show nxapi output:

show nxapi nxapi enabled HTTP Listen on port 80 HTTPS Listen on port 443

also, when I open a browser to the IP of this switch to see the API sandbox - this works, I can see the sandbox and run commands on it via the UI. The image installed on that switch is: NXOS: version 7.0(3)I2(1a)

Any idea what that might be?

Thanks, Tomer

jedelman8 commented 8 years ago

Can you verify you're using the management IP address?

On Dec 18, 2015, at 12:37 PM, tdichter notifications@github.com wrote:

sure jason,

Here is the show nxapi output:

show nxapi nxapi enabled HTTP Listen on port 80 HTTPS Listen on port 443

also, when I open a browser to the IP of this switch to see the API sandbox - this works, I can see the sandbox and run commands on it via the UI. The image installed on that switch is: NXOS: version 7.0(3)I2(1a)

Any idea what that might be?

Thanks, Tomer

— Reply to this email directly or view it on GitHub.

tdichter commented 8 years ago

the management interface is the one that I use in order to connect to the switch's sandbox:

interface mgmt0 vrf member management ip address 10.10.10.10/16 line console line vty session-limit 16 boot nxos bootflash:/nxos.7.0.3.I2.1a.bin

thanks, Tomer

tdichter commented 8 years ago

Another thing which might be interesting, is that when I call: switch = Device(ip='10.10.10.10',username='admin',password='default') - even if I specify a wrong password, it still works:

import json import xmltodict from pycsco.nxos.device import Device switch = Device(ip='10.10.48.101',username='admin',password='wrongPWD!')

Shouldn't we see an authentication error here?

just wondering... Thanks, Tomer

tdichter commented 8 years ago

and lastly - some info about the Linux machine that I try running this from: its a RHEL 6.5 which has Python 2.7.10 installed on it.

Not sure if this might be the root cause, but I thought of sharing this with you as well.

Thanks again for the help on that, Tomer

jedelman8 commented 8 years ago

Okay, try this...guaranteed to work...if it doesn't.... :)

from pycsco.nxos.device import Device
device = Device(ip='176.126.89.164', username='ntc',
password='Networktocode123')
device.show('show version')

On Fri, Dec 18, 2015 at 2:19 PM, tdichter notifications@github.com wrote:

and lastly - some info about the Linux machine that I try running this from: its a RHEL 6.5 which has Python 2.7.10 installed on it.

Not sure if this might be the root cause, but I thought of sharing this with you as well.

Thanks again for the help on that, Tomer

— Reply to this email directly or view it on GitHub https://github.com/jedelman8/pycsco/issues/21#issuecomment-165875308.

tdichter commented 8 years ago

looks like I cannot connect to that IP address with ping from the Linux machine I work with...

jedelman8 commented 8 years ago

It's on the public Internet. Maybe your corp IT is blocking.

tdichter commented 8 years ago

could be - but this is the same Linux that I ran Python automation on other vendors and all seems to work - only with the Cisco gear we have issues...

jedelman8 commented 8 years ago

Want to do a "pip install pycsco --upgrade" to be safe ?

On Fri, Dec 18, 2015 at 2:53 PM, tdichter notifications@github.com wrote:

could be - but this is the same Linux that I ran Python automation on other vendors and all seems to work - only with the Cisco gear we have issues...

— Reply to this email directly or view it on GitHub https://github.com/jedelman8/pycsco/issues/21#issuecomment-165883789.

tdichter commented 8 years ago

sure - I just ran it now:

pip install pycsco --upgrade --proxy=64.102.255.40 Requirement already up-to-date: pycsco in ./lib/python2.7/site-packages Requirement already up-to-date: scp in ./lib/python2.7/site-packages (from pycsco) Collecting paramiko (from pycsco) Downloading paramiko-1.16.0-py2.py3-none-any.whl (169kB) 100% |████████████████████████████████| 172kB 452kB/s Requirement already up-to-date: gtextfsm==0.2.1 in ./lib/python2.7/site-packages (from pycsco) Requirement already up-to-date: xmltodict==0.9.2 in ./lib/python2.7/site-packages (from pycsco) Requirement already up-to-date: ecdsa>=0.11 in ./lib/python2.7/site-packages (from paramiko->pycsco) Requirement already up-to-date: pycrypto!=2.4,>=2.1 in ./lib/python2.7/site-packages (from paramiko->pycsco) Installing collected packages: paramiko Found existing installation: paramiko 1.15.2 Uninstalling paramiko-1.15.2: Successfully uninstalled paramiko-1.15.2 Successfully installed paramiko-1.16.0 (foobar)[root@sjc23c-taffy foobar]#

now repeating the same sequence - still the same 'socket.timeout: timed out' error. I'm not so sure what's the issue here :-( In the worst case, Ill implement something of my own to execute the nx-api with Python, as the sand-box tool can generate the code, and I can give parameters to run any command needed in order to have the automation done....

jedelman8 commented 8 years ago

The only other differences are my testing is on Ubuntu running Python 2.6.
Time permitting I can try 2.7.10 - anyway you can try from another machine?

tdichter commented 8 years ago

hmmm - you might be up to something, cos another colleague who works with the same Linux OS on the same Python distro is able to run this...

thanks for the info on that :-)

jedelman8 commented 8 years ago

Okay, I'll keep this open for a few days. Would be good to find out if the problem is the OS, version of Python, or something else :) Let me know if you find out.

tdichter commented 8 years ago

sure - if there is a section of "known issues" or "release" notes, this piece of information can be mentioned there to let users know ...

Thanks, Tomer

jedelman8 commented 8 years ago

Or we narrow down the issue to OS or Python version, and implement the fix :)

On Dec 18, 2015, at 4:20 PM, tdichter notifications@github.com wrote:

sure - if there is a section of "known issues" or "release" notes, this piece of information can be mentioned there to let users know ...

Thanks, Tomer

— Reply to this email directly or view it on GitHub.

tdichter commented 8 years ago

True - until that can be done, we can publish something about that possible incompatibility that was found.

tdichter commented 8 years ago

I think that this issue can be closed and until proven differently, we can say that there is a compatibility problem when running this API on Python 2.7 running on a RHEL 6.5 OS.

I used the web based sandbox tool to generate Python API's from the generated code and make it open enough to be used on any switch needed, and also to scale up to as many switches the users will wish to automate.

Thanks for the help, Tomer