本文介绍了如何编写扩展现有提供程序的Chef提供程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

菜谱A在菜谱B中提供了一个我想用LWRP或HWRP扩展的LWRP,因此我可以执行以下操作,其中 provider_b 将使用 provider_a 中的现有代码/资源,并接受可以用于自身操作的其他属性:

Cookbook A provides a LWRP that I would like to extend with a LWRP or HWRP in cookbook B, so that I could do something like the following, where provider_b would use the existing code/resources in provider_a and accept additional attributes it could use for it's own actions:

provider_a "A" do
    attr_from_a :value
end

provider_b "B" do
    attr_from_a :value
    attr_from_b :value
end

这是否可能,而且如果我想避免编辑菜谱还是可能的A?

Is this possible, and is it still possible if I want to avoid editing cookbook A?

推荐答案

听起来您正在尝试创建现有LWRP的子资源,所以您不是包装它-您正在扩展它。 LWRP语法使此操作不尽如人意,因为在运行时会将资源动态编译为Ruby类。

It sounds like you're trying to create a sub-resource of an existing LWRP, so you're not "wrapping" it - you're "extending it". The LWRP syntax makes this less than desirable, because the resources are dynamically compiled into Ruby classes at runtime.

您可以切换到HWRP(新的是一个很好的示例,它使用继承和OO来扩展资源和共享属性。从本质上讲,LWRP并不是很可扩展,因为它们在运行时会动态重建和重新加载。

You could switch to HWRPs (the new Jenkins cookbook is a good example that uses inheritance and OO to extend resources and share attributes). By their nature, LWRPs are not very extensible, since they are dynamically rebuilt and reloaded at runtime.

这篇关于如何编写扩展现有提供程序的Chef提供程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 23:30