napalm-automation-community/napalm-s350

Integration with Napalm-Ansible

barte91 opened this issue · 17 comments

Hi,

I want to import this driver with napalm-ansible but I have always the error "" s350 os not supported".
I set the variable ansible_connection=network_cli

Has anyone already tried this integration?

@barte91 How did you install the s350 driver?

Ensure your napalm installation is working:

napalm --debug --user myusername --password mypassword --vendor s350 mydevice call get_facts  

Example how to get config:

- hosts: sg
  connection: local  
  gather_facts: no  
  tasks:  
    - name: get config from sg devices  
      napalm_get_facts:  
        hostname: switch-hostname  
        dev_os: s350  
        username: myusername  	
        password: mypassword  
        filter: 'config'  
      register: result

@cspeidel
I've run the first command to check if napalm is ok; but I've this error:

2019-01-29 10:12:05,681 - napalm - ERROR - open - Failed: connect() got an unexpected keyword argument 'passphrase'

The debug complete is it:

2019-01-29 10:12:05,678 - napalm - DEBUG - Starting napalm's debugging tool
2019-01-29 10:12:05,678 - napalm - DEBUG - Gathering napalm packages
2019-01-29 10:12:05,678 - napalm - DEBUG - napalm-ansible==0.10.0
2019-01-29 10:12:05,678 - napalm - DEBUG - napalm-asa==0.1.1
2019-01-29 10:12:05,679 - napalm - DEBUG - napalm-mos==2.0.5
2019-01-29 10:12:05,679 - napalm - DEBUG - napalm-s350==0.1.0
2019-01-29 10:12:05,679 - napalm - DEBUG - napalm==2.3.3
2019-01-29 10:12:05,679 - napalm - DEBUG - get_network_driver - Calling with args: ('s350',), {}
2019-01-29 10:12:05,680 - napalm - DEBUG - get_network_driver - Successful
2019-01-29 10:12:05,680 - napalm - DEBUG - __init__ - Calling with args: (<class 'napalm_s350.s350.S350Driver'>, 'mydevice', 'myuser'), {'password': u'*******', 'optional_args': {}, 'timeout': 60}
2019-01-29 10:12:05,680 - napalm - DEBUG - __init__ - Successful
2019-01-29 10:12:05,681 - napalm - DEBUG - pre_connection_tests - Calling with args: (<napalm_s350.s350.S350Driver object at 0x7f0ca8dbdc50>,), {}
2019-01-29 10:12:05,681 - napalm - DEBUG - open - Calling with args: (<napalm_s350.s350.S350Driver object at 0x7f0ca8dbdc50>,), {}
2019-01-29 10:12:05,681 - napalm - ERROR - open - Failed: connect() got an unexpected keyword argument 'passphrase'

Can you help me?

Make sure you use your username, password, and device name for the device you are trying to connect to.

Also for some reason, some of these switches don't use SSH authentication by default (SSH authentication type is none), and instead use a shell-like procedure once you SSH in. On some SG versions you may need to add the following to your config to use SSH authentication like other Cisco devices:

ip ssh password-auth

yes, the username,password and device name is correct, in this switch I enable only SSH auth, I think could be a problem with enable password... where can I definded it?

That's possible. Can you create an account with privilege level 15 and try connecting with that?

What is the output of:

pip show paramiko
pip show netmiko

In theese day I can't try to do a user with privilege 15.
in the meantime i paste you the output of command:

pip show paramiko
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Name: paramiko
Version: 2.4.2
Summary: SSH2 protocol library
Home-page: https://github.com/paramiko/paramiko/
Author: Jeff Forcier
Author-email: jeff@bitprophet.org
License: LGPL
Location: /usr/lib/python2.7/site-packages
Requires: cryptography, pynacl, pyasn1, bcrypt
Required-by: scp, netmiko, ncclient, junos-eznc, ansible
pip show netmiko
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Name: netmiko
Version: 2.3.0
Summary: Multi-vendor library to simplify Paramiko SSH connections to network devices
Home-page: https://github.com/ktbyers/netmiko
Author: Kirk Byers
Author-email: ktbyers@twb-tech.com
License: MIT
Location: /usr/lib/python2.7/site-packages
Requires: paramiko, scp, pyyaml, pyserial, textfsm, enum34, ipaddress
Required-by: pyIOSXR, napalm, napalm-s350, napalm-mos

@ktbyers do you know where the 'passphrase' keyword argument might come from? I don't see it being passed by the S350 driver. Works fine on my installation with the same paramiko/netmiko versions @barte91 is using.

He is getting 2019-01-29 10:12:05,681 - napalm - ERROR - open - Failed: connect() got an unexpected keyword argument 'passphrase'

