Skip to Content
《网络可编程性和自动化》第二版
book

《网络可编程性和自动化》第二版

by Matt Oswalt, Christian Adell, Scott S. Lowe, Jason Edelman
May 2025
Intermediate to advanced
828 pages
10h 54m
Chinese
O'Reilly Media, Inc.
Content preview from 《网络可编程性和自动化》第二版

第 10 章 使用网络 API 使用网络 API

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

从 Python、Go 和数据格式到使用 Jinja 进行配置模板化,我们已经探索了关键的基础技术和技能,它们将使你成为一名更好的网络工程师。在本章中,你将实际运用这些技能,开始使用各类网络设备 API 并与之通信,从而开始实现网络自动化。

正如我们在第 2 章中介绍的,如今有多种与网络平台交互的选择。除了传统的 CLI 和 SNMP,我们还有新的选择--从特定于网络的 API(如 NETCONF、RESTCONF 和 gNMI)到多用途 API(如基于 HTTP 的 API 或 Linux shell)。并非每台设备都支持所有这些选项,因此了解它们的功能将决定你的自动化选项。

所有接口都可用于自动化,各有利弊。本章的目标是介绍这些 API,展示如何在 Python 和 Go 中以编程方式使用它们。

为了更好地帮助您了解如何以编程方式开始与 Network+ 交互,本章分为两节:

了解网络 API

我们将研究 API 的架构和基础,包括基于 HTTP 的 RESTful 和非 RESTful API、NETCONF、RESTCONF 和 gRPC/gNMI。在每种情况下,我们都会介绍用于测试的常用工具,并说明如何使用每种工具。

使用网络 API 实现自动化

我们将介绍一些常用的 Python 和 Go 库,让您可以开始创建与网络交互的应用程序。 我们将介绍用于消费基于 HTTP API(包括 RESTCONF)的 Python Requests 和 Go HTTP 库、用于与 NETCONF 设备交互的 Python ncclient、用于与 gNMI 接口交互的 Go gNMIc,以及用于通过 SSH 实现设备自动化的 Python Netmiko 库。

在阅读本章时,请记住一点:本章不是关于任何特定 API 的综合指南,也不应作为 API 文档。 我们提供了使用不同供应商实现的特定 API 的示例,因为在多供应商环境中工作是很常见的。 了解 API 之间的共同模式和独特对比也很重要。

了解 Network+ 应用程序接口

我们的重点是网络设备上最常见的四种 API:基于 HTTP 的 API、NETCONF、RESTCONF 和 gRPC/gNMI。 我们将首先了解每种 API 的基础概念;在回顾这些概念后,我们将通过使用多个供应商提供的实践示例来探讨这些 API 的使用。

备注

对于每种网络 API 类型,我们都使用了一个或两个网络平台。这并不意味着每个 API 是一个平台支持的唯一接口。实际上,每个平台通常支持多个接口,但为了说明多个供应商和接口,我们使用了任意映射来显示多样性,而没有额外的考虑。

当我们开始使用网络 API 并与之交互的旅程时,在每个 API 小节中,我们的重点与本书迄今为止的重点一样--厂商中立的工具和库。 更具体地说,我们将使用 cURL 等工具来处理基于 HTTP 的 API(包括 RESTCONF),使用 NETCONF over SSH 来处理 NETCONF API,使用 gNMIc 来与 gNMI 接口交互。

需要注意的是,本节是关于探索Network API 的内容,我们将展示如何在不编写任何代码的情况下开始使用和测试 Network API。 我们希望您先了解每种特定 API 类型的概念,然后再在下一节中加以使用。本节涉及用于自动化生产网络的工具和技术。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python算法交易实战

Python算法交易实战

Posts & Telecom Press, Sebastien Donadio
软件工程基础

软件工程基础

Nathaniel Schutta, Dan Vega

Publisher Resources

ISBN: 9798341656994