def netmiko_Set_config(item1, inter_exter): if inter_exter == 'internal': net_connect = Netmiko(**deviceB) print('***** log in to device {}'.format(deviceB['host'])) else: net_connect = Netmiko(**deviceA) print('***** log in to device {}'.format(deviceA['host'])) f = open( file_path + "/commands/" + str(item1) + "_Loop_" + str(inter_exter) + "_Set_command.txt", 'r') f2 = f.readlines() clear_QOS_ouput() output = net_connect.send_config_set(f2) net_connect.commit() net_connect.exit_config_mode() print(output) command = "show ethernet loopback active | include ID" show_output = net_connect.send_command(command) if item1 == "L2": loop_id_to_render = get_L2_loop_ID(show_output) if loop_id_to_render != "1": print("**** doing rendering one more time") Command_Creation(location, item1, item2, inter_exter, loop_id_to_render, **interface_name) net_connect.disconnect()
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 netmiko_Set_config(item1, device): print("***** log in to device") net_connect = Netmiko(**device) f = open( file_path + "/commands/" + str(item1) + "_shut_noshut_command.txt", 'r') f2 = f.readlines() output = net_connect.send_config_set(f2) net_connect.commit() print(output) net_connect.exit_config_mode() net_connect.disconnect()
def delete_config(self): for node in self.data["site_list"]: net_connect = Netmiko(**node['login']) with open('commands/XC_command_{}_delete.txt'.format(node["Node_name"]),'r') as f: f2 = f.readlines() output = net_connect.send_config_set(f2) print(output) if node['login']['device_type'] == 'cisco_xr': net_connect.commit() else: pass net_connect.exit_config_mode() net_connect.disconnect()
def netmiko_Release_config(self, item1, inter_exter): if inter_exter == 'internal': net_connect = Netmiko(**self.deviceB) print('***** log in to device {}'.format(self.deviceB['host'])) else: net_connect = Netmiko(**self.deviceA) print('***** log in to device {}'.format(self.deviceA['host'])) f = open(self.file_path + "/commands/loop_test/" + str(item1) + "_Loop_" + str(inter_exter) + "_Release_command.txt", 'r') f2 = f.readlines() time.sleep(15) command_ouput(self, self.interface_name_list, self.device_list) output = net_connect.send_config_set(f2) net_connect.commit() net_connect.exit_config_mode() print(output) net_connect.disconnect()
def push_config(self): for node in self.data["site_list"]: net_connect = Netmiko(**node['login']) with open( 'templates/XC_command_{}_create.txt'.format( node["Node_name"]), 'r') as f: f2 = f.readlines() output = net_connect.send_config_set(f2) if node['login']['device_type'] == 'cisco_xr': net_connect.commit() else: pass #print(output) print("**** Configration completed on {}".format( node['Node_name'])) net_connect.exit_config_mode() 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()
'secret': password, 'device_type': 'juniper_junos' # Use invalid device type to see all supported devices # 'device_type': 'foo' } net_conn = Netmiko(**my_device) output = net_conn.send_command("show run | inc logging") print(output) cfg_commands = ['set system syslog archive size 120k files 3'] output = net_conn.send_config_set(cfg_commands) print(output) output = net_conn.commit() print(output) output = net_conn.exit_config_mode() output = net_conn.send_command("show configuration") # Cisco Devices # cfg_commands = ['logging bufered 10000', 'no logging console'] # output = net_conn.send_command(cfg_commands) # copy running config to start # save_command() print() print('-' * 80) print(output) print('-' * 80)
print("***** 30 seconds sleep done") print("***** log in to device") cisco1 = { "host": "10.91.126.199", "username": "******", "password": "******", "device_type": "cisco_xr", } net_connect = Netmiko(**cisco1) command = ['int HundredGigE0/0/1/0', 'no shut'] print() print(net_connect.find_prompt()) output = net_connect.send_config_set(command) net_connect.commit() net_connect.exit_config_mode() #output += net_connect.send_command("show int HundredGigE0/0/1/0") net_connect.disconnect() print(output) print() print("***** log out of device") time.sleep(90) print("***** 90 seconds sleep done") traffic_ctrl_ret = sth.traffic_control( port_handle=[port_handle[0], port_handle[1]], action='stop') print("***** traffic stopped") ##############################################################
'username': '******', 'password': '******', 'device_type': 'cisco_xr', 'port': 8181 } # Establish SSH connection to the network device using **kwargs to pull in details from dictionary net_connection = Netmiko(**cisco_device) # Send show run command to device to see current logging status and print to console output = net_connection.send_command('show run | inc logging') print(output) # Send command to change logging buffer size net_connection.send_config_set('logging buffered 4000000') # Commit this change on IOS-XR device net_connection.commit() # Send show run command again to verify successful config change and print to console output = net_connection.send_command('show run | inc logging') print('-' * 30) print(output) # This time send command to device from a txt file net_connection.send_config_from_file('config.txt') # Commit this change on IOS-XR device net_connection.commit() # Send show run command again to verify successful config change output = net_connection.send_command('show run | inc logging') # Check if logging buffer size is as we set it via config and print confirmation to console if '4000000' in output:
#!/usr/bin/env python from netmiko import Netmiko from getpass import getpass device = { 'host': 'srx1.twb-tech.com', 'username': '******', 'password': getpass(), 'device_type': 'juniper_junos', } commands = ['set system syslog archive size 240k files 3 '] net_connect = Netmiko(**device) print() print(net_connect.find_prompt()) output = net_connect.send_config_set(commands, exit_config_mode=False) output += net_connect.commit(and_quit=True) print(output) print() net_connect.disconnect()
#!/usr/bin/env python from netmiko import Netmiko from getpass import getpass device = { 'host': 'srx1.twb-tech.com', 'username': '******', 'password': getpass(), 'device_type': 'juniper_junos', } commands = [ 'set system syslog archive size 240k files 3 ' ] net_connect = Netmiko(**device) print() print(net_connect.find_prompt()) output = net_connect.send_config_set(commands, exit_config_mode=False) output += net_connect.commit(and_quit=True) print(output) print() net_connect.disconnect()