diff --git a/lib/puppet/provider/zfs/zfs.rb b/lib/puppet/provider/zfs/zfs.rb index 8e85005..57d0b36 100644 --- a/lib/puppet/provider/zfs/zfs.rb +++ b/lib/puppet/provider/zfs/zfs.rb @@ -1,109 +1,104 @@ Puppet::Type.type(:zfs).provide(:zfs) do desc 'Provider for zfs.' commands zfs: 'zfs' def self.instances zfs(:list, '-H').split("\n").map do |line| name, _used, _avail, _refer, _mountpoint = line.split(%r{\s+}) new(name: name, ensure: :present) end end def add_properties properties = [] Puppet::Type.type(:zfs).validproperties.each do |property| next if property == :ensure if (value = @resource[property]) && value != '' if property == :volsize properties << '-V' << value.to_s else properties << '-o' << "#{property}=#{value}" end end end properties end def create zfs(*([:create] + add_properties + [@resource[:name]])) end def destroy zfs(:destroy, @resource[:name]) end def exists? zfs(:list, @resource[:name]) true rescue Puppet::ExecutionFailure false end # On FreeBSD zoned is called jailed def container_property case Facter.value(:operatingsystem) when 'FreeBSD' :jailed else :zoned end end PARAMETER_UNSET_OR_NOT_AVAILABLE = '-'.freeze # https://docs.oracle.com/cd/E19963-01/html/821-1448/gbscy.html # shareiscsi (added in build 120) was removed from S11 build 136 # aclmode was removed from S11 in build 139 but it may have been added back # acltype is for ZFS on Linux, and allows disabling or enabling POSIX ACLs # http://webcache.googleusercontent.com/search?q=cache:-p74K0DVsdwJ:developers.slashdot.org/story/11/11/09/2343258/solaris-11-released+&cd=13 - [:aclmode, :acltype, :shareiscsi].each do |field| + [:aclmode, :acltype, :shareiscsi, :overlay].each do |field| # The zfs commands use the property value '-' to indicate that the # property is not set. We make use of this value to indicate that the # property is not set since it is not available. Conversely, if these # properties are attempted to be unset, and resulted in an error, our # best bet is to catch the exception and continue. define_method(field) do begin zfs(:get, '-H', '-o', 'value', field, @resource[:name]).strip rescue PARAMETER_UNSET_OR_NOT_AVAILABLE end end define_method(field.to_s + '=') do |should| begin zfs(:set, "#{field}=#{should}", @resource[:name]) rescue PARAMETER_UNSET_OR_NOT_AVAILABLE end end end - zfs_properties = [:aclinherit, :atime, :canmount, :checksum, - :compression, :copies, :dedup, :devices, :exec, :logbias, - :mountpoint, :nbmand, :primarycache, :quota, :readonly, - :recordsize, :refquota, :refreservation, :reservation, - :secondarycache, :setuid, :sharenfs, :sharesmb, - :snapdir, :version, :volsize, :vscan, :xattr] - - # The overlay property is only supported on Linux - zfs_properties << :overlay if Facter.value(:kernel) == 'Linux' - - zfs_properties.each do |field| + [:aclinherit, :atime, :canmount, :checksum, + :compression, :copies, :dedup, :devices, :exec, :logbias, + :mountpoint, :nbmand, :primarycache, :quota, :readonly, + :recordsize, :refquota, :refreservation, :reservation, + :secondarycache, :setuid, :sharenfs, :sharesmb, + :snapdir, :version, :volsize, :vscan, :xattr].each do |field| define_method(field) do zfs(:get, '-H', '-o', 'value', field, @resource[:name]).strip end define_method(field.to_s + '=') do |should| zfs(:set, "#{field}=#{should}", @resource[:name]) end end define_method(:zoned) do zfs(:get, '-H', '-o', 'value', container_property, @resource[:name]).strip end define_method('zoned=') do |should| zfs(:set, "#{container_property}=#{should}", @resource[:name]) end end diff --git a/lib/puppet/type/zfs.rb b/lib/puppet/type/zfs.rb index 520f317..6abce88 100644 --- a/lib/puppet/type/zfs.rb +++ b/lib/puppet/type/zfs.rb @@ -1,168 +1,170 @@ # Manage zfs. Create destroy and set properties on zfs instances. module Puppet Type.newtype(:zfs) do desc <<-DESC Manage zfs. Create destroy and set properties on zfs instances. **Autorequires:** If Puppet is managing the zpool at the root of this zfs instance, the zfs resource will autorequire it. If Puppet is managing any parent zfs instances, the zfs resource will autorequire them. @example Using zfs. zfs { 'tstpool': ensure => present, } DESC ensurable newparam(:name) do desc 'The full name for this filesystem (including the zpool).' end newproperty(:aclinherit) do desc 'The aclinherit property. Valid values are `discard`, `noallow`, `restricted`, `passthrough`, `passthrough-x`.' end newproperty(:aclmode) do desc 'The aclmode property. Valid values are `discard`, `groupmask`, `passthrough`.' end newproperty(:acltype) do desc "The acltype propery. Valid values are 'noacl' and 'posixacl'. Only supported on Linux." end newproperty(:atime) do desc 'The atime property. Valid values are `on`, `off`.' end newproperty(:canmount) do desc 'The canmount property. Valid values are `on`, `off`, `noauto`.' end newproperty(:checksum) do desc 'The checksum property. Valid values are `on`, `off`, `fletcher2`, `fletcher4`, `sha256`.' end newproperty(:compression) do desc 'The compression property. Valid values are `on`, `off`, `lzjb`, `gzip`, `gzip-[1-9]`, `zle`.' end newproperty(:copies) do desc 'The copies property. Valid values are `1`, `2`, `3`.' end newproperty(:dedup) do desc 'The dedup property. Valid values are `on`, `off`.' end newproperty(:devices) do desc 'The devices property. Valid values are `on`, `off`.' end newproperty(:exec) do desc 'The exec property. Valid values are `on`, `off`.' end newproperty(:logbias) do desc 'The logbias property. Valid values are `latency`, `throughput`.' end newproperty(:mountpoint) do desc 'The mountpoint property. Valid values are ``, `legacy`, `none`.' end newproperty(:nbmand) do desc 'The nbmand property. Valid values are `on`, `off`.' end - if Facter.value(:kernel) == 'Linux' - newproperty(:overlay) do - desc 'The overlay property. Valid values are `on`, `off`.' + newproperty(:overlay) do + desc 'The overlay property. Valid values are `on`, `off`.' + + validate do |_value| + raise Puppet::Error _('This property is only supported on Linux') unless Facter.value(:kernel) == 'Linux' end end newproperty(:primarycache) do desc 'The primarycache property. Valid values are `all`, `none`, `metadata`.' end newproperty(:quota) do desc 'The quota property. Valid values are ``, `none`.' end newproperty(:readonly) do desc 'The readonly property. Valid values are `on`, `off`.' end newproperty(:recordsize) do desc 'The recordsize property. Valid values are powers of two between 512 and 128k.' end newproperty(:refquota) do desc 'The refquota property. Valid values are ``, `none`.' end newproperty(:refreservation) do desc 'The refreservation property. Valid values are ``, `none`.' end newproperty(:reservation) do desc 'The reservation property. Valid values are ``, `none`.' end newproperty(:secondarycache) do desc 'The secondarycache property. Valid values are `all`, `none`, `metadata`.' end newproperty(:setuid) do desc 'The setuid property. Valid values are `on`, `off`.' end newproperty(:shareiscsi) do desc 'The shareiscsi property. Valid values are `on`, `off`, `type=`.' end newproperty(:sharenfs) do desc 'The sharenfs property. Valid values are `on`, `off`, share(1M) options' end newproperty(:sharesmb) do desc 'The sharesmb property. Valid values are `on`, `off`, sharemgr(1M) options' end newproperty(:snapdir) do desc 'The snapdir property. Valid values are `hidden`, `visible`.' end newproperty(:version) do desc 'The version property. Valid values are `1`, `2`, `3`, `4`, `current`.' end newproperty(:volsize) do desc 'The volsize property. Valid values are ``' end newproperty(:vscan) do desc 'The vscan property. Valid values are `on`, `off`.' end newproperty(:xattr) do desc 'The xattr property. Valid values are `on`, `off`.' end newproperty(:zoned) do desc 'The zoned property. Valid values are `on`, `off`.' end autorequire(:zpool) do # strip the zpool off the zfs name and autorequire it [@parameters[:name].value.split('/')[0]] end autorequire(:zfs) do # slice and dice, we want all the zfs before this one names = @parameters[:name].value.split('/') names.slice(1..-2).reduce([]) { |a, v| a << "#{a.last}/#{v}" }.map { |fs| names[0] + fs } end end end