SlideShare uma empresa Scribd logo
1 de 30
Baixar para ler offline
Python
For the Network Nerd
By Matt Bynum, A Network Nerd
About Me
● In IT for a total of 14 years
● Doing Networking and VoIP for 13 of those
● Consulting for 8 years
● Leading a consulting practice for 2 years
● Programming in Python for 3 Months
Disclaimer: I am not a Python expert.
APIs
SDN
Automation
Open Source
Python Basics
Working through SSH
Importing Devices from CSV
Building Config Templates
What to do Next
Python Basics
● Variables are references to objects.
● Objects can be built-in like strings, or “things” that can
be manipulated or passed around.
● Lists contain objects.
● Dictionaries are containers that use key:value pairing to
store objects, and coincidentally, are also objects
themselves.
● Libraries are Python packages that can be used over
and over
Python Fundies
● myVar = “this is a string”
● WAN01 = Router()
● [WAN01, WAN02, CORE01, CORE02]
● {‘ip’: ‘10.0.0.1’, ‘username’: ‘cisco’, ‘password’: ‘cisco’}
● import csv
Python Fundies (cont.)
What version of Python?
Stick with Python 2 for now.
Recommended Python Tutorials
Codecademy.com
Udacity.com
LearnPythonTheHardWay.org
edX.org Intro to CompSci
Working through SSH
“But why not Telnet, Mr. Presenter?”
Netmiko
● Based on Paramiko
● Created by Kirk Byers, a CCIE R/S Emeritus
● Found on GitHub: https://github.
com/ktbyers/netmiko
● Designed for Network Devices
Netmiko - Setup
import netmiko
device = {'ip': '192.168.0.1', 'username': 'admin', 'password': 'password123', 'secret':
'secret123', 'verbose': False}
SSHClass = netmiko.ssh_dispatcher(device_type="cisco_ios")
net_connect = SSHClass(**device)
Netmiko - Commands
# Single Command
output = net_connect.send_command(“show run | i snmp”)
print output
# Multiple Commands
commands = [“show ip int brief | e unass”, “show ip route”, “show cdp neighbors”]
for command in commands:
output += net_connect.send_command(command)
print output
Netmiko - Configs
config = [“interface gig 0/0/1”, “description Uplink to Core”, “switchport mode trunk”]
net_connect.send_config_set(config)
Netmiko - Multi-device
yourDevices = [{'ip': '192.168.0.1', 'username': 'admin', 'password': 'password123',
'secret': 'secret123', 'verbose': False},{'ip': '192.168.0.2', 'username': 'admin',
'password': 'password123', 'secret': 'secret123', 'verbose': False}]
SSHClass = netmiko.ssh_dispatcher(device_type="cisco_ios")
net_connect = SSHClass(**yourDevice)
Netmiko - Multi-device cont.
commands = [“show ip int brief | e unass”, “show ip route”, “show cdp neighbors”]
for each in yourDevices:
net_connect = SSHClass(**each)
output = ''
for command in commands:
output += net_connect.send_command(command)
print output
Importing Devices from CSV
Comma Separated Values
import csv
devices = []
devicesDict = {}
with open(“c:routers.csv”) as devicesFile:
devicesDict = csv.DictReader(devicesFile, dialect='excel')
for row in devicesDict:
devices.append(row)
CSV Input
CSV Output
[{'username': 'mbyn', 'verbose': 'True', 'ip': '172.20.5.14', 'hostname':
'TEST_DEVICE_1', 'secret': '', 'password': 'fakepw'},
{'username': 'mbyn', 'verbose': 'True', 'ip': '172.20.5.15', 'hostname':
'TEST_DEVICE_2', 'secret': '', 'password': 'fakepw'},
...]
Building Config Templates
Jinja2 Templates
{% if interface %}
int {{ interface }}
{% endif %}
{% if description %}
description Uplink from {{ hostname }} to {{ description }}
{% endif %}
Python Jinja2
import jinja2
device = {'hostname': 'DIST01', 'ip': '192.168.0.2', 'username': 'admin', 'password':
'password123', 'secret': 'secret123', 'verbose': False, 'interface': 'gig 0/0/1',
'description': 'CORE SWITCH 1'}
env = jinja2.Environment(loader=jinja2.FileSystemLoader('templates'),trim_blocks=True)
commands = env.get_template(“template.cfg”).render(device)
Rendered Configuration
int gig 0/0/1
description Uplink from DIST01 to CORE SWITCH 1
What to do Next
“The future belongs to those who see possibilities before they become obvious.”
- John Sculley
Things to work on
● Scripting VLAN Moves/Adds/Changes, QoS
deployments, any other bulk changes
● Configuration Auditing
● APIs
● SNMP collection and graphing
● Using YAML and JSON for templating config
elements
Where your job is heading
DevOps
SDN
Automation and Orchestration
The End

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Kong
KongKong
Kong
 
