# $Id: nfs_export.rb 2613 2009-06-21 17:43:52Z uwaechte $
Puppet::Type.newtype(:nfs_export) do
@doc = "Manages nfs-server's /etc/exports file."
ensurable
newproperty(:export_point) do
desc "The directory which is exported"
isnamevar
end
newproperty(:client) do
desc "The client addresses (or wildcards) to which the export_point should be exported"
# check for invalid characters
validate do |value|
unless value =~ /[-\w\*\?\/\@\.]+/
raise ArgumentError, "%s is not a valid client specification" % value
end
end
end
newproperty(:options) do
desc "Export options in linux-style notation. Those options that are applicable in FreeBSD are converted automatically."
defaultto "rw,no_subtree_check"
munge do |value|
if Facter.value(:kernel) == "FreeBSD"
linux_to_bsd_options(value)
else
super
end
end
def linux_to_bsd_options(opts)
options = []
optarr = opts.split(",")
optarr.each { |opt|
case opt
when "ro":
options << "-ro"
when "no_root_squash"
options << "-maproot=root"
when "root_squash"
uid=nil
gid=nil
optarr.each { |k|
case k
when /anonuid=(.*)/
uid=$1
when /anongid=(.*)/
gid=$1
end
}
map=[]
if !uid.nil?
map << uid.to_s
end
if !gid.nil?
map << gid.to_s
end
if map.length > 0
maps = map.join(":")
else
maps = "root"
end
options << "-maproot=#{maps}"
when "all_squash"
uid=nil
gid=nil
optarr.each { |k|
case k
when /anonuid=(.*)/
uid=$1
when /anongid=(.*)/
gid=$1
end
}
map=[]
if !uid.nil?
map << uid.to_s
end
if !gid.nil?
map << gid.to_s
end
if map.length > 0
maps = map.join(":")
else
maps = "nobody"
end
options << "-mapall=#{maps}"
end
}
return options.join(" ")
end
end
newparam(:name, :namevar => true) do
desc "The name of this export"
end
end