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

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
主站蜘蛛池模板: 龙海市| 浙江省| 柯坪县| 黑河市| 安达市| 武定县| 平湖市| 聂荣县| 封开县| 醴陵市| 张家港市| 河源市| 天气| 洛扎县| 宝山区| 苏尼特左旗| 南江县| 忻城县| 金门县| 漯河市| 曲周县| 邻水| 武冈市| 龙井市| 临汾市| 嘉荫县| 防城港市| 峡江县| 正阳县| 临邑县| 灌南县| 抚顺市| 通河县| 锡林浩特市| 昆明市| 新郑市| 建昌县| 尼勒克县| 吴江市| 阿合奇县| 普陀区|