ktbyers / netmiko

Multi-vendor library to simplify Paramiko SSH connections to network devices
MIT License
3.61k stars 1.31k forks source link

Netmiko Support for Arista EOS Physical Switches #1703

Closed sjsingh02 closed 4 years ago

sjsingh02 commented 4 years ago

Hi,

I have tested below script and works fine with Arista vEOS

Python 2.7

Netmiko 2.4.2

Paramiko 2.4.1

from netmiko import ConnectHandler

with open('commands_file') as f:
    commands_list = f.read().splitlines()

with open('devices_file') as f:
    devices_list = f.read().splitlines()

for devices in devices_list:
    print 'Connecting to device ' + devices
    ip_address_of_device = devices
    eos_device = {
        'device_type': 'arista_eos',
        'ip': ip_address_of_device,
        'username': 'admin',
        'password': 'Arista'
    }

    print "HELLO"
    net_connect = ConnectHandler(**eos_device)
    enable = net_connect.enable()
    output = net_connect.send_config_set(commands_list)
    result = open(str(devices) + "_Output", 'w')
    result.write(output)
    result.close

But wen the same script is run on a Physical Arista box, it throws the below error

[root@cvp-intern-1 ~]# python script.py Connecting to device 10.81.116.154 HELLO /usr/lib/python2.7/site-packages/paramiko/kex_ecdh_nist.py:39: CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding. m.add_string(self.Q_C.public_numbers().encode_point()) /usr/lib/python2.7/site-packages/paramiko/kex_ecdh_nist.py:96: CryptographyDeprecationWarning: Support for unsafe construction of public numbers from encoded data will be removed in a future version. Please use EllipticCurvePublicKey.from_encoded_point self.curve, Q_S_bytes /usr/lib/python2.7/site-packages/paramiko/kex_ecdh_nist.py:111: CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding. hm.add_string(self.Q_C.public_numbers().encode_point()) Traceback (most recent call last): File "script.py", line 24, in net_connect = ConnectHandler(eos_device) File "/usr/lib/python2.7/site-packages/netmiko/ssh_dispatcher.py", line 246, in ConnectHandler return ConnectionClass(*args, *kwargs) File "/usr/lib/python2.7/site-packages/netmiko/base_connection.py", line 317, in init self._open() File "/usr/lib/python2.7/site-packages/netmiko/base_connection.py", line 323, in _open self._try_session_preparation() File "/usr/lib/python2.7/site-packages/netmiko/base_connection.py", line 738, in _try_session_preparation self.session_preparation() File "/usr/lib/python2.7/site-packages/netmiko/arista/arista.py", line 14, in session_preparation self.set_terminal_width(command="terminal width 511") File "/usr/lib/python2.7/site-packages/netmiko/base_connection.py", line 1039, in set_terminal_width output = self.read_until_prompt() File "/usr/lib/python2.7/site-packages/netmiko/base_connection.py", line 605, in read_until_prompt return self._read_channel_expect(args, kwargs) File "/usr/lib/python2.7/site-packages/netmiko/base_connection.py", line 543, in _read_channel_expect "Timed-out reading channel, data not available." netmiko.ssh_exception.NetMikoTimeoutException: Timed-out reading channel, data not available.

Also tried to use session_log='output.txt' as an argument to ConnectHandler but got the Syntax error.

[root@cvp-intern-1 ~]# python script.py File "script.py", line 24 net_connect = ConnectHandler(**eos_device, session_log='output.txt')

Any help would be appreciated,

Rgds Saran

ktbyers commented 4 years ago

Can you turn on Netmiko logging and post that log-file here?

https://github.com/ktbyers/netmiko/blob/develop/COMMON_ISSUES.md#enable-netmiko-logging-of-all-reads-and-writes-of-the-communications-channel

This is on your set terminal width failure.

sjsingh02 commented 4 years ago

