From 5259d0443a1523b4d184dc41784e94e34163319a Mon Sep 17 00:00:00 2001 From: Xingyu Wang Date: Sun, 7 May 2023 23:27:20 +0800 Subject: [PATCH] RP @geekpi https://linux.cn/article-15793-1.html --- ...luster with this open source Python API wrapper.md | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) rename {translated/tech => published}/20230418.2 ⭐️⭐️ Talk to your cluster with this open source Python API wrapper.md (73%) diff --git a/translated/tech/20230418.2 ⭐️⭐️ Talk to your cluster with this open source Python API wrapper.md b/published/20230418.2 ⭐️⭐️ Talk to your cluster with this open source Python API wrapper.md similarity index 73% rename from translated/tech/20230418.2 ⭐️⭐️ Talk to your cluster with this open source Python API wrapper.md rename to published/20230418.2 ⭐️⭐️ Talk to your cluster with this open source Python API wrapper.md index 14fa4bc917..79c3309623 100644 --- a/translated/tech/20230418.2 ⭐️⭐️ Talk to your cluster with this open source Python API wrapper.md +++ b/published/20230418.2 ⭐️⭐️ Talk to your cluster with this open source Python API wrapper.md @@ -3,24 +3,28 @@ [#]: author: "Ruth Netser https://opensource.com/users/rnetser1" [#]: collector: "lkxed" [#]: translator: "geekpi" -[#]: reviewer: " " -[#]: publisher: " " -[#]: url: " " +[#]: reviewer: "wxy" +[#]: publisher: "wxy" +[#]: url: "https://linux.cn/article-15793-1.html" -使用这个开源 Python API 封装器与你的集群对话 +使用开源 Python API 封装器与你的集群对话 ====== -围绕 API 创建封装器的开源项目正变得越来越流行。这些项目使开发人员更容易与 API 交互并在他们的应用中使用它们。`openshift-python-wrapper` 项目是 [openshift-restclient-python][1] 的封装器。最初是一个帮助我们的团队使用 OpenShift API 的内部包,后来变成了一个[开源项目][2] (Apache License 2.0)。 +![][0] + +> 结合开放的 API 和 Python 编程语言的力量。 + +围绕 API 创建封装器的开源项目正变得越来越流行。这些项目使开发人员更容易与 API 交互并在他们的应用中使用它们。`openshift-python-wrapper` 项目是 [openshift-restclient-python][1] 的封装器。最初是一个帮助我们的团队使用 OpenShift API 的内部包,后来变成了一个[开源项目][2](Apache 许可证 2.0)。 本文讨论了什么是 API 封装器,为什么它很有用,以及封装器的一些例子。 ### 为什么要使用 API 封装器? -API 封装器是位于应用和 API 之间的一层代码。它通过抽象出一些涉及发出请求和解析响应的复杂性来简化 API 访问过程。封装器还可以提供 API 本身提供的功能之外的附加功能,例如缓存或错误处理。 +API 封装器是位于应用和 API 之间的一层代码。它通过将一些涉及发出请求和解析响应的复杂性抽象出来,以简化 API 访问过程。封装器还可以提供 API 本身提供的功能之外的附加功能,例如缓存或错误处理。 使用 API 封装器使代码更加模块化并且更易于维护。无需为每个 API 编写自定义代码,你可以使用封装器来提供与 API 交互的一致接口。它可以节省时间,避免代码重复,并减少出错的机会。 -使用 API 封装器的另一个好处是它可以保护你的代码免受 API 更改的影响。如果 API 更改了它的接口,你可以更新封装器代码而无需修改你的应用程序代码。随着时间的推移,这可以减少维护应用程序所需的工作。 +使用 API 封装器的另一个好处是它可以保护你的代码免受 API 变化的影响。如果 API 更改了它的接口,你可以更新封装器代码而无需修改你的应用程序代码。随着时间的推移,这可以减少维护应用程序所需的工作。 ### 安装 @@ -32,9 +36,9 @@ $ python3 -m pip install openshift-python-wrapper ### Python 封装器 -[OpenShift REST API][5] 提供对 OpenShift 平台的许多功能的编程访问。封装器提供了一个简单直观的界面,用于使用 `openshift-restclient-python` 库与 API 进行交互。它标准化了如何使用集群资源并提供统一的资源 CRUD(创建、读取、更新和删除)流程。它还提供额外的功能,例如需要由用户实现的特定于资源的功能。随着时间的推移,封装器使代码更易于阅读和维护。 +[OpenShift REST API][5] 提供对 OpenShift 平台的许多功能的编程访问。封装器提供了一个简单直观的界面,用于使用 `openshift-restclient-python` 库与 API 进行交互。它标准化了如何使用集群资源,并提供了统一的资源 CRUD(创建、读取、更新和删除)流程。它还提供额外的功能,例如需要由用户实现的特定于资源的功能。随着时间的推移,封装器使代码更易于阅读和维护。 -简化用法的一个示例是与容器交互。在容器内运行命令需要使用 Kubernetes 流、处理错误等。封装器处理这一切并提供[简单直观的功能][6]。 +简化用法的一个示例是与容器交互。在容器内运行命令需要使用 Kubernetes 流、处理错误等。封装器处理这一切并提供 [简单直观的功能][6]。 ``` >>> from ocp_resources.pod import Pod @@ -84,10 +88,12 @@ ip-10-0-128-213.ec2.internal ### 开源社区的开源代码 -套用一句流行的说法,“如果你喜欢你的代码,就把它释放出来。” `openshift-python-wrapper` 项目最初是作为 [OpenShift 虚拟化][7]的实用模块。随着越来越多的项目从代码中受益,我们决定将这些程序提取到一个单独的仓库中并将其开源。套用另一句俗语,“如果代码没有返回给你,就意味着它从来就不是你的。” 我们喜欢说,一旦发生这种情况,它就是真正的开源。 +套用一句流行的说法,“如果你热爱你的代码,就应该让它自由。” `openshift-python-wrapper` 项目最初是作为 [OpenShift 虚拟化][7] 的实用模块。随着越来越多的项目从代码中受益,我们决定将这些程序提取到一个单独的仓库中并将其开源。套用另一句俗语,“如果代码不回到你这里,那就意味着它从未属于你。” 一旦这种情况发生,它就真正成为了开源。 更多的贡献者和维护者意味着代码属于社区。欢迎大家贡献。 +*(题图:MJ/5ca32a4a-2194-4b36-ade9-053433e79201)* + -------------------------------------------------------------------------------- via: https://opensource.com/article/23/4/cluster-open-source-python-api-wrapper @@ -95,7 +101,7 @@ via: https://opensource.com/article/23/4/cluster-open-source-python-api-wrapper 作者:[Ruth Netser][a] 选题:[lkxed][b] 译者:[geekpi](https://github.com/geekpi) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 @@ -107,4 +113,5 @@ via: https://opensource.com/article/23/4/cluster-open-source-python-api-wrapper [4]: https://opensource.com/downloads/pip-cheat-sheet [5]: https://access.redhat.com/documentation/en-us/openshift_container_platform/3.5/html-single/using_the_openshift_rest_api/index?intcmp=7013a000002qLH8AAM [6]: https://github.com/RedHatQE/openshift-python-wrapper/blob/main/ocp_resources/pod.py#L72 -[7]: https://www.redhat.com/en/technologies/cloud-computing/openshift/virtualization?intcmp=7013a000002qLH8AAM \ No newline at end of file +[7]: https://www.redhat.com/en/technologies/cloud-computing/openshift/virtualization?intcmp=7013a000002qLH8AAM +[0]: https://img.linux.net.cn/data/attachment/album/202305/07/232516w8j766mkp7pz7frl.png \ No newline at end of file