ktbyers / netmiko

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

Configuration commands not being sent to NX-OS, receiving traceback #702

Closed NtwkEngineer closed 6 years ago

NtwkEngineer commented 6 years ago

Hi Kirk:

I am seeing the following when trying to send configuration commands to an NX-OS device (Nexus 3048 running 6.0(2)U3(7)):

net_connect = ConnectHandler(device_type='cisco_nxos', ip='192.168.1.1', username='a_username', password='a_password', secret='a_password')

net_connect.config_mode()

u'config term\r\r\nEnter configuration commands, one per line. End with CNTL/Z.\r\n\rNexus3K(config)# '

if_name = 'Ethernet1/48'

net_connect.send_command('interface %s' % if_name)

Traceback (most recent call last): File "", line 1, in File "build/bdist.linux-x86_64/egg/netmiko/base_connection.py", line 967, in send_command IOError: Search pattern never detected in send_command_expect: Nexus3K(config)#

net_connect.send_command('interface Ethernet1/48')

u''

Given that it's returning a unicode '', I was able to work around this in my script by using the 'expect_string' option in .send_command():

net_connect.send_command('interface %s' % if_name, expect_string='')

u''

Is this expected behavior, or should netmiko be handling this differently?

Thanks!

-Matt

NtwkEngineer commented 6 years ago

And actually, I'm seeing the same issue with IOS-XE on a 4500-X running 03.06.00.E. Same workaround as well.

ktbyers commented 6 years ago

@NtwkEngineer You should use send_config_set() method to send configuration changes and not try to manually enter/exit config mode.

send_config_set() will automatically enter/exit config mode.

For example:

config_commands=[cmd1, cmd2]
net_connect.send_config_set(config_commands)
NtwkEngineer commented 6 years ago

Perfect, thanks Kirk!