Skip to content

Commit e575775

Browse files
authored
Merge pull request #737 from ktbyers/develop
Netmiko release 2.1.0
2 parents 2f60d4d + 729798c commit e575775

38 files changed

+932
-582
lines changed

examples/DEVICE_CREDS.py

Lines changed: 0 additions & 98 deletions
This file was deleted.

examples/adding_delay/add_delay.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
from __future__ import print_function, unicode_literals
3+
4+
# Netmiko is the same as ConnectHandler
5+
from netmiko import Netmiko
6+
from getpass import getpass
7+
8+
my_device = {
9+
'host': "host.domain.com",
10+
'username': 'pyclass',
11+
'password': getpass(),
12+
'device_type': 'cisco_ios',
13+
# Increase (essentially) all sleeps by a factor of 2
14+
'global_delay_factor': 2,
15+
}
16+
17+
net_connect = Netmiko(**my_device)
18+
# Increase the sleeps for just send_command by a factor of 2
19+
output = net_connect.send_command("show ip int brief", delay_factor=2)
20+
print(output)
21+
net_connect.disconnect()

examples/asa_upgrade.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
#!/usr/bin/env python
22
"""Script to upgrade a Cisco ASA."""
3-
import sys
3+
from __future__ import print_function
44
from datetime import datetime
55
from getpass import getpass
66
from netmiko import ConnectHandler, FileTransfer
77

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

15+
1416
def main():
1517
"""Script to upgrade a Cisco ASA."""
16-
ip_addr = raw_input("Enter ASA IP address: ")
18+
try:
19+
ip_addr = raw_input("Enter ASA IP address: ")
20+
except NameError:
21+
ip_addr = input("Enter ASA IP address: ")
1722
my_pass = getpass()
1823
start_time = datetime.now()
19-
print ">>>> {}".format(start_time)
24+
print(">>>> {}".format(start_time))
2025

2126
net_device = {
2227
'device_type': 'cisco_asa',
@@ -27,16 +32,15 @@ def main():
2732
'port': 22,
2833
}
2934

30-
print "\nLogging in to ASA"
35+
print("\nLogging in to ASA")
3136
ssh_conn = ConnectHandler(**net_device)
32-
print
37+
print()
3338

3439
# ADJUST TO TRANSFER IMAGE FILE
3540
dest_file_system = 'disk0:'
3641
source_file = 'test1.txt'
3742
dest_file = 'test1.txt'
3843
alt_dest_file = 'asa825-59-k8.bin'
39-
scp_changed = False
4044

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

48-
print "Enabling SCP"
52+
print("Enabling SCP")
4953
output = asa_scp_handler(ssh_conn, mode='enable')
50-
print output
54+
print(output)
5155

52-
print "\nTransferring file\n"
56+
print("\nTransferring file\n")
5357
scp_transfer.transfer_file()
5458

55-
print "Disabling SCP"
59+
print("Disabling SCP")
5660
output = asa_scp_handler(ssh_conn, mode='disable')
57-
print output
61+
print(output)
5862

59-
print "\nVerifying file"
63+
print("\nVerifying file")
6064
if scp_transfer.verify_file():
61-
print "Source and destination MD5 matches"
65+
print("Source and destination MD5 matches")
6266
else:
6367
raise ValueError("MD5 failure between source and destination files")
6468

65-
print "\nSending boot commands"
69+
print("\nSending boot commands")
6670
full_file_name = "{}/{}".format(dest_file_system, alt_dest_file)
6771
boot_cmd = 'boot system {}'.format(full_file_name)
6872
output = ssh_conn.send_config_set([boot_cmd])
69-
print output
73+
print(output)
7074

71-
print "\nVerifying state"
75+
print("\nVerifying state")
7276
output = ssh_conn.send_command('show boot')
73-
print output
77+
print(output)
7478

7579
# UNCOMMENT TO PERFORM WR MEM AND RELOAD
76-
#print "\nWrite mem and reload"
77-
#output = ssh_conn.send_command_expect('write mem')
78-
#output += ssh_conn.send_command('reload')
79-
#output += ssh_conn.send_command('y')
80-
#print output
81-
82-
print "\n>>>> {}".format(datetime.now() - start_time)
83-
print
80+
# print("\nWrite mem and reload")
81+
# output = ssh_conn.send_command_expect('write mem')
82+
# output += ssh_conn.send_command('reload')
83+
# output += ssh_conn.send_command('y')
84+
# print(output)
85+
86+
print("\n>>>> {}".format(datetime.now() - start_time))
87+
print()
88+
8489

8590
if __name__ == "__main__":
8691
main()

examples/ciscoTP_example.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

examples/cisco_logging.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
logging buffered 8000
2+
logging console
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
from __future__ import print_function, unicode_literals
3+
4+
# Netmiko is the same as ConnectHandler
5+
from netmiko import Netmiko
6+
from getpass import getpass
7+
8+
my_device = {
9+
'host': "host.domain.com",
10+
'username': 'pyclass',
11+
'password': getpass(),
12+
'device_type': 'cisco_ios',
13+
}
14+
15+
net_connect = Netmiko(**my_device)
16+
cfg_commands = ['logging buffered 10000', 'no logging console']
17+
18+
# send_config_set() will automatically enter/exit config mode
19+
output = net_connect.send_config_set(cfg_commands)
20+
print(output)
21+
22+
net_connect.disconnect()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
from __future__ import print_function, unicode_literals
3+
4+
# Netmiko is the same as ConnectHandler
5+
from netmiko import Netmiko
6+
from getpass import getpass
7+
8+
my_device = {
9+
'host': "host.domain.com",
10+
'username': 'pyclass',
11+
'password': getpass(),
12+
'device_type': 'cisco_ios',
13+
}
14+
15+
net_connect = Netmiko(**my_device)
16+
17+
# Make configuration changes using an external file
18+
output = net_connect.send_config_from_file("change_file.txt")
19+
print(output)
20+
21+
net_connect.disconnect()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
"""
3+
This example is serial (i.e. no concurrency). Connect to one device, after the other,
4+
after the other.
5+
"""
6+
from __future__ import print_function, unicode_literals
7+
8+
# Netmiko is the same as ConnectHandler
9+
from netmiko import Netmiko
10+
from getpass import getpass
11+
12+
password = getpass()
13+
14+
cisco1 = {
15+
'host': "host1.domain.com",
16+
'username': 'pyclass',
17+
'password': password,
18+
'device_type': 'cisco_ios',
19+
}
20+
21+
arista1 = {
22+
'host': "host2.domain.com",
23+
'username': 'pyclass',
24+
'password': password,
25+
'device_type': 'arista_eos',
26+
}
27+
28+
srx1 = {
29+
'host': "host3.domain.com",
30+
'username': 'pyclass',
31+
'password': password,
32+
'device_type': 'juniper_junos',
33+
}
34+
35+
for device in (cisco1, arista1, srx1):
36+
net_connect = Netmiko(**device)
37+
print(net_connect.find_prompt())

examples/enable/enable.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python
2+
from __future__ import print_function, unicode_literals
3+
4+
# Netmiko is the same as ConnectHandler
5+
from netmiko import Netmiko
6+
from getpass import getpass
7+
8+
my_device = {
9+
'host': "host.domain.com",
10+
'username': 'pyclass',
11+
'password': getpass(),
12+
'device_type': 'cisco_ios',
13+
}
14+
15+
net_connect = Netmiko(**my_device)
16+
# Ensure in enable mode
17+
net_connect.enable()
18+
print(net_connect.find_prompt())
19+
20+
net_connect.disconnect()

0 commit comments

Comments
 (0)