使配置多个zope实例更加容易。
collective.recipe.zopeinstancemultiplier的Python项目详细描述
概述
这个方法使得配置多个zope实例更加容易。
示例用法
我们将从创建使用配方的构建开始:
>>> write('buildout.cfg', ... """ ... [buildout] ... parts = instance instance-multiplier ... ... [instance] ... recipe = collective.recipe.zopeinstancemultiplier:printer ... http-address = 8080 ... option-foo = value-foo ... option-bar = value-bar ... ... [instance-multiplier] ... recipe = collective.recipe.zopeinstancemultiplier ... instance-part = instance ... count = 2 ... """)
instance-multiplier部分配置为生成两个附加部分, 使用instance部分作为模型。将创建两个新部分:instance-1和 instance-2。这些部分将是模型部分的精确克隆,除了 http-address选项,将为每个部分递增。因此,我们将得到:
- instance与http-address等于8080。
- instance-1与http-address等于8081。
- instance-2与http-address等于8082。
:printer配方只在安装时打印出部件选项。我们不想 生成真正的zope实例来测试。在现实生活中你会用到 plone.recipe.zope2instance。
运行构建会给我们带来:
>>> print 'start', system(buildout) start... Installing instance. http-address = 8080 option-bar = value-bar option-foo = value-foo Installing instance-1. http-address = 8081 option-bar = value-bar option-foo = value-foo Installing instance-2. http-address = 8082 option-bar = value-bar option-foo = value-foo ...
支持“ip:port”语法
还支持http-address选项中的“ip:port”语法:
>>> write('buildout.cfg', ... """ ... [buildout] ... parts = my-instance my-instance-multiplier ... ... [my-instance] ... recipe = collective.recipe.zopeinstancemultiplier:printer ... http-address = 127.0.0.1:1234 ... ... [my-instance-multiplier] ... recipe = collective.recipe.zopeinstancemultiplier ... instance-part = my-instance ... count = 2 ... """)
运行构建会给我们带来:
>>> print 'start', system(buildout) start... Installing my-instance. http-address = 127.0.0.1:1234 Installing my-instance-1. http-address = 127.0.0.1:1235 Installing my-instance-2. http-address = 127.0.0.1:1236 ...
添加自定义实例
有时您希望在集群中有一个自定义实例。使配置更容易 “乘数”部分提供了一个包含下一个要使用的端口的特殊选项。你可以 像这样使用此选项:
>>> write('buildout.cfg', ... """ ... [buildout] ... parts = instance instance-multiplier instance-custom ... ... [instance] ... recipe = collective.recipe.zopeinstancemultiplier:printer ... http-address = 8080 ... ... [instance-multiplier] ... recipe = collective.recipe.zopeinstancemultiplier ... instance-part = instance ... count = 2 ... ... [instance-custom] ... <= instance ... http-address = ${instance-multiplier:next-http-address} ... custom-option = custom-value ... """)
运行构建会给我们带来:
>>> print 'start', system(buildout) start ... Installing instance. http-address = 8080 Installing instance-1. http-address = 8081 Installing instance-2. http-address = 8082 ... Installing instance-custom. custom-option = custom-value http-address = 8083
取决于部件的名称(${:_buildout_section_name}support)
有时选项值必须包含零件的名称。buildout通过 提供特殊值_buildout_section_name_。
下面的示例演示了如何在多个zope中使用此特殊值 实例场景,不使用此配方:
[instance] ... http-address = 8080 special-log-path = /path/to/the/logs/${:_buildout_section_name}.log [instance-1] <= instance http-address = 8081 [instance-2] <= instance http-address = 8082
尝试将上一个示例调整为使用此配方,如下所示:
[instance] ... http-address = 8080 special-log-path = /path/to/the/logs/${:_buildout_section_name}.log [instance-multiplier] recipe = collective.recipe.zopeinstancemultiplier instance-part = instance count = 2
然而,这将失败。因为buildout的工作方式,在配方可以访问的时候 为了使instance部分相乘,变量替换已经发生。
要使它起作用,需要简单的适应。只需添加一个额外的美元符号,以便 退出变量。下面是一个示例:
>>> write('buildout.cfg', ... """ ... [buildout] ... parts = instance instance-multiplier ... ... [instance] ... recipe = collective.recipe.zopeinstancemultiplier:printer ... http-address = 8080 ... special-log-path = /path/to/the/logs/$${:_buildout_section_name_}.log ... ... [instance-multiplier] ... recipe = collective.recipe.zopeinstancemultiplier ... instance-part = instance ... count = 2 ... """)
运行构建会给我们带来:
>>> print 'start', system(buildout) start ... Installing instance. http-address = 8080 special-log-path = /path/to/the/logs/instance.log Installing instance-1. http-address = 8081 special-log-path = /path/to/the/logs/instance-1.log Installing instance-2. http-address = 8082 special-log-path = /path/to/the/logs/instance-2.log ...
更改日志
0.1.0(2017-07-18)
- 添加对_buildout_section_name特殊变量的支持。
0.0.2(2017-07-17)
- 修复setup.py中的描述。
0.0.1(2017-07-17)
- 第一次释放。