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

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
主站蜘蛛池模板: 鸡东县| 海原县| 屏南县| 黔南| 张家港市| 政和县| 浠水县| 通山县| 寻乌县| 上饶市| 福安市| 广灵县| 五大连池市| 临江市| 衢州市| 京山县| 忻州市| 青海省| 观塘区| 蓬安县| 大竹县| 缙云县| 宕昌县| 龙门县| 明溪县| 泊头市| 黄龙县| 莒南县| 雷州市| 房山区| 开封市| 上蔡县| 景洪市| 仙居县| 葵青区| 新沂市| 烟台市| 青川县| 石柱| 鄱阳县| 全州县|