summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDavid Lutterkort <lutter@redhat.com>2009-10-05 20:32:38 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-10-24 08:36:58 +1100
commit66a44ddc3032654109036371a5f3a60dd2ab4a9f (patch)
tree95f790721ec7b8389f1813ef3fc1d23affb890c1 /lib
parentc61335f66f897bc64992c4e9209ea517193c8e30 (diff)
downloadpuppet-66a44ddc3032654109036371a5f3a60dd2ab4a9f.tar.gz
puppet-66a44ddc3032654109036371a5f3a60dd2ab4a9f.tar.xz
puppet-66a44ddc3032654109036371a5f3a60dd2ab4a9f.zip
type augeas: add 'incl' and 'lens' parameters
These parameters allow loading a file anywhere on the filesystem; using them also greatly speeds up processing the resource. * lib/puppet/type/augeas.rb: add 'incl' and 'lens' parameters; change default for 'context' when 'incl' is given. * lib/puppet/provider/augeas/augeas.rb: when 'lens' and 'incl' are given, only load that file * spec/unit/type/augeas.rb: check that constraints on new parameters are enforced This fixes ticket #2694
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/augeas/augeas.rb7
-rw-r--r--lib/puppet/type/augeas.rb27
2 files changed, 31 insertions, 3 deletions
diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb
index a645fbe8a..78be1d79e 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -133,6 +133,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do
unless @aug
flags = Augeas::NONE
flags = Augeas::TYPE_CHECK if resource[:type_check] == :true
+ flags |= Augeas::NO_MODL_AUTOLOAD if resource[:incl]
root = resource[:root]
load_path = resource[:load_path]
debug("Opening augeas with root #{root}, lens path #{load_path}, flags #{flags}")
@@ -141,6 +142,12 @@ Puppet::Type.type(:augeas).provide(:augeas) do
if get_augeas_version >= "0.3.6"
debug("Augeas version #{get_augeas_version} is installed")
end
+
+ if resource[:incl]
+ aug.set("/augeas/load/Xfm/lens", resource[:lens])
+ aug.set("/augeas/load/Xfm/incl", resource[:incl])
+ aug.load
+ end
end
@aug
end
diff --git a/lib/puppet/type/augeas.rb b/lib/puppet/type/augeas.rb
index 4ae3f06e1..b8d08bb81 100644
--- a/lib/puppet/type/augeas.rb
+++ b/lib/puppet/type/augeas.rb
@@ -58,10 +58,15 @@ Puppet::Type.newtype(:augeas) do
end
newparam (:context) do
- desc "Optional context path. This value is pre-pended to the paths of all changes if the
- path is relative. So a path specified as /files/foo will not be prepended with the
- context whild files/foo will be prepended"
+ desc "Optional context path. This value is prepended to the paths of all changes if the path is relative. If INCL is set, defaults to '/files' + INCL, otherwise the empty string"
defaultto ""
+ munge do |value|
+ if value.empty? and resource[:incl]
+ "/files" + resource[:incl]
+ else
+ value
+ end
+ end
end
newparam (:onlyif) do
@@ -129,6 +134,22 @@ Puppet::Type.newtype(:augeas) do
defaultto :false
end
+ newparam(:lens) do
+ desc "Use a specific lens, e.g. 'Hosts.lns'. When this parameter is set, you must also set the incl parameter to indicate which file to load. Only that file will be loaded, which greatly speeds up execution of the type"
+ end
+
+ newparam(:incl) do
+ desc "Load only a specific file, e.g. '/etc/hosts'. When this parameter is set, you must also set the lens parameter to indicate which lens to use."
+ end
+
+ validate do
+ has_lens = !self[:lens].nil?
+ has_incl = !self[:incl].nil?
+ if has_lens != has_incl
+ self.fail "You must specify both the lens and incl parameters, or neither"
+ end
+ end
+
# This is the acutal meat of the code. It forces
# augeas to be run and fails or not based on the augeas return
# code.