1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
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.
Supports vdevs with mirrors, raidz, logs and spares."
ensurable
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, :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\"]"
validate do |value|
if value.include?(",")
raise ArgumentError, "mirror names must be provided as string separated, not a comma-separated list"
end
end
end
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\"]"
validate do |value|
if value.include?(",")
raise ArgumentError, "raid names must be provided as string separated, not a comma-separated list"
end
end
end
newproperty(:spare, :array_matching => :all, :parent => Puppet::Property::VDev) do
desc "Spare disk(s) for this pool."
end
newproperty(:log, :array_matching => :all, :parent => Puppet::Property::VDev) do
desc "Log disks for this pool. (doesn't support mirroring yet)"
end
newparam(:pool) do
desc "The name for this pool."
isnamevar
end
newparam(:raid_parity) do
desc "Determines parity when using raidz property."
end
validate do
has_should = [:disk, :mirror, :raidz].select { |prop| self.should(prop) }
if has_should.length > 1
self.fail "You cannot specify %s on this type (only one)" % has_should.join(" and ")
end
end
end
end
|