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

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
主站蜘蛛池模板: 文昌市| 伊宁县| 高平市| 宜章县| 全州县| 芒康县| 沙雅县| 平原县| 青岛市| 潼关县| 郑州市| 黑龙江省| 墨玉县| 醴陵市| 托克托县| 神木县| 秭归县| 日土县| 慈溪市| 西平县| 金堂县| 女性| 孙吴县| 冕宁县| 湟源县| 四平市| 吉安市| 天全县| 崇左市| 堆龙德庆县| 柳河县| 绥芬河市| 太仆寺旗| 蛟河市| 四子王旗| 石嘴山市| 清远市| 淮安市| 金湖县| 深水埗区| 娄烦县|