diff --git a/REFERENCE.md b/REFERENCE.md index 39de250..c29d161 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1,249 +1,253 @@ # Reference ## Resource types * [`zfs`](#zfs): Manage zfs. Create destroy and set properties on zfs instances. **Autorequires:** If Puppet is managing the zpool at the root of this zfs in * [`zpool`](#zpool): Manage zpools. Create and delete zpools. The provider WILL NOT SYNC, only report differences. Supports vdevs with mirrors, raidz, logs and s ## Resource types ### zfs 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. #### Examples ##### Using zfs. ```puppet zfs { 'tstpool': ensure => present, } ``` #### Properties The following properties are available in the `zfs` type. ##### `ensure` Valid values: present, absent The basic property that the resource should be in. Default value: present ##### `aclinherit` The aclinherit property. Valid values are `discard`, `noallow`, `restricted`, `passthrough`, `passthrough-x`. ##### `aclmode` The aclmode property. Valid values are `discard`, `groupmask`, `passthrough`. ##### `acltype` The acltype propery. Valid values are 'noacl' and 'posixacl'. Only supported on Linux. ##### `atime` The atime property. Valid values are `on`, `off`. ##### `canmount` The canmount property. Valid values are `on`, `off`, `noauto`. ##### `checksum` The checksum property. Valid values are `on`, `off`, `fletcher2`, `fletcher4`, `sha256`. ##### `compression` The compression property. Valid values are `on`, `off`, `lzjb`, `gzip`, `gzip-[1-9]`, `zle`. ##### `copies` The copies property. Valid values are `1`, `2`, `3`. ##### `dedup` The dedup property. Valid values are `on`, `off`. ##### `devices` The devices property. Valid values are `on`, `off`. ##### `exec` The exec property. Valid values are `on`, `off`. ##### `logbias` The logbias property. Valid values are `latency`, `throughput`. ##### `mountpoint` The mountpoint property. Valid values are ``, `legacy`, `none`. ##### `nbmand` The nbmand property. Valid values are `on`, `off`. ##### `primarycache` The primarycache property. Valid values are `all`, `none`, `metadata`. ##### `quota` The quota property. Valid values are ``, `none`. ##### `readonly` The readonly property. Valid values are `on`, `off`. ##### `recordsize` The recordsize property. Valid values are powers of two between 512 and 128k. ##### `refquota` The refquota property. Valid values are ``, `none`. ##### `refreservation` The refreservation property. Valid values are ``, `none`. ##### `reservation` The reservation property. Valid values are ``, `none`. ##### `secondarycache` The secondarycache property. Valid values are `all`, `none`, `metadata`. ##### `setuid` The setuid property. Valid values are `on`, `off`. ##### `shareiscsi` The shareiscsi property. Valid values are `on`, `off`, `type=`. ##### `sharenfs` The sharenfs property. Valid values are `on`, `off`, share(1M) options ##### `sharesmb` The sharesmb property. Valid values are `on`, `off`, sharemgr(1M) options ##### `snapdir` The snapdir property. Valid values are `hidden`, `visible`. +##### `sync` + +The sync property. Valid values are `standard`, `always`, `disabled`. + ##### `version` The version property. Valid values are `1`, `2`, `3`, `4`, `current`. ##### `volsize` The volsize property. Valid values are `` ##### `vscan` The vscan property. Valid values are `on`, `off`. ##### `xattr` The xattr property. Valid values are `on`, `off`. ##### `zoned` The zoned property. Valid values are `on`, `off`. #### Parameters The following parameters are available in the `zfs` type. ##### `name` namevar The full name for this filesystem (including the zpool). ### zpool Manage zpools. Create and delete zpools. The provider WILL NOT SYNC, only report differences. Supports vdevs with mirrors, raidz, logs and spares. #### Examples ##### Using zpool. ```puppet zpool { 'tstpool': ensure => present, disk => '/ztstpool/dsk', } ``` #### Properties The following properties are available in the `zpool` type. ##### `ensure` Valid values: present, absent The basic property that the resource should be in. Default value: present ##### `disk` The disk(s) for this pool. Can be an array or a space separated string. Use disk/device names as displayed by "zpool status". On Linux/ZOL, use full device pathes as displayed by "zpool status -P". ##### `mirror` List of all the devices to mirror for this pool. Each mirror should be a space separated string: mirror => [\"disk1 disk2\", \"disk3 disk4\"], ##### `raidz` List of all the devices to raid for this pool. Should be an array of space separated strings: raidz => [\"disk1 disk2\", \"disk3 disk4\"], ##### `spare` Spare disk(s) for this pool. ##### `log` Log disks for this pool. This type does not currently support mirroring of log disks. #### Parameters The following parameters are available in the `zpool` type. ##### `pool` namevar The name for this pool. ##### `raid_parity` Determines parity when using the `raidz` parameter. diff --git a/lib/puppet/provider/zfs/zfs.rb b/lib/puppet/provider/zfs/zfs.rb index 7a2f5df..d2f8a1f 100644 --- a/lib/puppet/provider/zfs/zfs.rb +++ b/lib/puppet/provider/zfs/zfs.rb @@ -1,104 +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 unless defined? PARAMETER_UNSET_OR_NOT_AVAILABLE # 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, :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 [: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| + :snapdir, :sync, :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 6abce88..b2cd48a 100644 --- a/lib/puppet/type/zfs.rb +++ b/lib/puppet/type/zfs.rb @@ -1,170 +1,174 @@ # 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 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(:sync) do + desc 'The sync property. Valid values are `standard`, `always`, `disabled`.' + 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 diff --git a/spec/unit/type/zfs_spec.rb b/spec/unit/type/zfs_spec.rb index a595302..4f85757 100644 --- a/spec/unit/type/zfs_spec.rb +++ b/spec/unit/type/zfs_spec.rb @@ -1,43 +1,43 @@ require 'spec_helper' describe Puppet::Type.type(:zfs) do - properties = [:ensure, :mountpoint, :compression, :copies, :overlay, :quota, :reservation, :sharenfs, :snapdir] + properties = [:ensure, :mountpoint, :compression, :copies, :overlay, :quota, :reservation, :sharenfs, :snapdir, :sync] properties.each do |property| it "should have a #{property} property" do expect(described_class.attrclass(property).ancestors).to be_include(Puppet::Property) end end parameters = [:name] parameters.each do |parameter| it "should have a #{parameter} parameter" do expect(described_class.attrclass(parameter).ancestors).to be_include(Puppet::Parameter) end end it 'autorequires the containing zfs and the zpool' do zfs_provider = instance_double 'provider' allow(zfs_provider).to receive(:name).and_return(:zfs) allow(described_class).to receive(:defaultprovider) { zfs_provider } zpool_provider = instance_double 'provider' allow(zpool_provider).to receive(:name).and_return(:zpool) allow(Puppet::Type.type(:zpool)).to receive(:defaultprovider) { zpool_provider } foo_pool = Puppet::Type.type(:zpool).new(name: 'foo') foo_bar_zfs = described_class.new(name: 'foo/bar') foo_bar_baz_zfs = described_class.new(name: 'foo/bar/baz') foo_bar_baz_buz_zfs = described_class.new(name: 'foo/bar/baz/buz') Puppet::Resource::Catalog.new :testing do |conf| [foo_pool, foo_bar_zfs, foo_bar_baz_zfs, foo_bar_baz_buz_zfs].each { |resource| conf.add_resource resource } end req = foo_bar_baz_buz_zfs.autorequire.map { |edge| edge.source.ref } [foo_pool.ref, foo_bar_zfs.ref, foo_bar_baz_zfs.ref].each { |ref| expect(req.include?(ref)).to eq(true) } end end