[root@cvp-intern-1 ~]# cat test.log DEBUG:paramiko.transport:starting thread (client mode): 0xf2421110L DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.4.3 DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_6.6.1 INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_6.6.1) DEBUG:paramiko.transport:kex algos:[u'curve25519-sha256@libssh.org', u'ecdh-sha2-nistp521', u'ecdh-sha2-nistp256', u'ecdh-sha2-nistp384', u'diffie-hellman-group14-sha1'] server key:[u'ssh-rsa', u'ecdsa-sha2-nistp521', u'ssh-ed25519'] client encrypt:[u'aes256-gcm@openssh.com', u'aes128-gcm@openssh.com', u'aes256-ctr', u'aes192-ctr', u'aes128-ctr'] server encrypt:[u'aes256-gcm@openssh.com', u'aes128-gcm@openssh.com', u'aes256-ctr', u'aes192-ctr', u'aes128-ctr'] client mac:[u'hmac-sha2-512-etm@openssh.com', u'hmac-sha2-256-etm@openssh.com', u'hmac-sha1-etm@openssh.com', u'hmac-sha2-512', u'hmac-sha2-256', u'hmac-sha1'] server mac:[u'hmac-sha2-512-etm@openssh.com', u'hmac-sha2-256-etm@openssh.com', u'hmac-sha1-etm@openssh.com', u'hmac-sha2-512', u'hmac-sha2-256', u'hmac-sha1'] client compress:[u'none', u'zlib@openssh.com'] server compress:[u'none', u'zlib@openssh.com'] client lang:[u''] server lang:[u''] kex follows?False DEBUG:paramiko.transport:Kex agreed: ecdh-sha2-nistp256 DEBUG:paramiko.transport:HostKey agreed: ssh-ed25519 DEBUG:paramiko.transport:Cipher agreed: aes128-ctr DEBUG:paramiko.transport:MAC agreed: hmac-sha2-256 DEBUG:paramiko.transport:Compression agreed: none DEBUG:paramiko.transport:kex engine KexNistp256 specified hash_algo DEBUG:paramiko.transport:Switch to new keys ... DEBUG:paramiko.transport:Adding ssh-ed25519 host key for 10.81.116.154: a0622526220081d3d48b21a8740e1645 DEBUG:paramiko.transport:userauth is OK INFO:paramiko.transport:Auth banner: #############################################################

DEBUG:paramiko.transport:Authentication type (password) not permitted. DEBUG:paramiko.transport:Allowed methods: [u'publickey', u'keyboard-interactive'] DEBUG:paramiko.transport:userauth is OK INFO:paramiko.transport:Authentication (keyboard-interactive) successful! DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes DEBUG:paramiko.transport:[chan 0] Max packet out: 32768 bytes DEBUG:paramiko.transport:Secsh channel 0 opened. DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok DEBUG:netmiko:read_channel: Last login: Wed Apr 29 09:29:04 2020 from 10.85.144.161 Welcome to DCS-7150S-64-CL serial JPE16130474

DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel:

DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel:

DEBUG:netmiko:read_channel: co644...09:30:32# DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:In disable_paging DEBUG:netmiko:Command: terminal length 0

DEBUG:netmiko:write_channel: terminal length 0

DEBUG:netmiko:Pattern is: co644...09\:30\:32 DEBUG:netmiko:_read_channel_expect read_data:

DEBUG:netmiko:_read_channel_expect read_data: co644...09:30:32# co644...09:30:32# DEBUG:netmiko:Pattern found: co644...09\:30\:32 co644...09:30:32# co644...09:30:32# DEBUG:netmiko: co644...09:30:32# co644...09:30:32# DEBUG:netmiko:Exiting disable_paging DEBUG:netmiko:write_channel: terminal width 511

DEBUG:netmiko:Pattern is: co644...09\:30\:32 DEBUG:netmiko:_read_channel_expect read_data: terminal length 0

DEBUG:netmiko:_read_channel_expect read_data: Pagination disabled. co644...09:30:33# DEBUG:netmiko:_read_channel_expect read_data: terminal width 511 Width set to 511 columns. co644...09:30:33# DEBUG:netmiko:pattern: DEBUG:netmiko:write_channel:

DEBUG:netmiko:Pattern is: co644...09\:30\:32 DEBUG:netmiko:_read_channel_expect read_data: co644...09:30:41# DEBUG:netmiko:write_channel: exit

DEBUG:paramiko.transport:EOF in transport thread [root@cvp-intern-1 ~]#

Rgds Saranjit

sjsingh02 commented 4 years ago

The issue got sorted. It was with the device's host name.

Thanks for your response :)