官术网_书友最值得收藏!

Using the GET and SET methods to manage type properties

Each property defined in the type should implement a GET and SET method in the provider.

Puppet will then invoke these methods during a Puppet run to manage the property as follows:

  1. The GET method is called initially to retrieve the current value
  2. This is subsequently compared against the value declared by the user in the Puppet DSL
  3. If the values are different, then the SET method is invoked to update that value if necessary.

This is shown in the following code:

Puppet::Type.type(:mynewtype).provide(:yum) do
...
def version
version = rpm('-q', resource[:name])
if version =~ /^#{Regexp.escape(resource[:name])}-(.*)/
$1
end
end

def version=(value)
yum('install', "#{resource[:name]}-#{resource[:version]}")
end
...
end
主站蜘蛛池模板: 克东县| 英吉沙县| 鹿邑县| 四川省| 芒康县| 丰都县| 伊金霍洛旗| 唐山市| 井研县| 神农架林区| 沈阳市| 湛江市| 西乌珠穆沁旗| 张家界市| 新巴尔虎左旗| 崇仁县| 安龙县| 天津市| 黄冈市| 巩留县| 尤溪县| 沾益县| 保德县| 武宁县| 全州县| 沐川县| 牟定县| 新余市| 遂川县| 建平县| 池州市| 苏州市| 广德县| 阿克苏市| 龙陵县| 鹤峰县| 望城县| 静乐县| 城固县| 饶平县| 嘉善县|