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 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()
#!/usr/bin/env python from netmiko import Netmiko from getpass import getpass password = getpass() cisco1 = { 'host': 'cisco1.twb-tech.com', 'username': '******', 'password': password, 'device_type': 'cisco_ios', 'secret': password, } net_connect = Netmiko(**cisco1) print(net_connect.find_prompt()) net_connect.send_command_timing("disable") print(net_connect.find_prompt()) net_connect.enable() print(net_connect.find_prompt()) # Go into config mode net_connect.config_mode() print(net_connect.find_prompt()) net_connect.exit_config_mode() print(net_connect.find_prompt()) net_connect.disconnect()
pprint(nxos1_config) print("Splitting Config for nxos2 from template") print("^" * 35) nxos2_config = re.search("^##nxos2.*$", output, re.S | re.M).group(0) pprint(nxos2_config) print("Logging into NXOS devices") print("-" * 25) from my_devices_exercise2c import nxos1, nxos2 #try: ssh_connection1 = Netmiko(**nxos1) output1 = ssh_connection1.send_config_set(nxos1_config, cmd_verify=False) print(output1) output1 += ssh_connection1.exit_config_mode() pprint(output1) #except ValueError: # print("Value Error Occured") ssh_connection2 = Netmiko(**nxos2) output2 = ssh_connection2.send_config_set(nxos2_config, cmd_verify=False) pprint(output2) #except ValueError: # print("Value Error Occured") # output3 = ssh_connection1.send_command_timing("show bgp sessions") # output4 = ssh_connection2.send_command_timing("ping 10.1.100.1") # print(output3) # print(output4) # # #
"device_type": "cisco_ios", "session_log": "my_output.txt", } # Establish SSH connection to the network device using **kwargs to pull in details from dictionary net_connect = Netmiko(**device) # Part a - find and print the prompt to the screen print(net_connect.find_prompt()) # Part B - Enter config mode and find the prompt print(net_connect.config_mode()) print(net_connect.find_prompt()) # Part C - exit config mode and print the prompt print(net_connect.exit_config_mode()) print(net_connect.find_prompt()) # Part D - send disable down the SSH channel print(net_connect.write_channel('disable\n')) # Part E - Sleep for 2s and read back from SSH channel time.sleep(2) print(net_connect.read_channel()) # Part F - Go into enable mode and print prompt print(net_connect.enable()) print(net_connect.find_prompt()) net_connect.disconnect()
'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()
from netmiko import Netmiko from getpass import getpass net_connect = Netmiko(host='10.110.25.250', username='******', password="******", device_type='huawei') print(net_connect.find_prompt()) commands = [ ' interface GigabitEthernet1/0/27', 'port link-type access', 'port access vlan 103', ] print("######################################") #output = net_connect.send_config_set(commands, exit_config_mode=False) output = net_connect.send_config_set(commands) output += net_connect.exit_config_mode(exit_config='return', pattern='>') print(output) print("######################################") #net_connect.read_until_pattern(pattern='<') net_connect.disconnect()
password = getpass() device = { "host": "cisco4.lasthop.io", "username": "******", "password": password, "secret": password, "device_type": "cisco_ios", "session_log": "my_output_l2-ex6.txt", } net_connection = Netmiko(**device) print(net_connection.find_prompt()) net_connection.config_mode() print(net_connection.find_prompt()) net_connection.exit_config_mode() print(net_connection.find_prompt()) net_connection.write_channel("disable\n") time.sleep(2) output = net_connection.read_channel() print(output) print("Enter enable mode") net_connection.enable() print(net_connection.find_prompt()) net_connection.disconnect() print()
} ssh_conn = Netmiko(**devices) print("-" * 79) print("Execution of the command prompt :") print("-" * 79) print(ssh_conn.find_prompt()) print("-" * 79) print("Execution the config_mode:") print("-" * 79) ssh_conn.config_mode() print(ssh_conn.find_prompt()) print("-" * 79) print("Execution the exit_config_mode:") print("-" * 79) ssh_conn.exit_config_mode() print(ssh_conn.find_prompt()) print("-" * 79) print("Execution the write_channel:") print("-" * 79) ssh_conn.write_channel('disable') print(ssh_conn.find_prompt()) print("-" * 79) print("Execution the time sleep command:") time.sleep(2) print("-" * 79) print("Execution the read_channel:") print("-" * 79) ssh_conn.read_channel() print(ssh_conn.find_prompt()) print("-" * 79)