Python and Jinja2 Cisco Network Automation

  Рет қаралды 32,341

David Bombal

David Bombal

Күн бұрын

CSV files, Jinja2 templates, python and Network Automation! Wow - that is a lot! But Hank Preston demonstrates how to use all of those in this video. Source code here: bit.ly/2MyRDLR
Menu:
00:00 - Introduction
02:29 - Spreadsheet conversion
04:19 - Importing using Python
13:41 - What are the advantages of using Jinja2 templates?
16:35 - Skills that Network Engineers should learn?
19:00 - The working template
32:09 - Exporting to a text file
35:22 - Using a script
37:46 - How would I turn this into something that configures a device?
51:18 - Should I use CSV/YAML/JSON?
Links:
Video 1 in series: • Network Engineers are ...
Video 2 in series: • Python, Genie and CSV ...
Start Now Page on Devnet: bit.ly/2WBjb5v
NetDevOps Live Episode on Python Libraries including CSV: bit.ly/2VjbGP4
Coding Fundamentals Learning Labs: bit.ly/2vU1BO8
Network programmability Basics Video Series covering CSV: bit.ly/2JzlbY4
Jinja2 template video: • Embrace the DRY Princi...
#python #jinja2 #devnet

Пікірлер: 52
@eltreum1
@eltreum1 4 жыл бұрын
I work in telco service provider land and we manage literally a few million devices internally or for customers as a managed service. This is about how we do it but in large scale. The template process we made is in 2 phases to first assemble a complete device template file out of sub-template modules that models a specific piece of equipment or config package we want to deploy from an internal catalog. Next it populates that file with the specific fill in the blank data from whatever data source we want. We have an API service for template generation. I have used netmiko and CSV for small jobs all the time like this and is a great thing for an engineer to learn. Template engines like jinja or a YAML model used in a python app is best for assembling boiler-plate modules but let something else do the fill in the blank stuff. Pythons built-in string replace method is implemented in C in the background and lightning fast already. We have modules for everything we use; DHCP, ACLs, NAT, routing protocols and maps, QOS maps, SMNP, AAA, VPN, EEM or TCL scripts etc. We have used a few template systems over the years and let me caution about jinja and template engine use in general from my experience. You want as little template engine logic mixed in with your device config stuff as possible so it's more readable by other network engineers who are not programmers and lets them contribute modules to the library easier. Your templates also become coupled to that engine so change is hard later. It's a programmers best practice to separate business data from business logic as much as possible. In their example we do not use logic for trunk or access mode anymore in the interface module templates because it can vary by manufacturer, OS series, or firmware so we need a few versions anyway. We pull in the right access version, trunk version, or sub interface version of a template module as needed. Instead of a CSV our equipment inventory database has all the device specific IP data and options our generator program consumes via a fancy DB query. The database field names that get returned in the JSON reply match the template module variable names so string find/replace to fill in the blanks is trivial and tiny intuitive code to read/maintain. We can add new variables without changing code except the DB query which is in a isolated module by itself the program imports. We just add a new DB field name and referencing them in the template modules as variables. As long as they match it just works. Passwords, license keys, and security certificates should be variables called from a separate true-crypt like database when it renders the template. Do not leave those things lying around in plain text template modules. Whatever method you want to use put all your template modules, YAMLs, and program code in an internal GIT server so you have revision control and it facilitates secure collaboration. Our template system pulls all the module pieces out of git on demand and uses databases to fill in the blanks when we want to render a template. We maintain the central repository and every template is rendered in the latest version by default. We can use those to audit/update the network with worker scripts but that is another novel to explain lol.
@davidbombal
@davidbombal 4 жыл бұрын
Code here: bit.ly/2MyRDLR Menu: 00:00 - Introduction 02:29 - Spreadsheet conversion 04:19 - Importing using Python 13:41 - What are the advantages of using Jinja2 templates? 16:35 - Skills that Network Engineers should learn? 19:00 - The working template 32:09 - Exporting to a text file 35:22 - Using a script 37:46 - How would I turn this into something that configures a device? 51:18 - Should I use CSV/YAML/JSON? Links: Video 1 in series: kzfaq.info/get/bejne/hqhpd5eD1qjFgas.html Video 2 in series: kzfaq.info/get/bejne/aJmYg8ppnda-cqM.html Start Now Page on Devnet: bit.ly/2WBjb5v NetDevOps Live Episode on Python Libraries including CSV: bit.ly/2VjbGP4 Coding Fundamentals Learning Labs: bit.ly/2vU1BO8 Network programmability Basics Video Series covering CSV: bit.ly/2JzlbY4 Jinja2 template video: kzfaq.info/get/bejne/d7h2iJpk2cfMaHU.html
@NathanWind99
@NathanWind99 2 жыл бұрын
This is the best, no nonsense tutorial on this stuff that I’ve seen. Well done gentlemen!
@amphaeon5246
@amphaeon5246 3 жыл бұрын
This was one of the best tutorials I've ever seen for network admins with little programming experience. Glad to have found this channel! 10/10
@davidbombal
@davidbombal 3 жыл бұрын
Glad you liked it!
@ericdavid890
@ericdavid890 4 жыл бұрын
Hank & David this is an awesome video thanks for putting this together! I'm going through the Jinja2 templating doc but the method to adapt for IOS configs hadn't clicked just yet. This helps alot! Thanks again keep up the great work
@christostz03
@christostz03 Жыл бұрын
Hank & David, David & Hank, an awesome network - automation - couple !!! Thank you guys !!!
@ajaycnt
@ajaycnt 3 жыл бұрын
Thank you very much! This is a very useful and detailed tutorial for network professionals looking for automation!
@otonielricardo
@otonielricardo 4 жыл бұрын
This is priceless information, thank you for sharing!
@MariaSanchez-lb4kp
@MariaSanchez-lb4kp 4 жыл бұрын
Awesome! Thanks for sharing! This will definitely help me with Network Automation. Thanks guys!
@henrys5520
@henrys5520 4 жыл бұрын
Thanks for the video Bombal and Hank! Idea for next video: use cases for network automation? Or what other network engineers are doing to start automating?
@jackmorris3279
@jackmorris3279 4 жыл бұрын
Amazing work! Great video Hank and David
@davidbombal
@davidbombal 4 жыл бұрын
Glad you enjoyed it!
@naveenjkumar9684
@naveenjkumar9684 4 жыл бұрын
Thumbs up David and Preston for this support 😃
@davidbombal
@davidbombal 4 жыл бұрын
Thank you
@zilhazrahman3280
@zilhazrahman3280 4 жыл бұрын
This is really cool. Thank you for sharing!!
@riccardoandreetta9520
@riccardoandreetta9520 3 жыл бұрын
Very cool. You can also use spreadsheets to convert them into YAML files, to be further processed by Ansible or similar tools. Pretty much the same approach, in that case you can have the same stuff to configure not only routers but also firewalls, ACI data center, and so on. Good job anyway, very useful explanation. A 'device' column could be added in such a way that the same format could be used for all devices in the network.
@menukawijayarathne886
@menukawijayarathne886 3 жыл бұрын
Enjoyed this ,thanks hanks and david
@HankPreston
@HankPreston 4 жыл бұрын
Glad everyone is enjoying the video and series. You can find the code samples at github.com/hpreston/python_networking/tree/master/csv_config_gen
@ragayclark
@ragayclark 4 жыл бұрын
Thanks for all your videos david, you're one of the main reasons I am studying my CCNP R&S :D,
@mjgritli
@mjgritli 4 жыл бұрын
Thank you very much for such session
@tarunjha4421
@tarunjha4421 4 жыл бұрын
great video David.. thank you
@craigallan114
@craigallan114 4 жыл бұрын
Such a great video!
@rajeshreddyn3080
@rajeshreddyn3080 4 жыл бұрын
Thanks David .. really appreciate your efforts. Can you please make some video on pyang Vs YDK and deep dive on pyang..
@hansthepeter
@hansthepeter Жыл бұрын
came back today just for fun. This video series with hank got me started back then. Turned out i was already perfect skilled for upcoming job requierements! Same as Cybersecurity today. Thank you so much David! How do you archive always being ahead of the time?
@francis2k488
@francis2k488 4 жыл бұрын
Thanks for the video David. What's the prerequisite for this tutorial? Seems like good knowledge of Python is important.
@kiefffrc2386
@kiefffrc2386 4 жыл бұрын
what great info and well explained. Thanks for the video David and Hank, powerful stuff.
@davidbombal
@davidbombal 4 жыл бұрын
Thank you! Hank is amazing :)
@jhonvinod8988
@jhonvinod8988 4 жыл бұрын
Awesome video
@Houston123ABC
@Houston123ABC 3 жыл бұрын
This is so great
@MrLupoNino
@MrLupoNino Жыл бұрын
I would suggest to give some more instruction, how to create the .csv template file, you had in first column "Switch", and inside seem only one device is there sbx-n9kv-ao, but what about if we had a 2nd, 3rd switch, for example sw02, sw03...how to make the loop to generate separate config file for each of the switches? Also some more recommandation how to create the structure of inventory file (no matter in csv or yaml) could be helpful, where to include stuff like ospf, bgp, and how to connect with proper interfaces, neighbors etc. Anyway, thanks so much for you guys brining this session
@kewlguyjason
@kewlguyjason 4 жыл бұрын
I'm guessing the answer is "use jinja2 templates" but what if we had to do deeper into the prompt, such as*interface* or *config-bgp* *config-ospf*, is it still possible to configure with just netmiko? I guess we would just have to change what we expect back from the router as the expect value (so not #) or just put in send_config_timing?
@charfeddinealioui3507
@charfeddinealioui3507 4 жыл бұрын
thank you for sharing
@m.imraniqbaal6912
@m.imraniqbaal6912 Ай бұрын
Hi David, I came here to see if we can achieve Zero touch provisioning for Cisco Devices, like literally out of the box. Can you please recommend this piece if you've already made it. Thanks!
@lahcenkhweb1912
@lahcenkhweb1912 Жыл бұрын
great video ☻
@UlissesOliva
@UlissesOliva 4 жыл бұрын
Perfect!
@javiersegovia4420
@javiersegovia4420 3 жыл бұрын
I have a file with extension text, how conversion to spreadsheet? or how can read with python?
@luongtrongvinh9457
@luongtrongvinh9457 3 жыл бұрын
I have a quesiton? What OS and software does he use for simulating in the video? Hopefully you reply me.
@networkpips323
@networkpips323 3 жыл бұрын
Can u do a video on how to automate ios patch upgrade with Python
@seand8030
@seand8030 4 жыл бұрын
Whoa! 🤯
@madaraekouta8058
@madaraekouta8058 4 жыл бұрын
Bombal the Rock of the Network . we're wainting your ccnp enterprise or Service provider after febuary sir .please
@davidbombal
@davidbombal 4 жыл бұрын
Thank you. I will be working on CCNP :)
@ashishsolanki86
@ashishsolanki86 4 жыл бұрын
Hi David, I had scheduled Cisco 200-901 exam on 2nd of July 1845 IST however at the scheduled time I was not able to launch the exam and now it's been 5 days I'm chasing Pearson but not getting any response can you help me to reach out someone else who can help me..
@kenmurphy4259
@kenmurphy4259 4 жыл бұрын
Great review of Netmiko, Jinja2 and CSV. Is there a link to the code used in this example?
@davidbombal
@davidbombal 4 жыл бұрын
Here you go: bit.ly/2MyRDLR
@amitbeniwal1
@amitbeniwal1 4 жыл бұрын
Hi David the videos are a great content and it feels like I am being greedy but if you could upload the scripts used in the videos to github and share it would be great. Specially the ones used for restconf/netconf
@davidbombal
@davidbombal 4 жыл бұрын
Here you go: bit.ly/2MyRDLR
@omega1007
@omega1007 3 жыл бұрын
I loved Jinja2 until I tried to use a variable I had declared in a for loop. Why the hell would they limit the scope that much, limits Jinjas use cases so much by doing so. I was using Jinja to write 15000 line config files but can no longer as I'm unable to carry variables across multiple blocks.
@ahmedbadal3795
@ahmedbadal3795 4 жыл бұрын
thanks david always delivering wat is best for us ....but this new 200-301 ccna is scary to me ...cant we just become network developers with out the certificates us u know u programming is free ......
@davidbombal
@davidbombal 4 жыл бұрын
The new CCNA will only have a small portion focusing on Network Automation. The bulk of the cert is still focused on traditional networking. I don't think you have to worry.
@ahmedbadal3795
@ahmedbadal3795 4 жыл бұрын
@@davidbombal okey david thanks
@milangerloff5252
@milangerloff5252 3 жыл бұрын
Font is very small, i can bearly see
Real World AUTOMATION // Top skills, jobs, certs, laptops and more
1:00:34
Python, Genie and CSV Files = Easy Network Automation (DevNet)
51:33
Wait for the last one! 👀
00:28
Josh Horton
Рет қаралды 122 МЛН
The joker's house has been invaded by a pseudo-human#joker #shorts
00:39
Untitled Joker
Рет қаралды 14 МЛН
Parse Cisco IOS to JSON with Python and Netmiko
17:15
Data Knox
Рет қаралды 21 М.
Ansible Jinja2 Template Tutorial  Network Automation Cisco
18:56
Roger Perkin
Рет қаралды 49 М.
get started with Ansible Network Automation (FREE cisco router lab)
15:02
Python Network Automation Training changes today!
15:06
David Bombal
Рет қаралды 72 М.
Python Skills and Techniques for Network Engineers, Part 1
57:54
Cisco DevNet
Рет қаралды 54 М.
Fundamentals of Network Automation
1:29:59
Kevin Wallace Training, LLC
Рет қаралды 44 М.
Start Automating Your Life Using Python! (File Management with Python Tutorial)
13:07
How to reuse code blocks easily with Jinja2 macros!
7:55
teclado
Рет қаралды 19 М.
Ansible Network Automation
1:02:52
David Bombal
Рет қаралды 73 М.
Asus  VivoBook Винда за 8 часов!
1:00
Sergey Delaisy
Рет қаралды 1,2 МЛН
Хотела заскамить на Айфон!😱📱(@gertieinar)
0:21
Взрывная История
Рет қаралды 4,5 МЛН
iPhone 16 с инновационным аккумулятором
0:45
ÉЖИ АКСЁНОВ
Рет қаралды 519 М.
1$ vs 500$ ВИРТУАЛЬНАЯ РЕАЛЬНОСТЬ !
23:20
GoldenBurst
Рет қаралды 1,4 МЛН
Неразрушаемый смартфон
1:00
Status
Рет қаралды 2,1 МЛН