
- 340 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Python Network Programming Techniques
About this book
Become well-versed with network programmability by solving the most commonly encountered problems using Python 3 and open-source packagesKey Features• Explore different Python packages to automate your infrastructure• Leverage AWS APIs and the Python library Boto3 to administer your public cloud network efficiently• Get started with infrastructure automation by enhancing your network programming knowledgeBook DescriptionNetwork automation offers a powerful new way of changing your infrastructure network. Gone are the days of manually logging on to different devices to type the same configuration commands over and over again. With this book, you'll find out how you can automate your network infrastructure using Python.You'll get started on your network automation journey with a hands-on introduction to the network programming basics to complement your infrastructure knowledge. You'll learn how to tackle different aspects of network automation using Python programming and a variety of open source libraries. In the book, you'll learn everything from templating, testing, and deploying your configuration on a device-by-device basis to using high-level REST APIs to manage your cloud-based infrastructure. Finally, you'll see how to automate network security with Cisco's Firepower APIs.By the end of this Python network programming book, you'll have not only gained a holistic overview of the different methods to automate the configuration and maintenance of network devices, but also learned how to automate simple to complex networking tasks and overcome common network programming challenges.What you will learn• Programmatically connect to network devices using SSH (secure shell) to execute commands• Create complex configuration templates using Python• Manage multi-vendor or multi-device environments using network controller APIs or unified interfaces• Use model-driven programmability to retrieve and change device configurations• Discover how to automate post modification network infrastructure tests• Automate your network security using Python and Firepower APIsWho this book is forThis book is for network engineers who want to make the most of Python to automate their infrastructure. A basic understanding of Python programming and common networking principles is necessary.
Frequently asked questions
- Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
- Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Information
Chapter 1: A Primer on Python 3
- Assigning variables in Python
- Converting between data types in Python
- Looping over lists in Python
- Controlling the flow of a Python program using if statements
- Executing code until a condition is met using while loops
- Writing reusable code with functions
- Storing and accessing key-value pairs using dictionaries
- Importing modules from the standard library
- Installing modules from the Python Package Index (PyPI)
Technical requirements
Assigning variables in Python
Getting ready
How to do it…
- Define a variable called my_hostname and assign it the value of your name using the = operator:my_hostname = "router01"
- We can also use single quotes to assign a string. Note that you can't mix the different types of quotes: my_domain = 'example.com'
- Furthermore, we can use triple quotes to define a string that spans multiple lines:my_motd = """This is a string that willcontain linebreaks and could be the motd of arouter."""
- If we want to see the value of a variable, we can use Python's built-in print() function to display the value stored on the command line:print(my_hostname)print(my_domain)print(my_motd)
- Similar to strings, we can also assign numeric values. We can distinguish two types of variables: floats for floating-point numbers and integers for whole numbers. Define a variable called my_port to hold the default port number of a Secure Shell (SSH) server (as an integer/whole number) and a variable called my_throughput to hold your server's average number of requests per minute (as a float/floating-point number): my_port = 22my_throughput = 1.75
- We can print out the value of a variable of the type int or float, the same way we did with the string:print(my_port)print(my_throughput)
- Truth values in Python are represented by the two True and False Boolean values. We can define a variable called knows_python, assign it to either be true or false, and then print the value of said variable:knows_python = Trueknows_python = Falseprint(knows_python)
- Sometimes, we want to store lists (also referre...
Table of contents
- Python Network Programming Techniques
- Contributors
- Preface
- Chapter 1: A Primer on Python 3
- Chapter 2: Connecting to Network Devices via SSH Using Paramiko
- Chapter 3: Building Configuration Templates Using Jinja2
- Chapter 4: Configuring Network Devices Using Netmiko
- Chapter 5: Model-Driven Programmability with NETCONF and ncclient
- Chapter 6: Automating Complex Multi-Vendor Networks with NAPALM
- Chapter 7: Automating Your Network Tests and Deployments with pyATS and Genie
- Chapter 8: Configuring Devices Using RESTCONF and requests
- Chapter 9: Consuming Controllers and High-Level Networking APIs with requests
- Chapter 10: Incorporating your Python Scripts into an Existing Workflow by Writing Custom Ansible Modules
- Chapter 11: Automating AWS Cloud Networking Infrastructure Using the AWS Python SDK
- Chapter 12: Automating your Network Security Using Python and the Firepower APIs
- Other Books You May Enjoy