NGINX: Basics and Best Practices
NGINX: Basics and Best PracticesNGINX: Basics and Best Practices
NGINX: Basics and Best Practices
 
OpenID Connect Explained
OpenID Connect ExplainedOpenID Connect Explained
OpenID Connect Explained
 
Kubernetes internals (Kubernetes 해부하기)
Kubernetes internals (Kubernetes 해부하기)Kubernetes internals (Kubernetes 해부하기)
Kubernetes internals (Kubernetes 해부하기)
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
Intro to WebSockets
Intro to WebSocketsIntro to WebSockets
Intro to WebSockets
 
Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...
Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...
Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...
 
OpenStack Networking
OpenStack NetworkingOpenStack Networking
OpenStack Networking
 
Deep dive into Kubernetes Networking
Deep dive into Kubernetes NetworkingDeep dive into Kubernetes Networking
Deep dive into Kubernetes Networking
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple Steps
 
An overview of the Kubernetes architecture
An overview of the Kubernetes architectureAn overview of the Kubernetes architecture
An overview of the Kubernetes architecture
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Engine
 
Go Book - Fonksiyonlar, Metotlar, Arayüzler ve Yapılar
Go Book - Fonksiyonlar, Metotlar, Arayüzler ve YapılarGo Book - Fonksiyonlar, Metotlar, Arayüzler ve Yapılar
Go Book - Fonksiyonlar, Metotlar, Arayüzler ve Yapılar
 
HTTP request and response
HTTP request and responseHTTP request and response
HTTP request and response
 
[오픈소스컨설팅] Open Stack Ceph, Neutron, HA, Multi-Region
[오픈소스컨설팅] Open Stack Ceph, Neutron, HA, Multi-Region[오픈소스컨설팅] Open Stack Ceph, Neutron, HA, Multi-Region
[오픈소스컨설팅] Open Stack Ceph, Neutron, HA, Multi-Region
 
Basics of HTTP - Nafis Fuad
Basics of HTTP - Nafis FuadBasics of HTTP - Nafis Fuad
Basics of HTTP - Nafis Fuad
 

Destaque

Network programming in python..
Network programming in python..Network programming in python..
Network programming in python..
Bharath Kumar
 
Feb 2009 Certification
Feb 2009 CertificationFeb 2009 Certification
Feb 2009 Certification
Matt Bynum
 
Linux fundamentals
Linux fundamentalsLinux fundamentals
Linux fundamentals
Raghu nath
 
F5 BIG-IP Web-based Customer Training
F5 BIG-IP Web-based Customer TrainingF5 BIG-IP Web-based Customer Training
F5 BIG-IP Web-based Customer Training
F5 Networks
 
F5 - BigIP ASM introduction
F5 - BigIP ASM introductionF5 - BigIP ASM introduction
F5 - BigIP ASM introduction
Jimmy Saigon
 

Destaque (20)

Python (Jinja2) Templates for Network Automation
Python (Jinja2) Templates for Network AutomationPython (Jinja2) Templates for Network Automation
Python (Jinja2) Templates for Network Automation
 
