Introduction To Netmiko
Introduction To Netmiko
Netmiko
The library is based on the Paramiko SSH library and
is named Netmiko.
The purposes of this library are the following:
Testing
Regularly Limited
Experimental
tested testing
Regularly
tested
Arista EOS
Cisco ASA
Cisco IOS/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 OS10
Dell PowerConnect
Extreme MLX/NetIron
(Brocade/Foundry)
Huawei
and many more..
Experimental
A10
Accedian
Aruba
Ciena SAOS
Citrix Netscaler
Cisco Telepresence
Check Point GAiA
Coriant
Dell OS6
Dell EMC Isilon
Nokia/Alcatel SR-OS
QuantaMesh
Example 1: Simple SSH session to a Cisco router;
execute and return the 'show ip int brief'
command.
First, we must import the ConnectHandler factory function from
Netmiko.
This factory function selects the correct Netmiko class based upon the
device_type.
net_connect2 = ConnectHandler(device_type='cisco_ios',
host='cisco.domain.com', username='admin',
password='cisco123')
Now at this point we should have an established SSH connection. We
can verify this by executing the find_prompt() method
In [5]: net_connect.find_prompt()
Out[5]: 'cisco3#'
We can also send commands down the SSH channel and receive the
output back. Here, we use the .send_command() method to send the
'show ip int brief' command:
cisco1 = {
"host": "cisco1.twb-tech.com",
"username": "pyclass",
"password": getpass(),
"device_type": "cisco_ios",
}
net_connect = Netmiko(**cisco1)
print(net_connect.find_prompt())
net_connect.disconnect()
Basic Threads Example
start_time = datetime.now()
for a_device in devices:
my_thread = threading.Thread(target=show_version,
args=(a_device,))
my_thread.start()
main_thread = threading.currentThread()
for some_thread in threading.enumerate():
if some_thread != main_thread:
print(some_thread)
some_thread.join()
print("\nElapsed time: " + str(datetime.now() - start_time))
if __name__ == "__main__":
main()