在分析记录port的创建过程时,注意到会调用neutron-lib库的方法,所以就比较好奇neutron-lib在这个过程中起到了何种作用。所以本篇就用自己蹩脚的英文,尝试翻译记录下openstack官网中有关neutron-lib的介绍。
Neutron-lib is an OpenStack library project used by Neutron, Advanced Services, and third-party projects that aims to provide common functionality across all such consumers. The library is developed with the following goals in mind:
-
Decouple sub-projects from Neutron (i.e. no direct neutron imports in sub-projects).
-
Pay down Neutron technical debt via refactoring/re-architecting of sub-optimal patterns in their respective neutron-lib implementation.
neutron-lib是opesntack中neutron这一高级服务使用的库,其作为第三方的项目存在的目的是为了消费者提供通用功能。其大体上依据以下目标发展:
1.将子项目同neutron解耦;
2.通过在其各自的工具重建次优模式来偿还neutron技术债务;(百度翻译,搞不懂。。)
Consuming neutron-lib
Many OpenStack projects consume neutron-lib by importing and using its code. As a result, these consumers must define neutron-lib
as a dependency in their respective requirements.txt
file. While this is likely nothing new to most OpenStack developers, it may not be obvious to consumers if they need to always use the latest release of neutron-lib, or if they can lag behind using an old(er) release of it.
许多openstack项目通过导入使用其code的方式使用neutron-lib库。因此,使用者必须要在各自的requirements.txt文件中定义neutron-lib,将其作为依赖包。虽然对于大多数开发者而言这并不新鲜,但是对于消费者而言,如果他们总是需要使用最新版本,或者使用落后的旧版本就不太明显了。
The answer is that it’s up to the consuming project if they want to stay “current” or not in terms of the neutron-lib version they use. While we might like all consumers to stay current and there are benefits to it, this isn’t always realistic for projects that have less developers/velocity. Therefore, each project has two options for consuming neutron-lib.
答案是,如果想保持最新或者不想使用他们的neutron-lib版本,这取决于消费者项目。虽然我们想让所有的消费者保持最新,而且他们也能从此处受益,但是对于开发者很少的项目显然是不现实的。因此,每个项目有两个使用neutron-lib库的选择。
Opt-in to stay current by adding a comment with neutron-lib-current
in their requirements.txt
. This string declares the project’s intent to use the latest version of neutron-lib as well as their agreement to stay current with overall OpenStack initiatives. These projects receive updates “for free” as part of the ongoing neutron-lib work. For more details see the ML archive
选择保持最新需要将neutron-lib-current加入requirements.txt文件。这个字符串声明了此项目意图使用最新的neutron-lib,同时其同意与所有openstack项目保持同步。这些项目免费接受更新,作为正在进行中的neutron-lib的一部分。
Do not opt-in and rather manage your own consumption of neutron-lib. In this case your project developers must define the version of neutron-lib to use and update the project’s code to consume it as they bump up the version. In this scenario most projects will also be managing a back-leveled version of neutron
since neutron is always current with neutron-lib and might otherwise break the consuming code.
不选择保持最新而是管理自己的neutron-lib库。这样的话,项目开发者必须定义使用的neutron-lib库的版本,并且需要随着版本提升更新代码。在这种设想下,各个项目也必须管理neutron的版本,因为neutron总是同neutron-lib库的版本一致,否则可能会消耗代码。
neutron-lib库的协议
Interface Contract¶
The neutron-lib repo exists to provide code with a long-term stable interface for subprojects. If we do need to deprecate something, a debtcollector warning will be added, the neutron-lib core team will make every effort to update any neutron stadium project for you, and you will get at least the current release plus two cycles before it disappears.
In keeping with how hard it is to remove things, the change velocity of this library will be slower than neutron. There are two notable cases where code should go into standard neutron instead of this lib (or your repo):
-
It is something common, but changes a lot. An example is something like the neutron Port object. Everyone uses it, but it changes frequently. You don’t want to wait for a library release to tweak some neutron feature, and we are not going to force releases quickly because you tried to put it here. Those items will need to be addressed in some other manner (in the case of the Port object, it’ll be via an auto-magic container object that mimics it.)
-
It is something common, but you need it now. Put it in the repo that needs it, get your stuff working. Then consider making it available in the lib, and eventually remove it from your repo when the lib is publishing it. An example would be a new neutron constant. The process would be, put it in neutron along with your change, submit it to the lib, when that constant is eventually available, remove it from neutron and use the lib version.
总结来看,就是neutron-lib库的接口协议是为了长期使用而准备的,因此其更新周期会比neutron慢,所以有些时候新增的部分只能加入到neutron里面,而不会加入neutron-lib中。
本文简单从概念方面介绍了neutron-lib库,一是水平有限,二是篇幅有限,故挑选了一些自认为重要的地方,想查看原文可登录openstack官网:https://docs.openstack.org/neutron-lib/latest/