openstack plugin 之(四)如何區分 OpenStack Neutron Extension 和 Plugin

原文鏈接:https://www.cnblogs.com/zhutianshi/p/3902315.html

Neutron 裏面的 extension 和 plugin 是非常相似的兩個概念,我花了好久才貌似搞懂了兩者的區別,還不一定完全正確。

在OpenStack 的官網wiki中,可以找到它們兩個的定義:

Plugin:

Neutron exposes a logical API to define network connectivity between devices from other OpenStack services (e.g., vNICs from Nova VMs). The logical connectivity described using the API must be translated into actually configuration on virtual and/or physical switches. This is where a Neutron plugin comes in. The Neutron plugin is able to talk to one or more types of switches and dynamically reconfigures the switches based on API calls.

Extension:

API Extensions allow a plugin to extend the Neutron API in order to expose more information. This information could be required to implement advanced functionality that is specific to a particular plugin, or to expose a capability before it has been incorporated into an official Neutron API.

具體鏈接在這裏:https://wiki.openstack.org/wiki/NeutronDevelopment

由上述定義,再結合 Neutron 源代碼中的一些文件可以看出,其實一個官方的核心插件(Core Plugin)只包括三種資源:Network, Subnet 以及 Port。插件必須能夠與一些交換機溝通,實現邏輯上的二層和三層網絡。而當我們需要在Neutron中加入更多的網絡資源,例如 Router, Load Balancer, Gateway, VPN, Security Group 等的時候,extension 就出場了。這些額外的資源都可以在 extension 中進行定義,例如我在之前的文章中提到的RESOURCE_ATTRIBUTE_MAP等。

在官網中,我們還可以看到,extension還分三種:

Resource extensions introduce a new "entity" to the API. In Neutron, current entities are "networks" and "ports".
Action extensions tend to be "verbs" that act on a resource. For example, in Nova, there is a "server" resource, and a "rebuild" action on that server resource: http://docs.openstack.org/cactus/openstack-compute/developer/openstack-compute-api-1.1/content/Rebuild_Server-d1e3538.html#d2278e1430 . Core Neutron API doesn't really use "actions" as part of the core API, but extensions certainly could.
Request extensions allow one to add new values to existing requests objects. For example, if you were doing a POST to create a server, but wanted to add a new 'widgetType' attribute for the server object.

可以看到,第一種 Resource extensions 就是我們說的在需要加入更多新資源的時候可以用到。

第二種 Action extensions 就是在我們需要加入新動作的時候可以用到。比如說我有一個 Gateway 資源,希望可以把它和許多 Network 關聯起來,這個操作可能就不存在於傳統的CRUD中,那我就需要定義一個新的 Action Extension。

第三種我也不是特別理解,可能是說Request Extension是可以用來處理已經存在的資源的一些新增屬性。例如 Network 資源多出來一個 priority 屬性,傳統的CRUD只針對 Network 原有的屬性,不會去涉及到 priority 的值,那我就需要針對 priority 屬性定義一個新的 Request Extension。

所以根據上面的描述,在我們要開發 Neutron 的時候,第一個要決定的事情就是我到底要寫一個 Extension 還是 Plugin?如果我需要新增一些資源,那毫無疑問必須上 Extension; 如果我要實現一個新的與交換機溝通的方法,那就需要實現一組新的 Plugin。

發佈了4 篇原創文章 · 獲贊 38 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章