A Network Engineer's Approach to Automation
A Network Engineer's Approach to AutomationA Network Engineer's Approach to Automation
A Network Engineer's Approach to Automation
 
Network programming in python..
Network programming in python..Network programming in python..
Network programming in python..
 
LinuxCon North America: SIPPing from the Open Source Well
LinuxCon North America: SIPPing from the Open Source WellLinuxCon North America: SIPPing from the Open Source Well
LinuxCon North America: SIPPing from the Open Source Well
 
Demystifying Software Defined Networking (SDN)
Demystifying Software Defined Networking (SDN)Demystifying Software Defined Networking (SDN)
Demystifying Software Defined Networking (SDN)
 
Feb 2009 Certification
Feb 2009 CertificationFeb 2009 Certification
Feb 2009 Certification
 
04 - I love my OS, he protects me (sometimes, in specific circumstances)
04 - I love my OS, he protects me (sometimes, in specific circumstances)04 - I love my OS, he protects me (sometimes, in specific circumstances)
04 - I love my OS, he protects me (sometimes, in specific circumstances)
 
Let's read code: python-requests library
Let's read code: python-requests libraryLet's read code: python-requests library
Let's read code: python-requests library
 
VMware Horizon with F5 BIG-IP vs. Citrix XenDesktop with Citrix NetScaler
VMware Horizon with F5 BIG-IP vs. Citrix XenDesktop with Citrix NetScalerVMware Horizon with F5 BIG-IP vs. Citrix XenDesktop with Citrix NetScaler
VMware Horizon with F5 BIG-IP vs. Citrix XenDesktop with Citrix NetScaler
 
The Rules of Network Automation - Interop/NYC 2014
The Rules of Network Automation - Interop/NYC 2014The Rules of Network Automation - Interop/NYC 2014
The Rules of Network Automation - Interop/NYC 2014
 
Network Automation - Interconnection tools
Network Automation - Interconnection toolsNetwork Automation - Interconnection tools
Network Automation - Interconnection tools
 
F5 Offers Advanced Web Security With BIG-IP v10.1
F5 Offers Advanced Web Security With BIG-IP v10.1F5 Offers Advanced Web Security With BIG-IP v10.1
F5 Offers Advanced Web Security With BIG-IP v10.1
 
Linux fundamentals
Linux fundamentalsLinux fundamentals
Linux fundamentals
 
Linux fundamentals Training
Linux fundamentals TrainingLinux fundamentals Training
Linux fundamentals Training
 
F5 Networks: architecture and risk management
F5 Networks: architecture and risk managementF5 Networks: architecture and risk management
F5 Networks: architecture and risk management
 
F5 BIG-IP Web-based Customer Training
F5 BIG-IP Web-based Customer TrainingF5 BIG-IP Web-based Customer Training
F5 BIG-IP Web-based Customer Training
 
Configuration F5 BIG IP ASM v12
Configuration F5 BIG IP ASM v12Configuration F5 BIG IP ASM v12
Configuration F5 BIG IP ASM v12
 
BGP Overview
BGP OverviewBGP Overview
BGP Overview
 
F5 Networks: Introduction to Silverline WAF (web application firewall)
F5 Networks: Introduction to Silverline WAF (web application firewall)F5 Networks: Introduction to Silverline WAF (web application firewall)
F5 Networks: Introduction to Silverline WAF (web application firewall)
 
F5 - BigIP ASM introduction
F5 - BigIP ASM introductionF5 - BigIP ASM introduction
F5 - BigIP ASM introduction
 

Semelhante a Python for the Network Nerd

Cracking Into Embedded Devices - HACK.LU 2K8
Cracking Into Embedded Devices - HACK.LU 2K8Cracking Into Embedded Devices - HACK.LU 2K8
Cracking Into Embedded Devices - HACK.LU 2K8
guest441c58b71
 
Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2
Alessandro Molina
 
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPFA Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
oholiab
 

