Skip to content

Commit

Permalink
Fixing pycodestyle upgrade issue; adding DFWCUG use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbyers committed Apr 17, 2018
1 parent 27ca30d commit 0a9457d
Show file tree
Hide file tree
Showing 40 changed files with 971 additions and 2 deletions.
20 changes: 20 additions & 0 deletions examples/use_cases/case10_ssh_proxy/conn_ssh_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass

key_file = "/home/gituser/.ssh/test_rsa"

cisco1 = {
'device_type': 'cisco_ios',
'host': 'cisco1.twb-tech.com',
'username': 'testuser',
'use_keys': True,
'key_file': key_file,
'ssh_config_file': './ssh_config',
}

net_connect = Netmiko(**cisco1)
print(net_connect.find_prompt())
output = net_connect.send_command("show ip arp")
print(output)

7 changes: 7 additions & 0 deletions examples/use_cases/case10_ssh_proxy/ssh_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
host jumphost
IdentityFile ~/.ssh/test_rsa
user gituser
hostname 54.241.72.159

host * !jumphost
ProxyCommand ssh jumphost nc %h %p
18 changes: 18 additions & 0 deletions examples/use_cases/case11_logging/conn_with_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass

import logging
logging.basicConfig(filename='test.log', level=logging.DEBUG)
logger = logging.getLogger("netmiko")

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()
64 changes: 64 additions & 0 deletions examples/use_cases/case11_logging/test.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
DEBUG:paramiko.transport:starting thread (client mode): 0xb63946ec
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.4.1
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-Cisco-1.25
INFO:paramiko.transport:Connected (version 2.0, client Cisco-1.25)
DEBUG:paramiko.transport:kex algos:['diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa'] client encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-cbc', '3des-cbc', 'aes192-cbc', 'aes256-cbc'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-cbc', '3des-cbc', 'aes192-cbc', 'aes256-cbc'] client mac:['hmac-sha1', 'hmac-sha1-96', 'hmac-md5', 'hmac-md5-96'] server mac:['hmac-sha1', 'hmac-sha1-96', 'hmac-md5', 'hmac-md5-96'] client compress:['none'] server compress:['none'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group-exchange-sha1
DEBUG:paramiko.transport:HostKey agreed: ssh-rsa
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:MAC agreed: hmac-sha1
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:Got server p (2048 bits)
DEBUG:paramiko.transport:kex engine KexGex specified hash_algo <built-in function openssl_sha1>
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Adding ssh-rsa host key for cisco1.twb-tech.com: b'c77967d9e78b5c6d9acaaa55cc7ad897'
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (password) successful!
DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes
DEBUG:paramiko.transport:[chan 0] Max packet out: 4096 bytes
DEBUG:paramiko.transport:Secsh channel 0 opened.
DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok
DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok
DEBUG:netmiko:read_channel:
pynet-rtr1#
DEBUG:netmiko:read_channel:
DEBUG:netmiko:read_channel:
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:read_channel:
pynet-rtr1#
DEBUG:netmiko:read_channel:
DEBUG:netmiko:read_channel:
DEBUG:netmiko:In disable_paging
DEBUG:netmiko:Command: terminal length 0

DEBUG:netmiko:write_channel: b'terminal length 0\n'
DEBUG:netmiko:Pattern is: pynet\-rtr1
DEBUG:netmiko:_read_channel_expect read_data: ter
DEBUG:netmiko:_read_channel_expect read_data: minal length 0
pynet-rtr1#
DEBUG:netmiko:Pattern found: pynet\-rtr1 terminal length 0
pynet-rtr1#
DEBUG:netmiko:terminal length 0
pynet-rtr1#
DEBUG:netmiko:Exiting disable_paging
DEBUG:netmiko:write_channel: b'terminal width 511\n'
DEBUG:netmiko:Pattern is: pynet\-rtr1
DEBUG:netmiko:_read_channel_expect read_data: t
DEBUG:netmiko:_read_channel_expect read_data: erminal width 511
pynet-rtr1#
DEBUG:netmiko:Pattern found: pynet\-rtr1 terminal width 511
pynet-rtr1#
DEBUG:netmiko:read_channel:
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:read_channel:
pynet-rtr1#
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:read_channel:
pynet-rtr1#
DEBUG:netmiko:read_channel:
DEBUG:netmiko:read_channel:
DEBUG:netmiko:exit_config_mode:
DEBUG:netmiko:write_channel: b'exit\n'
19 changes: 19 additions & 0 deletions examples/use_cases/case11_logging/write_channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass
import time

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.write_channel("show ip int brief\n")
time.sleep(1)
output = net_connect.read_channel()
print(output)
net_connect.disconnect()
14 changes: 14 additions & 0 deletions examples/use_cases/case12_telnet/conn_telnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass

cisco1 = {
'host': 'cisco1.twb-tech.com',
'username': 'pyclass',
'password': getpass(),
'device_type': 'cisco_ios_telnet',
}

net_connect = Netmiko(**cisco1)
print(net_connect.send_command("show ip arp"))
net_connect.disconnect()
55 changes: 55 additions & 0 deletions examples/use_cases/case13_term_server/term_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python
import time
from netmiko import ConnectHandler, redispatch

net_connect = ConnectHandler(
device_type='terminal_server',
ip='10.10.10.10',
username='admin',
password='admin123',
secret='secret123')

# Manually handle interaction in the Terminal Server (fictional example, but
# hopefully you see the pattern)
net_connect.write_channel("\r\n")
time.sleep(1)
net_connect.write_channel("\r\n")
time.sleep(1)
output = net_connect.read_channel()
# Should hopefully see the terminal server prompt
print(output)

# Login to end device from terminal server
net_connect.write_channel("connect 1\r\n")
time.sleep(1)

# Manually handle the Username and Password
max_loops = 10
i = 1
while i <= max_loops:
output = net_connect.read_channel()

if 'Username' in output:
net_connect.write_channel(net_connect.username + '\r\n')
time.sleep(1)
output = net_connect.read_channel()

# Search for password pattern / send password
if 'Password' in output:
net_connect.write_channel(net_connect.password + '\r\n')
time.sleep(.5)
output = net_connect.read_channel()
# Did we successfully login
if '>' in output or '#' in output:
break

net_connect.write_channel('\r\n')
time.sleep(.5)
i += 1

# We are now logged into the end device
# Dynamically reset the class back to the proper Netmiko class
redispatch(net_connect, device_type='cisco_ios')

# Now just do your normal Netmiko operations
new_output = net_connect.send_command("show ip int brief")
27 changes: 27 additions & 0 deletions examples/use_cases/case14_secure_copy/secure_copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python
from getpass import getpass
from netmiko import ConnectHandler, file_transfer

password = getpass()

cisco = {
'device_type': 'cisco_ios',
'host': 'cisco1.twb-tech.com',
'username': 'pyclass',
'password': password,
}

source_file = 'test1.txt'
dest_file = 'test1.txt'
direction = 'put'
file_system = 'flash:'

ssh_conn = ConnectHandler(**cisco)
transfer_dict = file_transfer(ssh_conn,
source_file=source_file,
dest_file=dest_file,
file_system=file_system,
direction=direction,
overwrite_file=True)

print(transfer_dict)
1 change: 1 addition & 0 deletions examples/use_cases/case14_secure_copy/test1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
whatever
69 changes: 69 additions & 0 deletions examples/use_cases/case15_netmiko_tools/.netmiko.yml_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---

# Dictionary is a device
pynet_rtr1:
device_type: cisco_ios
host: cisco1.twb-tech.com
username: admin
password: cisco123
port: 22

pynet_rtr2:
device_type: cisco_ios
ip: 10.10.10.71
username: admin
password: cisco123

arista_sw1:
device_type: arista_eos
ip: 10.10.10.72
username: admin
password: cisco123

arista_sw2:
device_type: arista_eos
ip: 10.10.10.73
username: admin
password: cisco123

arista_sw3:
device_type: arista_eos
ip: 10.10.10.74
username: admin
password: cisco123

arista_sw4:
device_type: arista_eos
ip: 10.10.10.75
username: admin
password: cisco123

juniper_srx:
device_type: juniper
ip: 10.10.10.76
username: admin
password: cisco123

cisco_asa:
device_type: cisco_asa
ip: 10.10.10.1
username: admin
password: cisco123
secret: secret

# Any list is group of devices
cisco:
- pynet_rtr1
- pynet_rtr2

asa:
- cisco_asa

arista:
- arista_sw1
- arista_sw2
- arista_sw3
- arista_sw4

juniper:
- juniper_srx
6 changes: 6 additions & 0 deletions examples/use_cases/case15_netmiko_tools/vlans.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
vlan 100
name red100
vlan 101
name red101
vlan 102
name red102
62 changes: 62 additions & 0 deletions examples/use_cases/case16_concurrency/my_devices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from getpass import getpass

std_pwd = getpass("Enter standard password: ")

pynet_rtr1 = {
'device_type': 'cisco_ios',
'ip': '184.105.247.70',
'username': 'pyclass',
'password': std_pwd,
}

pynet_rtr2 = {
'device_type': 'cisco_ios',
'ip': '184.105.247.71',
'username': 'pyclass',
'password': std_pwd,
}

pynet_sw1 = {
'device_type': 'arista_eos',
'ip': '184.105.247.72',
'username': 'pyclass',
'password': std_pwd,
}

pynet_sw2 = {
'device_type': 'arista_eos',
'ip': '184.105.247.73',
'username': 'pyclass',
'password': std_pwd,
}

pynet_sw3 = {
'device_type': 'arista_eos',
'ip': '184.105.247.74',
'username': 'pyclass',
'password': std_pwd,
}

pynet_sw4 = {
'device_type': 'arista_eos',
'ip': '184.105.247.75',
'username': 'pyclass',
'password': std_pwd,
}

juniper_srx = {
'device_type': 'juniper_junos',
'ip': '184.105.247.76',
'username': 'pyclass',
'password': std_pwd,
}

device_list = [
pynet_rtr1,
pynet_rtr2,
pynet_sw1,
pynet_sw2,
pynet_sw3,
pynet_sw4,
juniper_srx,
]
Loading

0 comments on commit 0a9457d

Please sign in to comment.