def send_config_command(device, config_commands): net_connect = Netmiko(**device) net_connect.find_prompt() net_connect.config_mode(config_command='configure private') if net_connect.check_config_mode(): for c in config_commands: output = net_connect.send_config_set(c, exit_config_mode=False) if 'syntax error' in output: print('''Command "{}" error! {} '''.format(c, output)[:-23]) if exit_or_continue(): break elif 'missing argument' in output: print('''Command "{}" error! {} '''.format(c, output)[:-23]) if exit_or_continue(): break elif 'invalid interface type in' in output: print('''Command "{}" error! {} '''.format(c, output)[:-23]) if exit_or_continue(): break net_connect.send_config_set("show | compare", exit_config_mode=False) net_connect.commit(and_quit=True) net_connect.disconnect()
def send_config_command(device, config_commands): net_connect = Netmiko(**device) output = net_connect.find_prompt() output += net_connect.config_mode(config_command='configure private') if net_connect.check_config_mode(): output += net_connect.send_config_set(config_commands, exit_config_mode=False) output += net_connect.send_config_set("show | compare", exit_config_mode=False) output += net_connect.commit(and_quit=True) print(output) net_connect.disconnect()
'port':'22', 'secret':'cisco' } from netmiko import Netmiko connection = Netmiko(**cisco_device) output = connection.send_command('show ip int brief') #Check if enable mode and enter enable mode if not prompt= (connection.find_prompt()) print (prompt) if '>' in prompt: connection.enable() print (connection.find_prompt()) #Entered the enable mode output = connection.send_command('show run') print (output) print (connection.check_config_mode()) if not connection.check_config_mode(): connection.config_mode() print('Switched to config mode') print (connection.check_config_mode()) connection.disconnect()