Semelhante a Python for the Network Nerd (20)

Getting started with RDO Havana
Getting started with RDO HavanaGetting started with RDO Havana
Getting started with RDO Havana
 
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
 
Harmonia open iris_basic_v0.1
Harmonia open iris_basic_v0.1Harmonia open iris_basic_v0.1
Harmonia open iris_basic_v0.1
 
Red Hat Forum Tokyo - OpenStack Architecture
Red Hat Forum Tokyo - OpenStack ArchitectureRed Hat Forum Tokyo - OpenStack Architecture
Red Hat Forum Tokyo - OpenStack Architecture
 
Automation intro
Automation introAutomation intro
Automation intro
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
Cracking Into Embedded Devices - HACK.LU 2K8
Cracking Into Embedded Devices - HACK.LU 2K8Cracking Into Embedded Devices - HACK.LU 2K8
Cracking Into Embedded Devices - HACK.LU 2K8
 
The internet of $h1t
The internet of $h1tThe internet of $h1t
The internet of $h1t
 
Python Network Programming – Course Applications Guide
Python Network Programming – Course Applications GuidePython Network Programming – Course Applications Guide
Python Network Programming – Course Applications Guide
 
SDNDS.TW Mininet
SDNDS.TW MininetSDNDS.TW Mininet
SDNDS.TW Mininet
 
Pycon - Python for ethical hackers
Pycon - Python for ethical hackers Pycon - Python for ethical hackers
Pycon - Python for ethical hackers
 
Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2
 
Build reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQBuild reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQ
 
Banog meetup August 30th, network device property as code
Banog meetup August 30th, network device property as codeBanog meetup August 30th, network device property as code
Banog meetup August 30th, network device property as code
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
A.java
A.javaA.java
A.java
 
mininet-intro.pdf
mininet-intro.pdfmininet-intro.pdf
mininet-intro.pdf
 
Ake hedman why we need to unite and why vscp is a solution to a problem
Ake hedman  why we need to unite and why vscp is a solution to a problemAke hedman  why we need to unite and why vscp is a solution to a problem
Ake hedman why we need to unite and why vscp is a solution to a problem
 
Iot with-the-best & VSCP
Iot with-the-best & VSCPIot with-the-best & VSCP
Iot with-the-best & VSCP
 
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPFA Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
 

Mais de Matt Bynum (6)

Demystifying Software Defined Networking (SDN)
Demystifying Software Defined Networking (SDN)Demystifying Software Defined Networking (SDN)
Demystifying Software Defined Networking (SDN)
 
NCUG - Current State Of Cisco UC
NCUG - Current State Of Cisco UCNCUG - Current State Of Cisco UC
NCUG - Current State Of Cisco UC
 
Session Initiation Protocol
Session Initiation ProtocolSession Initiation Protocol
Session Initiation Protocol
 
healthcamp:nash - Unified Communications in Healthcare
healthcamp:nash -  Unified Communications in Healthcarehealthcamp:nash -  Unified Communications in Healthcare
healthcamp:nash - Unified Communications in Healthcare
 
Social Networking 101
Social Networking 101Social Networking 101
Social Networking 101
 
IPv6 Fundamentals
IPv6 FundamentalsIPv6 Fundamentals
IPv6 Fundamentals
 

Último

