diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/provider/zpool/solaris.rb | 20 | ||||
-rwxr-xr-x | lib/puppet/type/zpool.rb | 43 |
2 files changed, 50 insertions, 13 deletions
diff --git a/lib/puppet/provider/zpool/solaris.rb b/lib/puppet/provider/zpool/solaris.rb index d680a5f63..aaa79c15f 100644 --- a/lib/puppet/provider/zpool/solaris.rb +++ b/lib/puppet/provider/zpool/solaris.rb @@ -9,25 +9,29 @@ Puppet::Type.type(:zpool).provide(:solaris) do return Hash.new(:absent) end #get the name and get rid of it - pool = Hash.new([]) + pool = Hash.new pool[:pool] = pool_array[0] pool_array.shift - #order matters here :( tmp = [] - pool_array.reverse.each_with_index do |value, i| + #order matters here :( + pool_array.reverse.each do |value| + sym = nil case value - when "spares": pool[:spare] = tmp.reverse and tmp.clear - when "logs": pool[:log] = tmp.reverse and tmp.clear + when "spares": sym = :spare + when "logs": sym = :log when "mirror", "raidz1", "raidz2": sym = value == "mirror" ? :mirror : :raidz - pool[sym].unshift(tmp.reverse.join(' ')) pool[:raid_parity] = "raidz2" if value == "raidz2" - tmp.clear else tmp << value - pool[:disk] = tmp.reverse if i == 0 + sym = :disk if value == pool_array.first + end + + if sym + pool[sym] = pool[sym] ? pool[sym].unshift(tmp.reverse.join(' ')) : [tmp.reverse.join(' ')] + tmp.clear end end diff --git a/lib/puppet/type/zpool.rb b/lib/puppet/type/zpool.rb index 6d589a0fe..11618256f 100755 --- a/lib/puppet/type/zpool.rb +++ b/lib/puppet/type/zpool.rb @@ -1,4 +1,37 @@ module Puppet + class Property + + class VDev < Property + + def flatten_and_sort(array) + array.collect { |a| a.split(' ') }.flatten.sort + end + + def insync?(is) + return true unless self.should + + return @should == [:absent] if is == :absent + + flatten_and_sort(is) == flatten_and_sort(@should) + end + end + + class MultiVDev < VDev + def insync?(is) + return true unless self.should + + return @should == [:absent] if is == :absent + + return false unless is.length == @should.length + + is.each_with_index { |list, i| return false unless flatten_and_sort(list) == flatten_and_sort(@should[i]) } + + #if we made it this far we are in sync + true + end + end + end + newtype(:zpool) do @doc = "Manage zpools. Create and delete zpools. The provider WILL NOT SYNC, only report differences. @@ -6,11 +39,11 @@ module Puppet ensurable - newproperty(:disk, :array_matching => :all) do + newproperty(:disk, :array_matching => :all, :parent => Puppet::Property::VDev) do desc "The disk(s) for this pool. Can be an array or space separated string" end - newproperty(:mirror, :array_matching => :all) do + newproperty(:mirror, :array_matching => :all, :parent => Puppet::Property::MultiVDev) do desc "List of all the devices to mirror for this pool. Each mirror should be a space separated string. mirror => [\"disk1 disk2\", \"disk3 disk4\"]" @@ -21,7 +54,7 @@ module Puppet end end - newproperty(:raidz, :array_matching => :all) do + newproperty(:raidz, :array_matching => :all, :parent => Puppet::Property::MultiVDev) do desc "List of all the devices to raid for this pool. Should be an array of space separated strings. raidz => [\"disk1 disk2\", \"disk3 disk4\"]" @@ -32,11 +65,11 @@ module Puppet end end - newproperty(:spare, :array_matching => :all) do + newproperty(:spare, :array_matching => :all, :parent => Puppet::Property::VDev) do desc "Spare disk(s) for this pool." end - newproperty(:log, :array_matching => :all) do + newproperty(:log, :array_matching => :all, :parent => Puppet::Property::VDev) do desc "Log disks for this pool. (doesn't support mirroring yet)" end |