|
1 Enhance the zone type to configure zones using a zonecfg export file format. |
|
2 Enhance the output of the puppet resource zone. |
|
3 |
|
4 --- puppet-3.2.2/lib/puppet/type/zone.rb.orig 2013-07-16 16:44:01.005467245 -0600 |
|
5 +++ puppet-3.2.2/lib/puppet/type/zone.rb 2013-07-16 16:45:04.216692249 -0600 |
|
6 @@ -1,10 +1,5 @@ |
|
7 -require 'puppet/property/list' |
|
8 Puppet::Type.newtype(:zone) do |
|
9 - @doc = "Manages Solaris zones. |
|
10 - |
|
11 -**Autorequires:** If Puppet is managing the directory specified as the root of |
|
12 -the zone's filesystem (with the `path` attribute), the zone resource will |
|
13 -autorequire that directory." |
|
14 + @doc = "Manages Solaris zones." |
|
15 |
|
16 class StateMachine |
|
17 # A silly little state machine. |
|
18 @@ -73,7 +68,7 @@ |
|
19 |
|
20 # This is seq value because the order of declaration is important. |
|
21 # i.e we go linearly from :absent -> :configured -> :installed -> :running |
|
22 - seqvalue :absent, :down => :destroy |
|
23 + seqvalue :absent, :down => :unconfigure |
|
24 seqvalue :configured, :up => :configure, :down => :uninstall |
|
25 seqvalue :installed, :up => :install, :down => :stop |
|
26 seqvalue :running, :up => :start |
|
27 @@ -102,10 +97,10 @@ |
|
28 sleep 1 |
|
29 end |
|
30 provider.send(method) |
|
31 - provider.flush() |
|
32 end |
|
33 |
|
34 def sync |
|
35 + |
|
36 method = nil |
|
37 direction = up? ? :up : :down |
|
38 |
|
39 @@ -129,127 +124,34 @@ |
|
40 |
|
41 newparam(:name) do |
|
42 desc "The name of the zone." |
|
43 - |
|
44 isnamevar |
|
45 end |
|
46 |
|
47 - newparam(:id) do |
|
48 - desc "The numerical ID of the zone. This number is autogenerated |
|
49 - and cannot be changed." |
|
50 - end |
|
51 - |
|
52 - newparam(:clone) do |
|
53 - desc "Instead of installing the zone, clone it from another zone. |
|
54 - If the zone root resides on a zfs file system, a snapshot will be |
|
55 - used to create the clone; if it resides on a ufs filesystem, a copy of the |
|
56 - zone will be used. The zone from which you clone must not be running." |
|
57 - end |
|
58 - |
|
59 - newproperty(:ip, :parent => Puppet::Property::List) do |
|
60 - require 'ipaddr' |
|
61 - |
|
62 - desc "The IP address of the zone. IP addresses must be specified |
|
63 - with the interface, separated by a colon, e.g.: bge0:192.168.0.1. |
|
64 - For multiple interfaces, specify them in an array." |
|
65 - |
|
66 - # The default action of list should is to lst.join(' '). By specifying |
|
67 - # @should, we ensure the should remains an array. If we override should, we |
|
68 - # should also override insync?() -- property/list.rb |
|
69 - def should |
|
70 - @should |
|
71 - end |
|
72 - |
|
73 - # overridden so that we match with self.should |
|
74 - def insync?(is) |
|
75 - return true unless is |
|
76 - is = [] if is == :absent |
|
77 - is.sort == self.should.sort |
|
78 - end |
|
79 - end |
|
80 - |
|
81 - newproperty(:iptype) do |
|
82 - desc "The IP stack type of the zone." |
|
83 - defaultto :shared |
|
84 - newvalue :shared |
|
85 - newvalue :exclusive |
|
86 - end |
|
87 - |
|
88 - newproperty(:autoboot, :boolean => true) do |
|
89 - desc "Whether the zone should automatically boot." |
|
90 - defaultto true |
|
91 - newvalues(:true, :false) |
|
92 + newparam(:config_profile) do |
|
93 + desc "Path to the config_profile to use to configure a solaris zone. |
|
94 + This is set when providing a sysconfig profile instead of running the |
|
95 + sysconfig SCI tool on first boot of the zone." |
|
96 end |
|
97 |
|
98 - newproperty(:path) do |
|
99 - desc "The root of the zone's filesystem. Must be a fully qualified |
|
100 - file name. If you include `%s` in the path, then it will be |
|
101 - replaced with the zone's name. Currently, you cannot use |
|
102 - Puppet to move a zone. Consequently this is a readonly property." |
|
103 - |
|
104 - validate do |value| |
|
105 - raise ArgumentError, "The zone base must be fully qualified" unless value =~ /^\// |
|
106 - end |
|
107 - |
|
108 - munge do |value| |
|
109 - if value =~ /%s/ |
|
110 - value % @resource[:name] |
|
111 - else |
|
112 - value |
|
113 - end |
|
114 - end |
|
115 - end |
|
116 - |
|
117 - newproperty(:pool) do |
|
118 - desc "The resource pool for this zone." |
|
119 + newparam(:zonecfg_export) do |
|
120 + desc "Contains the zone configuration information. This can be passed in |
|
121 + in the form of a file generated by the zonecfg command, in the form |
|
122 + of a template, or a string." |
|
123 end |
|
124 |
|
125 - newproperty(:shares) do |
|
126 - desc "Number of FSS CPU shares allocated to the zone." |
|
127 + newparam(:archive) do |
|
128 + desc "The archive file containing an archived zone." |
|
129 end |
|
130 |
|
131 - newproperty(:dataset, :parent => Puppet::Property::List ) do |
|
132 - desc "The list of datasets delegated to the non-global zone from the |
|
133 - global zone. All datasets must be zfs filesystem names which are |
|
134 - different from the mountpoint." |
|
135 - |
|
136 - def should |
|
137 - @should |
|
138 - end |
|
139 - |
|
140 - # overridden so that we match with self.should |
|
141 - def insync?(is) |
|
142 - return true unless is |
|
143 - is = [] if is == :absent |
|
144 - is.sort == self.should.sort |
|
145 - end |
|
146 - |
|
147 - validate do |value| |
|
148 - unless value !~ /^\// |
|
149 - raise ArgumentError, "Datasets must be the name of a zfs filesystem" |
|
150 - end |
|
151 - end |
|
152 + newparam(:archived_zonename) do |
|
153 + desc "The archived zone to configure and install" |
|
154 end |
|
155 - |
|
156 - newproperty(:inherit, :parent => Puppet::Property::List) do |
|
157 - desc "The list of directories that the zone inherits from the global |
|
158 - zone. All directories must be fully qualified." |
|
159 - |
|
160 - def should |
|
161 - @should |
|
162 - end |
|
163 - |
|
164 - # overridden so that we match with self.should |
|
165 - def insync?(is) |
|
166 - return true unless is |
|
167 - is = [] if is == :absent |
|
168 - is.sort == self.should.sort |
|
169 - end |
|
170 - |
|
171 - validate do |value| |
|
172 - unless value =~ /^\// |
|
173 - raise ArgumentError, "Inherited filesystems must be fully qualified" |
|
174 - end |
|
175 - end |
|
176 + |
|
177 + newparam(:clone) do |
|
178 + desc "Instead of installing the zone, clone it from another zone. |
|
179 + If the zone root resides on a zfs file system, a snapshot will be |
|
180 + used to create the clone; if it resides on a ufs filesystem, a copy of the |
|
181 + zone will be used. The zone from which you clone must not be running." |
|
182 end |
|
183 |
|
184 # Specify the sysidcfg file. This is pretty hackish, because it's |
|
185 @@ -286,70 +188,11 @@ |
|
186 so Puppet only checks for it at that time.} |
|
187 end |
|
188 |
|
189 - newparam(:create_args) do |
|
190 - desc "Arguments to the `zonecfg` create command. This can be used to create branded zones." |
|
191 - end |
|
192 - |
|
193 newparam(:install_args) do |
|
194 desc "Arguments to the `zoneadm` install command. This can be used to create branded zones." |
|
195 end |
|
196 |
|
197 - newparam(:realhostname) do |
|
198 - desc "The actual hostname of the zone." |
|
199 - end |
|
200 - |
|
201 - # If Puppet is also managing the base dir or its parent dir, list them |
|
202 - # both as prerequisites. |
|
203 - autorequire(:file) do |
|
204 - if @parameters.include? :path |
|
205 - [@parameters[:path].value, ::File.dirname(@parameters[:path].value)] |
|
206 - else |
|
207 - nil |
|
208 - end |
|
209 - end |
|
210 - |
|
211 - # If Puppet is also managing the zfs filesystem which is the zone dataset |
|
212 - # then list it as a prerequisite. Zpool's get autorequired by the zfs |
|
213 - # type. We just need to autorequire the dataset zfs itself as the zfs type |
|
214 - # will autorequire all of the zfs parents and zpool. |
|
215 - autorequire(:zfs) do |
|
216 - # Check if we have datasets in our zone configuration and autorequire each dataset |
|
217 - self[:dataset] if @parameters.include? :dataset |
|
218 - end |
|
219 - |
|
220 - def validate_ip(ip, name) |
|
221 - IPAddr.new(ip) if ip |
|
222 - rescue ArgumentError |
|
223 - self.fail "'#{ip}' is an invalid #{name}" |
|
224 - end |
|
225 - |
|
226 - def validate_exclusive(interface, address, router) |
|
227 - return if !interface.nil? and address.nil? |
|
228 - self.fail "only interface may be specified when using exclusive IP stack: #{interface}:#{address}" |
|
229 - end |
|
230 - def validate_shared(interface, address, router) |
|
231 - self.fail "ip must contain interface name and ip address separated by a \":\"" if interface.nil? or address.nil? |
|
232 - [address, router].each do |ip| |
|
233 - validate_ip(address, "IP address") unless ip.nil? |
|
234 - end |
|
235 - end |
|
236 - |
|
237 - validate do |
|
238 - return unless self[:ip] |
|
239 - # self[:ip] reflects the type passed from proeprty:ip.should. If we |
|
240 - # override it and pass @should, then we get an array here back. |
|
241 - self[:ip].each do |ip| |
|
242 - interface, address, router = ip.split(':') |
|
243 - if self[:iptype] == :shared |
|
244 - validate_shared(interface, address, router) |
|
245 - else |
|
246 - validate_exclusive(interface, address, router) |
|
247 - end |
|
248 - end |
|
249 - end |
|
250 - |
|
251 def retrieve |
|
252 - provider.flush |
|
253 hash = provider.properties |
|
254 return setstatus(hash) unless hash.nil? or hash[:ensure] == :absent |
|
255 # Return all properties as absent. |
|
256 @@ -372,4 +215,25 @@ |
|
257 end |
|
258 prophash |
|
259 end |
|
260 + |
|
261 + # Private Properties |
|
262 + # The following properties are used in conjunction with the "puppet resource zone" |
|
263 + # output. They are valid properties for configuring a zone. |
|
264 + |
|
265 + newproperty(:id) do |
|
266 + desc "The numerical ID of the zone. This number is autogenerated |
|
267 + and cannot be changed." |
|
268 + end |
|
269 + |
|
270 + newproperty(:zonepath) do |
|
271 + desc "The path to zone's file system." |
|
272 + end |
|
273 + |
|
274 + newproperty(:iptype) do |
|
275 + desc "Displays exclusive or shared instance of IP." |
|
276 + end |
|
277 + |
|
278 + newproperty(:brand) do |
|
279 + desc "The zone's brand type" |
|
280 + end |
|
281 end |