支持定义中的多个通知
Support multiple notifies in definitions
这是
的后续问题
我将一些提供程序包装到定义中,我想知道如何处理通知。我成功地编写了一个廉价的实现,我可以在其中传递一个数组,类似于:
provider_definition name do
component $some_component
notifies [[:redeploy, "docker_container[some_container]", :immediately],
[:redeploy, "docker_container[some_other_cntr]", :delayed]]
end
然后在我的定义中我有这样的东西:
params[:notifies].each do |notify_action, resource_name, notify_time|
notifies notify_action, resource_name, notify_time
end
肯定有更好的方法吗?我希望我能在食谱中保持同样的格式:
provider_definition name do
component $some_component
notifies :redeploy, "docker_container[some_container]", :immediately
notifies :redeploy, "docker_container[some_other_cntr]", :delayed
end
但是当我这样做时,只有最后一个通知符合我的定义。
坚持定义你已经有了我认为更好的方法。
实现您希望的一个选项是将您的定义转换为 LWRP,这将创建一个自定义资源,它可以像任何其他厨师资源一样采用通知属性。
docker_library/resources/my_deploy.rb
action :deploy
default_action :deploy
attribute :component, kind_of: Hash, required: true
docker_library/provider/my_deploy.rb
action :deploy do
params = new_resource.component
docker_image params['name'] do
registry params['registry']
tag params['tag']
action :pull
end
end
我可能对组件的类型有误,我让你适应你的具体情况。凭记忆写的,我可能忘记了什么,LWRP 上有更多文档 here。
和前面的食谱一样,只是 LWRP 名称将从食谱名称和文件名派生,所以在这种情况下:
my_component = $auth_docker
docker_library_my_deploy my_component.name do
component my_component
notifies :redeploy, "docker_container[some_container]", :immediately
notifies :redeploy, "docker_container[some_other_cntr]", :delayed
end
这是
我将一些提供程序包装到定义中,我想知道如何处理通知。我成功地编写了一个廉价的实现,我可以在其中传递一个数组,类似于:
provider_definition name do
component $some_component
notifies [[:redeploy, "docker_container[some_container]", :immediately],
[:redeploy, "docker_container[some_other_cntr]", :delayed]]
end
然后在我的定义中我有这样的东西:
params[:notifies].each do |notify_action, resource_name, notify_time|
notifies notify_action, resource_name, notify_time
end
肯定有更好的方法吗?我希望我能在食谱中保持同样的格式:
provider_definition name do
component $some_component
notifies :redeploy, "docker_container[some_container]", :immediately
notifies :redeploy, "docker_container[some_other_cntr]", :delayed
end
但是当我这样做时,只有最后一个通知符合我的定义。
坚持定义你已经有了我认为更好的方法。
实现您希望的一个选项是将您的定义转换为 LWRP,这将创建一个自定义资源,它可以像任何其他厨师资源一样采用通知属性。
docker_library/resources/my_deploy.rb
action :deploy
default_action :deploy
attribute :component, kind_of: Hash, required: true
docker_library/provider/my_deploy.rb
action :deploy do
params = new_resource.component
docker_image params['name'] do
registry params['registry']
tag params['tag']
action :pull
end
end
我可能对组件的类型有误,我让你适应你的具体情况。凭记忆写的,我可能忘记了什么,LWRP 上有更多文档 here。
和前面的食谱一样,只是 LWRP 名称将从食谱名称和文件名派生,所以在这种情况下:
my_component = $auth_docker
docker_library_my_deploy my_component.name do
component my_component
notifies :redeploy, "docker_container[some_container]", :immediately
notifies :redeploy, "docker_container[some_other_cntr]", :delayed
end