@cspeidel I try to reinsyall all napalm and community driver (napalm-s350).
First of all, I noticed that the file setup.py can be optimize for pip >10.1 with this code:

try:  # for pip >= 10
        from pip._internal.req import parse_requirements
except ImportError:  # for pip <= 9.0.3
        from pip.req import parse_requirements

Instead this line:
from pip.req import parse_requirements

Then I download the zip file and try to install with python, but I've this error:

[root@NAPALM2 napalm]# python napalm-s350-master/setup.py
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/pip/_internal/download.py", line 444, in get_file_content
    with open(url, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "napalm-s350-master/setup.py", line 16, in <module>
    reqs = [str(ir.req) for ir in install_reqs]
  File "napalm-s350-master/setup.py", line 16, in <listcomp>
    reqs = [str(ir.req) for ir in install_reqs]
  File "/usr/lib/python3.6/site-packages/pip/_internal/req/req_file.py", line 103, in parse_requirements
    filename, comes_from=comes_from, session=session
  File "/usr/lib/python3.6/site-packages/pip/_internal/download.py", line 448, in get_file_content
    'Could not open requirements file: %s' % str(exc)
pip._internal.exceptions.InstallationError: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'

Sorry... I solve my problem to install correctly the driver!
Now if I can try to send command

napalm --debug --user myuser --password mypsw --vendor s350 myhostname call get_facts

I get this error:

2019-01-31 17:35:47,636 - napalm - DEBUG - Starting napalm's debugging tool
2019-01-31 17:35:47,636 - napalm - DEBUG - Gathering napalm packages
2019-01-31 17:35:47,637 - napalm - DEBUG - napalm-s350==0.1.0
2019-01-31 17:35:47,637 - napalm - DEBUG - napalm==2.3.3
2019-01-31 17:35:47,637 - napalm - DEBUG - get_network_driver - Calling with args: ('s350',), {}
2019-01-31 17:35:47,640 - napalm - DEBUG - get_network_driver - Successful
2019-01-31 17:35:47,640 - napalm - DEBUG - init - Calling with args: (<class 'napalm_s350.s350.S350Driver'>, '192.168.2.103', 'admin'), {'password': '*******', 'timeout': 60, 'optional_args': {}}
2019-01-31 17:35:47,640 - napalm - DEBUG - init - Successful
2019-01-31 17:35:47,640 - napalm - DEBUG - pre_connection_tests - Calling with args: (<napalm_s350.s350.S350Driver object at 0x7f9ceae2b898>,), {}
2019-01-31 17:35:47,640 - napalm - DEBUG - open - Calling with args: (<napalm_s350.s350.S350Driver object at 0x7f9ceae2b898>,), {}
2019-01-31 17:35:51,225 - napalm - ERROR - open - Failed: Authentication failure: unable to connect cisco_s300 192.168.2.103:22
('Bad authentication type', ['']) (allowed_types=[''])

================= Traceback =================

Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/netmiko/base_connection.py", line 782, in establish_connection
self.remote_conn_pre.connect(**ssh_connect_params)
File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 437, in connect
passphrase,
File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 749, in _auth
raise saved_exception
File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 736, in _auth
self._transport.auth_password(username, password)
File "/usr/lib/python3.6/site-packages/paramiko/transport.py", line 1436, in auth_password
return self.auth_handler.wait_for_response(my_event)
File "/usr/lib/python3.6/site-packages/paramiko/auth_handler.py", line 250, in wait_for_response
raise e
paramiko.ssh_exception.BadAuthenticationType: ('Bad authentication type', ['']) (allowed_types=[''])

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/bin/napalm", line 11, in
load_entry_point('napalm==2.3.3', 'console_scripts', 'napalm')()
File "/usr/lib/python3.6/site-packages/napalm/base/clitools/cl_napalm.py", line 284, in main
run_tests(args)
File "/usr/lib/python3.6/site-packages/napalm/base/clitools/cl_napalm.py", line 259, in run_tests
call_open_device(device)
File "/usr/lib/python3.6/site-packages/napalm/base/clitools/cl_napalm.py", line 27, in wrapper
r = func(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/napalm/base/clitools/cl_napalm.py", line 191, in call_open_device
return device.open()
File "/usr/lib/python3.6/site-packages/napalm_s350/s350.py", line 93, in open
**self.netmiko_optional_args)
File "/usr/lib/python3.6/site-packages/netmiko/ssh_dispatcher.py", line 218, in ConnectHandler
return ConnectionClass(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/netmiko/base_connection.py", line 270, in init
self.establish_connection()
File "/usr/lib/python3.6/site-packages/netmiko/base_connection.py", line 793, in establish_connection
raise NetMikoAuthenticationException(msg)
netmiko.ssh_exception.NetMikoAuthenticationException: Authentication failure: unable to connect cisco_s300 192.168.2.103:22
('Bad authentication type', ['']) (allowed_types=[''])

I try to switch with user on privilege 15.

Did you add the following to the switch?
ip ssh password-auth

ok, now I set ip ssh password-auth and now I can connect to switch but if I try to do:
napalm --debug --user myuser --password mypasw --vendor s350 ip_device call get_facts
I get this error:

2019-02-01 12:10:21,211 - napalm - DEBUG - Starting napalm's debugging tool
2019-02-01 12:10:21,211 - napalm - DEBUG - Gathering napalm packages
2019-02-01 12:10:21,212 - napalm - DEBUG - napalm-s350==0.1.0
2019-02-01 12:10:21,212 - napalm - DEBUG - napalm==2.3.3
2019-02-01 12:10:21,212 - napalm - DEBUG - get_network_driver - Calling with args: ('s350',), {}
2019-02-01 12:10:21,214 - napalm - DEBUG - get_network_driver - Successful
2019-02-01 12:10:21,214 - napalm - DEBUG - __init__ - Calling with args: (<class 'napalm_s350.s350.S350Driver'>, '10.36.245.123', 'admin'), {'password': '*******', 'timeout': 60, 'optional_args': {}}
2019-02-01 12:10:21,215 - napalm - DEBUG - __init__ - Successful
2019-02-01 12:10:21,215 - napalm - DEBUG - pre_connection_tests - Calling with args: (<napalm_s350.s350.S350Driver object at 0x7fb3f81569e8>,), {}
2019-02-01 12:10:21,215 - napalm - DEBUG - open - Calling with args: (<napalm_s350.s350.S350Driver object at 0x7fb3f81569e8>,), {}
2019-02-01 12:10:27,363 - napalm - DEBUG - open - Successful
2019-02-01 12:10:27,364 - napalm - DEBUG - connection_tests - Calling with args: (<napalm_s350.s350.S350Driver object at 0x7fb3f81569e8>,), {}
2019-02-01 12:10:27,364 - napalm - DEBUG - get_facts - Calling with args: (<napalm_s350.s350.S350Driver object at 0x7fb3f81569e8>,), {}
2019-02-01 12:10:30,977 - napalm - ERROR - get_facts - Failed: list index out of range

================= Traceback =================

Traceback (most recent call last):
  File "/usr/bin/napalm", line 11, in <module>
    load_entry_point('napalm==2.3.3', 'console_scripts', 'napalm')()
  File "/usr/lib/python3.6/site-packages/napalm/base/clitools/cl_napalm.py", line 284, in main
    run_tests(args)
  File "/usr/lib/python3.6/site-packages/napalm/base/clitools/cl_napalm.py", line 263, in run_tests
    call_facts(device)
  File "/usr/lib/python3.6/site-packages/napalm/base/clitools/cl_napalm.py", line 27, in wrapper
    r = func(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/napalm/base/clitools/cl_napalm.py", line 179, in call_facts
    facts = device.get_facts()
  File "/usr/lib/python3.6/site-packages/napalm_s350/s350.py", line 227, in get_facts
    domain_line = show_hosts.splitlines()[4]
IndexError: list index out of range

is it mandatory set the domainname?

Great! Can you give me the full output of "show hosts"? There are some issues I want to fix in the driver.

This is my "show hosts"

MAG245SW001NET#show hosts

Name/address lookup is enabled
Domain Timeout: 2 seconds
Domain Retry: 1 times
Domain Polling Interval: 8 seconds


Default Domain Table

                   Domain                    Source  Interface Preference
-------------------------------------------- ------- --------- ----------
Domain name is not configured


Name Server Table

                 IP Address                  Source  Interface Preference
-------------------------------------------- ------- --------- ----------
Name server is not configured


Cache Table
Flags: (STA/DYN, OK/NE/??)
STA - Static, DYN - Dynamic
OK - Okay, NE - Negative Cache, ?? - No Response

                                                               Remaining
          Host                   Addresses         Type State     TTL
------------------------- ------------------------ ---- ------ ----------
No hostname is mapped to an IP address

@barte91 The issue is because some switches don't support output modifiers (e.g. | begin) which the current code is expecting.

I have made a patch that you can try at https://github.com/cspeidel/napalm-s350. Clone the repo and run python setup.py develop inside the repo.

Let me know if it works for you.

@cspeidel Sorry, I'm out of office for few days, when I return to office I try to do a new patch

Thanks for your support!!

Hi @cspeidel
I try it and now work correctly!!
Thanks for your support!!!! Thank a lot again, I proceed to close this issue

Thanks @barte91. I'll get this merged into the main repo.