Table of contents : Cover Copyright Contributors Table of Contents Preface Chapter 1: Review of TCP/IP Protocol Suite and Python An overview of the Internet Servers, hosts, and network components The rise of data centers Enterprise data centers Cloud data centers Edge data centers The OSI model The client-server model Network protocol suites The transmission control protocol Functions and characteristics of TCP TCP messages and data transfer The user datagram protocol The Internet protocol IP network address translation (NAT) and network security IP routing concepts Python language overview Python versions Operating system Running a Python program Python built-in types The None type Numerics Sequences Mapping Sets Python operators Python control flow tools Python functions Python classes Python modules and packages Summary Chapter 2: Low-Level Network Device Interactions The challenges of the CLI Constructing a Virtual lab Physical devices Virtual devices Cisco modeling labs CML tips Cisco DevNet GNS3 and others Python virtual environment Python pexpect library Pexpect installation Pexpect overview Our first Pexpect program More Pexpect Features Pexpect and SSH Pexpect complete example The Python Paramiko library Installation of Paramiko Paramiko overview First Paramiko program More Paramiko features Paramiko for servers More Paramiko examples The Netmiko library The Nornir framework Downsides of Pexpect and Paramiko compared to other tools Idempotent network device interaction Bad automation speeds up bad things Summary Chapter 3: APIs and Intent-Driven Networking Infrastructure-as-Code (IaC) Intent-driven networking Screen scraping versus API structured output Data modeling for IaC YANG and NETCONF Cisco API examples Cisco NX-API Lab preparation NX-API examples The Cisco YANG Model The Cisco ACI examples Cisco Meraki controller The Python API for Juniper Networks Juniper and NETCONF Device preparation Juniper NETCONF examples Juniper PyEZ for developers Installation and preparation PyEZ examples The Arista Python API Arista eAPI management eAPI preparation eAPI examples The Arista Pyeapi library Pyeapi installation Pyeapi examples VyOS example Other libraries Summary Chapter 4: The Python Automation Framework – Ansible Ansible – A More Declarative Framework Ansible Versions Our First Ansible Network Example The Control Node Installation Lab Topology The Variable Files Our First Playbook The Advantages of Ansible Agentless Idempotence Simple and Extensible Ansible Content Collections More Ansible Network Examples Inventory Nesting Ansible Conditionals Configuration Change Ansible Network Facts Ansible Loops Standard Loops Looping over Dictionaries Templates The Jinja Template Variables Jinja Template Loops Jinja Template Conditional Summary Chapter 5: Docker Containers for Network Engineers Docker Overview Advantages of Docker Building Python applications in Docker Installing Docker Useful Docker commands Building hello world Building our application Sharing Docker images Container orchestration with Docker-compose Container networking Container host network Custom bridge network Other container network options Containers in the network engineering field Containerlab Docker and Kubernetes Summary Chapter 6: Network Security with Python The Lab Setup Python Scapy Installing Scapy Interactive examples Packet captures with Scapy The TCP port scan The ping collection Common attacks Scapy resources Access lists Implementing access lists with Ansible MAC access lists The Syslog search Searching with the regular expression module Other tools Private VLANs UFW with Python Further reading Summary Chapter 7: Network Monitoring with Python – Part 1 Lab Setup SNMP Setup PySNMP Python for Data Visualization Matplotlib Installation Matplotlib – the first example Matplotlib for SNMP results Additional Matplotlib resources Pygal Installation Pygal – the first example Pygal for SNMP results Additional Pygal resources Python for Cacti Installation Python script as an input source Summary Chapter 8: Network Monitoring with Python – Part 2 Graphviz Lab setup Installation Graphviz examples Python with Graphviz examples LLDP neighbor graphing Information retrieval Python parser script Testing the playbook Flow-based monitoring NetFlow parsing with Python Python Socket and Struct ntop traffic monitoring Python extension for ntop sFlow SFlowtool and sFlow-RT with Python Summary Chapter 9: Building Network Web Services with Python Comparing Python web frameworks Flask and lab setup Introduction to Flask Flask versions Flask examples The HTTPie client URL routing URL variables URL generation The jsonify return Network resource API Flask-SQLAlchemy The network content API The devices API The device ID API Network dynamic operations Asynchronous operations Authentication and Authorization Running Flask in containers Summary Chapter 10: Introduction to Async IO Asynchronous operations overview Python multiprocessing Python multithreading Python asyncio module The Scrapli project Scrapli example Scrapli async example Summary Chapter 11: AWS Cloud Networking AWS setup The AWS CLI and Python SDK AWS network overview Virtual Private Cloud Route tables and route targets Automation with CloudFormation Security Groups and Network ACLs Elastic IP NAT gateways Direct Connect and VPN VPN gateways Direct Connect Network scaling services Elastic Load Balancing Route 53 DNS service CloudFront CDN services Other AWS network services Summary Chapter 12: Azure Cloud Networking Azure and AWS network service comparison Azure setup Azure administration and APIs Azure service principals Python versus PowerShell Azure global infrastructure Azure virtual networks Internet access Network resource creation VNet service endpoints VNet peering VNet routing Network security groups Azure VPNs Azure ExpressRoute Azure network load balancers Other Azure network services Summary Chapter 13: Network Data Analysis with Elastic Stack What is the Elastic Stack? Lab topology Elastic Stack as a service First End-to-End example Elasticsearch with a Python client Data ingestion with Logstash Data ingestion with Beats Search with Elasticsearch Data visualization with Kibana Summary Chapter 14: Working with Git Content management considerations and Git Introduction to Git Benefits of Git Git Terminology Git and GitHub Setting up Git Gitignore Git Usage Examples Git Branch GitHub Example Collaborating with Pull Requests Git with Python GitPython PyGitHub Automating Configuration Backup Collaborating with Git Summary Chapter 15: Continuous Integration with GitLab The traditional change management process Introduction to continuous integration Installing GitLab GitLab runners First GitLab example GitLab network example Summary Chapter 16: Test-Driven Development for Networks Test-driven development overview Test definitions Topology as code XML parsing example Python’s unittest module More on Python testing pytest examples Writing tests for networking Testing for reachability Testing for network latency Testing for security Testing for transactions Testing for network configuration Testing for Ansible pyATS and Genie Summary Other Books You May Enjoy Index