Último (20)

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Python for the Network Nerd

  • 1. Python For the Network Nerd By Matt Bynum, A Network Nerd
  • 2. About Me ● In IT for a total of 14 years ● Doing Networking and VoIP for 13 of those ● Consulting for 8 years ● Leading a consulting practice for 2 years ● Programming in Python for 3 Months Disclaimer: I am not a Python expert.
  • 4.
  • 5. Python Basics Working through SSH Importing Devices from CSV Building Config Templates What to do Next
  • 7. ● Variables are references to objects. ● Objects can be built-in like strings, or “things” that can be manipulated or passed around. ● Lists contain objects. ● Dictionaries are containers that use key:value pairing to store objects, and coincidentally, are also objects themselves. ● Libraries are Python packages that can be used over and over Python Fundies
  • 8. ● myVar = “this is a string” ● WAN01 = Router() ● [WAN01, WAN02, CORE01, CORE02] ● {‘ip’: ‘10.0.0.1’, ‘username’: ‘cisco’, ‘password’: ‘cisco’} ● import csv Python Fundies (cont.)
  • 9. What version of Python? Stick with Python 2 for now.
  • 12. “But why not Telnet, Mr. Presenter?”
  • 13. Netmiko ● Based on Paramiko ● Created by Kirk Byers, a CCIE R/S Emeritus ● Found on GitHub: https://github. com/ktbyers/netmiko ● Designed for Network Devices
  • 14. Netmiko - Setup import netmiko device = {'ip': '192.168.0.1', 'username': 'admin', 'password': 'password123', 'secret': 'secret123', 'verbose': False} SSHClass = netmiko.ssh_dispatcher(device_type="cisco_ios") net_connect = SSHClass(**device)
  • 15. Netmiko - Commands # Single Command output = net_connect.send_command(“show run | i snmp”) print output # Multiple Commands commands = [“show ip int brief | e unass”, “show ip route”, “show cdp neighbors”] for command in commands: output += net_connect.send_command(command) print output
  • 16. Netmiko - Configs config = [“interface gig 0/0/1”, “description Uplink to Core”, “switchport mode trunk”] net_connect.send_config_set(config)
  • 17. Netmiko - Multi-device yourDevices = [{'ip': '192.168.0.1', 'username': 'admin', 'password': 'password123', 'secret': 'secret123', 'verbose': False},{'ip': '192.168.0.2', 'username': 'admin', 'password': 'password123', 'secret': 'secret123', 'verbose': False}] SSHClass = netmiko.ssh_dispatcher(device_type="cisco_ios") net_connect = SSHClass(**yourDevice)
  • 18. Netmiko - Multi-device cont. commands = [“show ip int brief | e unass”, “show ip route”, “show cdp neighbors”] for each in yourDevices: net_connect = SSHClass(**each) output = '' for command in commands: output += net_connect.send_command(command) print output
  • 20. Comma Separated Values import csv devices = [] devicesDict = {} with open(“c:routers.csv”) as devicesFile: devicesDict = csv.DictReader(devicesFile, dialect='excel') for row in devicesDict: devices.append(row)
  • 22. CSV Output [{'username': 'mbyn', 'verbose': 'True', 'ip': '172.20.5.14', 'hostname': 'TEST_DEVICE_1', 'secret': '', 'password': 'fakepw'}, {'username': 'mbyn', 'verbose': 'True', 'ip': '172.20.5.15', 'hostname': 'TEST_DEVICE_2', 'secret': '', 'password': 'fakepw'}, ...]
  • 24. Jinja2 Templates {% if interface %} int {{ interface }} {% endif %} {% if description %} description Uplink from {{ hostname }} to {{ description }} {% endif %}
  • 25. Python Jinja2 import jinja2 device = {'hostname': 'DIST01', 'ip': '192.168.0.2', 'username': 'admin', 'password': 'password123', 'secret': 'secret123', 'verbose': False, 'interface': 'gig 0/0/1', 'description': 'CORE SWITCH 1'} env = jinja2.Environment(loader=jinja2.FileSystemLoader('templates'),trim_blocks=True) commands = env.get_template(“template.cfg”).render(device)
  • 26. Rendered Configuration int gig 0/0/1 description Uplink from DIST01 to CORE SWITCH 1
  • 27. What to do Next “The future belongs to those who see possibilities before they become obvious.” - John Sculley
  • 28. Things to work on ● Scripting VLAN Moves/Adds/Changes, QoS deployments, any other bulk changes ● Configuration Auditing ● APIs ● SNMP collection and graphing ● Using YAML and JSON for templating config elements
  • 29. Where your job is heading DevOps SDN Automation and Orchestration