Book Image

Python Network Programming Techniques

By : Marcel Neidinger
Book Image

Python Network Programming Techniques

By: Marcel Neidinger

Overview of this book

Network 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.
Table of Contents (14 chapters)

What this book covers

Chapter 1, A Primer to Python 3, covers the basic concepts of Python used throughout this book. We will cover variables, loops, basic data structures, and flow control as well as concepts such as functions that help make scripts more readable.

Chapter 2, Connecting to Network Devices via SSH Using Paramiko, covers how to establish an SSH connection to our network device using Python and the paramiko package. We will then use this established connection to issue simple commands and read basic output back from the devices.

Chapter 3, Building Configuration Templates Using Jinja2, teaches you how to create templates for configuration files that can be filled with data provided by the Python script using Python and jinja2, a widely used templating language. Using loops, control structures, and inheritance within jinja2 templates, we will build highly customizable configuration templates.

Chapter 4, Configuring Network Devices Using Netmiko, looks at netmiko, which is built on top of paramiko. The netmiko package provides abstraction around SSH interactions with network devices of multiple vendors. Using netmiko, we will interact with the network device to retrieve status information and apply configuration changes.

"Chapter 5: Model-Driven Programmability with NETCONF and ncclient" on page xviii, Model-Driven Programmability with NETCONF and ncclient, covers how model-driven programmability allows the user to specify the desired state of a networking infrastructure using a module that then gets applied to the device. We will use the ncclient package to change networking devices based on their YANG models.

Chapter 6, Automating Complex Multi-Vendor Networks with NAPALM, looks at NAPALM, which allows developers to automate complex multi-vendor networks using a unified interface. In this chapter, we will see examples of how to automate the configuration of devices from different vendors and validate these deployments.

Chapter 7, Automating Your Network Tests and Deployments with pyATS and Genie, looks at how automated network tests allow you to verify the success of your change quicker and find potential errors introduced by your change more easily. In this chapter, we will use pyATS and Genie to go from simple connectivity tests to advanced state tests for a variety of devices.

Chapter 8, Configuring Devices Using RESTCONF and requests, revisits model-driven programmability by using RESTCONF, a protocol that exposes a subset of NETCONF commands via HTTP(S). We will explore the requests package to send different RESTCONF JSON payloads to network devices.

Chapter 9, Consuming Controllers and High-Level Networking APIs with requests, discusses how most modern network controllers provide a REST API to make interaction with the underlying network infrastructure more uniform and easy to consume. In this chapter, we will learn how to query REST APIs using the requests package to retrieve information from and apply changes to multiple network devices.

Chapter 10, Incorporating Your Python Scripts into an Existing Workflow by Writing Custom Ansible Modules, covers Ansible, which is one of the most common tools for the automation of IT systems in the world. Its power comes from the variety of modules that provide functionality, and in this chapter, you'll learn how to write such a module yourself. This will allow you to call your Python scripts written in previous chapters from Ansible.

Chapter 11, Automating AWS Cloud Networking Infrastructure Using the AWS Python SDK, looks at Amazon Web Services (AWS), which is one of the biggest cloud providers in the world. In this chapter, we will use the AWS API and its Python library boto3 to administer our cloud network.

Chapter 12, Automating Your Network Security Using Python and Firepower APIs, discusses how security is one of the biggest concerns in modern network engineering. In this chapter, we will have a look at how to automate our network security using the APIs available in Cisco's Firepower products and the requests module.