diff options
author | Andrew Shafer <andrew@reductivelabs.com> | 2008-12-13 21:51:32 -0700 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2008-12-15 11:48:31 +1100 |
commit | 1f34bcac626d57e4bc8cbc3476a6e41319a6533e (patch) | |
tree | f1e5b13b76849dcf93a360ac375b796c5b0c3bcd /lib/puppet/type | |
parent | 6d5a1295c9d9771d2dd648b45f4928d8fc4517e0 (diff) | |
download | puppet-1f34bcac626d57e4bc8cbc3476a6e41319a6533e.tar.gz puppet-1f34bcac626d57e4bc8cbc3476a6e41319a6533e.tar.xz puppet-1f34bcac626d57e4bc8cbc3476a6e41319a6533e.zip |
Issue 1804 VDev with the same devices should be in sync
Added VDev and MultiVDev properties to the ZPool type to handle logic
Vdevs with the same devices are now in sync even if the order changes
Diffstat (limited to 'lib/puppet/type')
-rwxr-xr-x | lib/puppet/type/zpool.rb | 43 |
1 files changed, 38 insertions, 5 deletions
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 |