1. Introduction
This module is used to simplify the SSH connection between paramiko and network devices, and can be used on Windows and Unix platforms.
2. Currently supported devices
(2019.03.07)
Regularly tested Arista vEOS Cisco ASA Cisco IOS Cisco IOS-XE Cisco IOS-XR Cisco NX-OS Cisco SG300 HP Comware7 HP ProCurve Juniper Junos Linux Limited testing Alcatel AOS6/AOS8 Apresia Systems AEOS Calix B6 Cisco AireOS (Wireless LAN Controllers) Dell OS9 (Force10) Dell OS10 Dell PowerConnect Extreme ERS (Avaya) Extreme VSP (Avaya) Extreme VDX (Brocade) Extreme MLX/NetIron (Brocade/Foundry) Huawei IP Infusion OcNOS Mellanox NetApp cDOT OneAccess Palo Alto PAN-OS Pluribus Ruckus ICX/FastIron Ubiquiti EdgeSwitch Vyatta VyOS Experimental A10 Accedian Aruba Ciena SAOS Citrix Netscaler Cisco Telepresence Check Point GAiA Coriant Dell OS6 Dell EMC Isilon Eltex Enterasys Extreme EXOS Extreme Wing Extreme SLX (Brocade) F5 TMSH F5 Linux Fortinet MRV Communications OptiSwitch Nokia/Alcatel SR-OS QuantaMesh Rad ETX
3. Experimental environment
1. Operating system: win10
Version: python3.6.6
Module version: 2.3.0
4. Install netmiko module
#Preparation preparation module (install netmiko to automatically download dependencies):Paramiko >= 2.4.1 scp >= 0.10.0 pyyaml pyserial textfsm #install netmikopip install netmiko
ps: There are no all prerequisite modules installed, no errors are reported when using netmiko, which means that there is no call in the running code, not that it is not needed.
5. Simple examples
5.1 Execute the viewing command: show ip int brief
from netmiko import ConnectHandler cisco = { 'device_type':'cisco_ios', 'host':'ip address', 'username':'username', 'password':'password' } net_connect = ConnectHandler(**cisco) ##or# net_connect = ConnectHandler(device_type='cisco_ios',host='IP address',username='username',password='password') #Find the current viewcurrent_view = net_connect.find_prompt() print(current_view) #Execute the command, return the result as a string, assign the value to outputoutput = net_connect.send_command('show ip int brief') print(output) # #This is if \n cannot display the carriage input in Windows, the following statement format is performed# o_list = ("\n") # for line in o_list: # print(line)
5.2 Execute the configuration command: manually close interface G1/0/29
from netmiko import ConnectHandler cisco = { 'device_type':'cisco_ios', 'host':'ip address', 'username':'username', 'password':'password' } net_connect = ConnectHandler(**cisco) ##or# net_connect = ConnectHandler(device_type='cisco_ios',host='IP address',username='username',password='password') #Command to be configuredconfig_commands = ['interface GigabitEthernet1/0/29','shutdown'] #Submit the command to be configured, input is the real content of the submittedinput = net_connect.send_config_set(config_commands) #Verify whether shutdown is executed successfullyoutput = net_connect.send_command('show run inter gi1/0/29') print(output) # #This is if \n cannot display the carriage input in Windows, the following statement format is performed# o_list = ("\n") # for line in o_list: # print(line)
6. Common methods
- net_connect.send_command() # Send commands down and return output (based on mode)
- net_connect.send_command_timing() # Send commands along the channel and return output (based on timing)
- net_connect.send_config_set() # Send configuration commands to remote devices
- net_connect.send_config_from_file() # Send configuration commands loaded from a file
- net_connect.save_config() # Save running#config to startup#config
- net_connect.enable() # Enter Enable Mode
- net_connect.find_prompt() # Return to the current router prompt
- net_connect.commit() # Perform a commit operation on Juniper and IOS#XR
- net_connect.disconnect() # Close the connection
- net_connect.write_channel() # Low-level write to the channel
- net_connect.read_channel() # Low-level write to the channel
7. References
1./blog/automation/
2./ktbyers/netmiko
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.