logo资料库

Mastering Python Networking 无水印pdf.pdf

第1页 / 共439页
第2页 / 共439页
第3页 / 共439页
第4页 / 共439页
第5页 / 共439页
第6页 / 共439页
第7页 / 共439页
第8页 / 共439页
资料共439页,剩余部分请下载后查看
Cover
Copyright
Foreword
About the Author
Table of Contents
Preface
1: Review of TCP/IP Protocol Suite and Python Language
The internet overview
Servers, hosts, and network components
The rise of datacenter
Enterprise datacenters
Cloud datacenters
Edge datacenters
The OSI model
Client server models
Network protocol suites
The Transmission Control Protocol (TCP)
Functions and Characteristics of TCP
TCP messages and data transfer
User Datagram Protocol (UDP)
The Internet Protocol (IP)
The IP NAT and 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
2: Low-Level Network Device Interactions
The challenges of CLI
Constructing a virtual lab
Cisco Virtual Internet Routing Lab (VIRL)
VIRL tips
Cisco DevNet and dCloud
GNS3
Python Pexpect Library
Installation
The Pexpect overview
Our first Expect program
More Pexpect features
Pexpect and SSH
Putting things together for Pexpect
The Python Paramiko library
Installating Paramiko
The Paramiko overview
Our first Paramiko program
More Paramiko features
Paramiko for Servers
Putting things together for Paramiko
Looking ahead
Downsides of Pexpect and Paramiko compared to other tools
Idempotent network device interaction
Bad automation speeds bad things up
Summary
3: API and Intent-Driven Networking
Infrastructure as the Python code
Screen scraping versus API structured output
Data modeling for infrastructure as code
The Cisco API and ACI
Cisco NX-API
Lab Software Installation and Device Preparation
NX-API examples
Cisco and YANG model
The Cisco ACI
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
The Arista eAPI management
The eAPI preparation
eAPI examples
The Arista Pyeapi library
The Pyeapi installation
Pyeapi examples
Vendor neutral libraries
Summary
4: The Python Automation Framework - Ansible Basics
A quick Ansible example
The control node installation
Your first Ansible playbook
The Public key authorization
The inventory file
Our first playbook
The advantages of Ansible
Agentless
Idempotent
Simple and extensible
The vendor Support
The Ansible architecture
YAML
Inventories
Variables
Templates with Jinja2
Ansible networking modules
Local connections and facts
Provider arguments
The Ansible Cisco example
The Ansible Juniper example
The Ansible Arista example
Summary
5: The Python Automation Framework - Ansible Advance Topics
Ansible conditionals
The when clause
Network module conditional
Ansible loops
Standard loops
Looping over dictionaries
Templates
The Jinja2 template
Jinja2 loops
The Jinja2 conditional
Group and host variables
Group variables
Host variables
The Ansible vault
The Ansible include and roles
The Ansible include statement
Ansible roles
Writing your own custom module
The first custom module
The second custom module
Summary
6: Network Security with Python
The lab setup
Python Scapy
Installing Scapy
Interactive examples
Sniffing
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 regular expressions
Other tools
Private VLANs
UFW with Python
Summary
7: Network Monitoring with Python - Part 1
Lab setup
SNMP
Setup
PySNMP
Python 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
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
Final 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
Elasticsearch (ELK stack)
Setting up a hosted ELK service
The logstash format
Python helper script for Logstash formatting
Summary
9: Building Network Web Services with Python
Comparing Python web frameworks
Flask and lab setup
Introduction to Flask
The HTTPie client
URL routing
URL variables
URL generation
The jsonify return
Network static content API
Flask-SQLAlchemy
Network content API
Devices API
The device ID API
Network dynamic operations
Asynchronous operations
Security
Additional resources
Summary
10: OpenFlow Basics
Lab setup
Introducing OpenFlow
Basic operations
OpenFlow 1.0 vs 1.3
Mininet
The Ryu controller with Python
Open vSwitch commands
The Ryu firewall application
Layer 2 OpenFlow switch
Planning your application
Application components
The POX controller
Summary
11: Advanced OpenFlow Topics
Setup
OpenFlow operations with Ryu
Packet inspection
Static router
Mininet topology
Ryu controller code
Ryu flow installation
Ryu packet generation
Final result
Router with API
Ryu controller with API
API usage examples
BGP router with OpenFlow
Lab router setup
Python with the BGP speaker library
Ryu BGP application
Firewall with OpenFlow
Summary
12: OpenStack, OpenDaylight, and NFV
OpenStack
OpenStack overview
Networking in OpenStack
Trying out OpenStack
OpenDaylight
OpenDaylight programming overview
OpenDaylight example
Summary
13: Hybrid SDN
Preparing the network
Familiarize yourself with the existing framework and tools
Network standardization
Create minimum viable products
Relentlessly experiment
Greenfield deployment
Controller redundancy
Multiple controller example
BGP migration example
Migration segmentation
VIRL and Mininet setup
Cisco device configuration
Ryu BGP speaker
Mininet and REST Router
Result and verification
More BGP example
Examine the JSONRPC over WebSocket
Monitoring integration
Secure TLS connection
Physical switch selection
Lab OpenFlow switches
Incumbent vendor switches
Whitebox Switches
Summary
Index
Mastering Python Networking Advanced networking with Python Eric Chou BIRMINGHAM - MUMBAI
Mastering Python Networking Copyright © 2017 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: June 2017 Production reference: 1230617 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78439-700-5 www.packtpub.com
Credits Author Eric Chou Reviewer Allen Su Copy Editor Gladson Monteiro Project Coordinator Virginia Dias Commissioning Editor Kartikey Pandey Acquisition Editor Meeta Rajani Proofreader Safis Editing Indexer Rekha Nair Content Development Editor Sweeny Dias Graphics Kirk D'Penha Technical Editors Prashant Chaudhari Komal Karne Production Coordinator Aparna Bhagat
Foreword Over my 20 years in computer networking, I have been lucky to work on a handful of popular, large-scale systems. If you had asked me in 2001, I would have told you my favorite project was AOL Instant Messenger. To scale to the size that we did in the early days, we had to create our own APIs for provisioning, security, and control over all aspects of the service--all aspects save the physical network, that is. This was a pain, but we lived with it as compute and storage needs were dynamic while network needs stayed reasonably static. In 2010, while working on what would become Microsoft Azure, it was clear that usage patterns have changed. Compute and storage have now been disaggregated, so it is more important than ever to have non-blocking connectivity and the ability to utilize any overlay technology required by the workload. Within the last few years, we have seen quite a shift in thinking, from network device vendors adding APIs and Python scripting environments to their devices in the hope of them being driven programmatically. In this book, Eric Chou helps us gain a thorough understanding of interfacing with networks and network devices using Python, from interacting with a single device to large numbers of devices with complex automation using Ansible. Then, he takes us to my favorite topics of network monitoring and security, as well as an array of OpenFlow projects controlled through the Python-based Ryu SDN controller. Eric and I worked together at Microsoft, where we built Microsoft DEMon, an Openflow- based network packet broker. Eric's deep understanding of Python and his love for automation show in every project we work on together. I have had the pleasure to see many of Eric's examples from this book used in real life and proven in actual projects. In Mastering Python Networking, Eric is adding some theory and a set of practical examples taken from real problems that he has solved. Rich Groves Director of R&D at A10 Networks
About the Author Eric Chou is a seasoned technologist with over 16 years of experience. He has managed some of the largest networks in the industry while working at Amazon and Microsoft and is passionate about network automation and Python. He shares this deep interest in these fields through his teachings as a Python instructor, blogger, and active contributor to some of the popular Python open source projects. Currently, Eric holds two patents in IP Telephony and is a principal engineer at A10 Networks with a focus on product research and development in the field of security. I would like to thank members of the Packt Publishing team--Meeta Rajani, Prashant Chaudhari, and Sweeny Dias--and my technical reviewer, Allen Su, for making my dream of writing this book a reality. Thank you for the opportunity to work with you and for your tireless effort and support. I would also like to thank the open source and Python community members for generously sharing their knowledge and code with the public. Without their contributions, many of the projects referenced in this book would not have been possible. I’m also grateful for the people who have helped me in my career and shaped my professional path. I’d like to thank all who have been part of my professional growth, especially my mentors at each stage of my career: Hup Chen, Monika Machado, and Rich Groves. Thank you for inspiring me to be the best I can be. Finally, I would like to thank my wife and my two beautiful daughters for their support. They provided me the freedom and understanding I needed to focus on and complete the book.
About the Reviewer Allen Su, CCIE no. 13871 (Routing and Switching, Service Provider, Security), is currently a senior network and cloud security engineer at Microsoft, where he is driving innovative design and engineering of secure edge services and automation capabilities. Allen is a networking industry veteran, having spent the last 15 years in various engineering and architectural roles. Prior to Microsoft, Allen was at Arista Networks, where he worked with and helped some marquee cloud providers build their cloud-scale networks and define and develop their network automation framework and strategy. Before his tenure at Arista, Allen spent a significant portion of his career at Cisco, learning the intricacies of networking, which he leveraged to design, architect, and build some of the world’s largest networks. I would like to thank Eric Chou for giving me the opportunity and privilege to review his hard work. It was a great learning journey for me personally, and I think I’ve gained way more from this journey than what I could give. Eric is the one who inspired me to begin into the network automation journey five years ago, and he continues to be an inspiration for me in this regard. I would also like to thank my wife, Cindy, for the support and love she has always given me, no matter what I set out to do. It would have been a lot tougher to review this book without her support and understanding.
www.PacktPub.com For support files and downloads related to your book, please visit www.PacktPub.com. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. h t t p s ://w w w . p a c k t p u b . c o m /m a p t Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career. Why subscribe? Fully searchable across every book published by Packt Copy and paste, print, and bookmark content On demand and accessible via a web browser
分享到:
收藏