ktbyers / netmiko

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

hp_comware defaulting an interface using send_config_from_file #1862

Closed davidforde1208 closed 4 years ago

davidforde1208 commented 4 years ago

Hi,

am a newbee to python, am in a bit of a bind. I have managed to get a script to read commands from file using the send_config_from_file, however when the hp_comware command to default an interface "default" is prompted to confirm defaulting the interface requiring a "y" and enter (if you were to do it on the CLI of the switch). i am getting a "Timed-out reading channel, data not available" error. I also for logging purpsoses have the output going to a file of the changes made to both switches.

I have added the arguements for the connection handler: "global_delay_factor": 10, "blocking_timeout": 15 to the dictionary that is creating the SSH connection to see if it was a timing issue - but get the same error. have pasted code below with some bits redacted

code: from future import absolute_import, division, print_function

import json import netmiko import mytools import time

netmiko_exceptions = (netmiko.ssh_exception.NetMikoTimeoutException, netmiko.ssh_exception.NetMikoAuthenticationException)

username, password = mytools.get_credentials()

with open('switches.json') as dev_file: devices = json.load(dev_file)

for device in devices: device['username'] = username device['password'] = password try: print('~' * 79) print('Connecting to device:', device['ip']) connection = netmiko.ConnectHandler(**device) filename = connection.base_prompt + '.txt' with open(filename, 'w') as out_file: if device['ip'] == '': out_file.write('moving to system mode -> ' +connection.enable('system')) out_file.write('Sent following command to: ' +connection.find_prompt()+ ' -> ' +connection.send_config_from_file( 'core_commands_1.txt')+ '\n\n') time.sleep(50) out_file.write(connection.send_command('display ospf peer')) out_file.write(connection.send_command('save force')) print ('disconnecting... ' +connection.disconnect()) elif device['ip'] != '': out_file.write('moving to system mode -> ' +connection.enable( 'system')) out_file.write('Sent following command to: ' +connection.find_prompt()+ ' -> ' +connection.send_config_from_file( 'access_switch_commands_1.txt')+ '\n\n') out_file.write(connection.send_command('save force')) print('disconecting... ' +connection.disconnect()) except netmiko_exceptions as e: print('Failed to ', device['ip'], e)

commands in both files to be read where issue occurs:

interface Ten-GigabitEthernet2/2/0/27 default <----- this point is where it hangs y <------ this doesn't get sent to the switch

output with errors:

Connecting to device: <IPADDRESS>
Failed to  <IPADDRESS> Timed-out reading channel, data not available.

Connecting to device: Failed to Timed-out reading channel, data not available.

davidforde1208 commented 4 years ago

okay so i found a work around, it doesn't resolve the issue where by the delay in defaulting a switchport causes the timeout issue.

i changed the default command in my command config file to "undo port link-mode"

going forward i may need to issue the "default" command to the switchport interface.