Skip to content

Commit

Permalink
Merge pull request #737 from ktbyers/develop
Browse files Browse the repository at this point in the history
Netmiko release 2.1.0
  • Loading branch information
ktbyers authored Mar 7, 2018
2 parents 2f60d4d + 729798c commit e575775
Show file tree
Hide file tree
Showing 38 changed files with 932 additions and 582 deletions.
98 changes: 0 additions & 98 deletions examples/DEVICE_CREDS.py

This file was deleted.

21 changes: 21 additions & 0 deletions examples/adding_delay/add_delay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python
from __future__ import print_function, unicode_literals

# Netmiko is the same as ConnectHandler
from netmiko import Netmiko
from getpass import getpass

my_device = {
'host': "host.domain.com",
'username': 'pyclass',
'password': getpass(),
'device_type': 'cisco_ios',
# Increase (essentially) all sleeps by a factor of 2
'global_delay_factor': 2,
}

net_connect = Netmiko(**my_device)
# Increase the sleeps for just send_command by a factor of 2
output = net_connect.send_command("show ip int brief", delay_factor=2)
print(output)
net_connect.disconnect()
55 changes: 30 additions & 25 deletions examples/asa_upgrade.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
#!/usr/bin/env python
"""Script to upgrade a Cisco ASA."""
import sys
from __future__ import print_function
from datetime import datetime
from getpass import getpass
from netmiko import ConnectHandler, FileTransfer


def asa_scp_handler(ssh_conn, cmd='ssh scopy enable', mode='enable'):
"""Enable/disable SCP on Cisco ASA."""
if mode == 'disable':
cmd = 'no ' + cmd
return ssh_conn.send_config_set([cmd])


def main():
"""Script to upgrade a Cisco ASA."""
ip_addr = raw_input("Enter ASA IP address: ")
try:
ip_addr = raw_input("Enter ASA IP address: ")
except NameError:
ip_addr = input("Enter ASA IP address: ")
my_pass = getpass()
start_time = datetime.now()
print ">>>> {}".format(start_time)
print(">>>> {}".format(start_time))

net_device = {
'device_type': 'cisco_asa',
Expand All @@ -27,16 +32,15 @@ def main():
'port': 22,
}

print "\nLogging in to ASA"
print("\nLogging in to ASA")
ssh_conn = ConnectHandler(**net_device)
print
print()

# ADJUST TO TRANSFER IMAGE FILE
dest_file_system = 'disk0:'
source_file = 'test1.txt'
dest_file = 'test1.txt'
alt_dest_file = 'asa825-59-k8.bin'
scp_changed = False

with FileTransfer(ssh_conn, source_file=source_file, dest_file=dest_file,
file_system=dest_file_system) as scp_transfer:
Expand All @@ -45,42 +49,43 @@ def main():
if not scp_transfer.verify_space_available():
raise ValueError("Insufficient space available on remote device")

print "Enabling SCP"
print("Enabling SCP")
output = asa_scp_handler(ssh_conn, mode='enable')
print output
print(output)

print "\nTransferring file\n"
print("\nTransferring file\n")
scp_transfer.transfer_file()

print "Disabling SCP"
print("Disabling SCP")
output = asa_scp_handler(ssh_conn, mode='disable')
print output
print(output)

print "\nVerifying file"
print("\nVerifying file")
if scp_transfer.verify_file():
print "Source and destination MD5 matches"
print("Source and destination MD5 matches")
else:
raise ValueError("MD5 failure between source and destination files")

print "\nSending boot commands"
print("\nSending boot commands")
full_file_name = "{}/{}".format(dest_file_system, alt_dest_file)
boot_cmd = 'boot system {}'.format(full_file_name)
output = ssh_conn.send_config_set([boot_cmd])
print output
print(output)

print "\nVerifying state"
print("\nVerifying state")
output = ssh_conn.send_command('show boot')
print output
print(output)

# UNCOMMENT TO PERFORM WR MEM AND RELOAD
#print "\nWrite mem and reload"
#output = ssh_conn.send_command_expect('write mem')
#output += ssh_conn.send_command('reload')
#output += ssh_conn.send_command('y')
#print output

print "\n>>>> {}".format(datetime.now() - start_time)
print
# print("\nWrite mem and reload")
# output = ssh_conn.send_command_expect('write mem')
# output += ssh_conn.send_command('reload')
# output += ssh_conn.send_command('y')
# print(output)

print("\n>>>> {}".format(datetime.now() - start_time))
print()


if __name__ == "__main__":
main()
29 changes: 0 additions & 29 deletions examples/ciscoTP_example.py

This file was deleted.

2 changes: 0 additions & 2 deletions examples/cisco_logging.txt

This file was deleted.

2 changes: 2 additions & 0 deletions examples/configuration_changes/change_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
logging buffered 8000
logging console
22 changes: 22 additions & 0 deletions examples/configuration_changes/config_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
from __future__ import print_function, unicode_literals

# Netmiko is the same as ConnectHandler
from netmiko import Netmiko
from getpass import getpass

my_device = {
'host': "host.domain.com",
'username': 'pyclass',
'password': getpass(),
'device_type': 'cisco_ios',
}

net_connect = Netmiko(**my_device)
cfg_commands = ['logging buffered 10000', 'no logging console']

# send_config_set() will automatically enter/exit config mode
output = net_connect.send_config_set(cfg_commands)
print(output)

net_connect.disconnect()
21 changes: 21 additions & 0 deletions examples/configuration_changes/config_changes_from_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python
from __future__ import print_function, unicode_literals

# Netmiko is the same as ConnectHandler
from netmiko import Netmiko
from getpass import getpass

my_device = {
'host': "host.domain.com",
'username': 'pyclass',
'password': getpass(),
'device_type': 'cisco_ios',
}

net_connect = Netmiko(**my_device)

# Make configuration changes using an external file
output = net_connect.send_config_from_file("change_file.txt")
print(output)

net_connect.disconnect()
37 changes: 37 additions & 0 deletions examples/connect_multiple_devices/connect_multiple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python
"""
This example is serial (i.e. no concurrency). Connect to one device, after the other,
after the other.
"""
from __future__ import print_function, unicode_literals

# Netmiko is the same as ConnectHandler
from netmiko import Netmiko
from getpass import getpass

password = getpass()

cisco1 = {
'host': "host1.domain.com",
'username': 'pyclass',
'password': password,
'device_type': 'cisco_ios',
}

arista1 = {
'host': "host2.domain.com",
'username': 'pyclass',
'password': password,
'device_type': 'arista_eos',
}

srx1 = {
'host': "host3.domain.com",
'username': 'pyclass',
'password': password,
'device_type': 'juniper_junos',
}

for device in (cisco1, arista1, srx1):
net_connect = Netmiko(**device)
print(net_connect.find_prompt())
20 changes: 20 additions & 0 deletions examples/enable/enable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python
from __future__ import print_function, unicode_literals

# Netmiko is the same as ConnectHandler
from netmiko import Netmiko
from getpass import getpass

my_device = {
'host': "host.domain.com",
'username': 'pyclass',
'password': getpass(),
'device_type': 'cisco_ios',
}

net_connect = Netmiko(**my_device)
# Ensure in enable mode
net_connect.enable()
print(net_connect.find_prompt())

net_connect.disconnect()
Loading

0 comments on commit e575775

Please sign in to comment.