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