| Path: | lib/puppet/type/zone.rb |
| Last Update: | Tue Dec 02 06:55:04 +0100 2008 |
# File lib/puppet/type/zone.rb, line 81
81: def self.alias_state(values)
82: @state_aliases ||= {}
83: values.each do |nick, name|
84: @state_aliases[nick] = name
85: end
86: end
# File lib/puppet/type/zone.rb, line 88
88: def self.newvalue(name, hash)
89: if @parametervalues.is_a? Hash
90: @parametervalues = []
91: end
92:
93: @parametervalues << name
94:
95: @states[name] = hash
96: hash[:name] = name
97: end
# File lib/puppet/type/zone.rb, line 116
116: def self.state_index(value)
117: @parametervalues.index(state_name(value))
118: end
# File lib/puppet/type/zone.rb, line 99
99: def self.state_name(name)
100: if other = @state_aliases[name]
101: other
102: else
103: name
104: end
105: end
Return all of the states between two listed values, exclusive of the first item.
# File lib/puppet/type/zone.rb, line 122
122: def self.state_sequence(first, second)
123: findex = sindex = nil
124: unless findex = @parametervalues.index(state_name(first))
125: raise ArgumentError, "'%s' is not a valid zone state" % first
126: end
127: unless sindex = @parametervalues.index(state_name(second))
128: raise ArgumentError, "'%s' is not a valid zone state" % first
129: end
130: list = nil
131:
132: # Apparently ranges are unidirectional, so we have to reverse
133: # the range op twice.
134: if findex > sindex
135: list = @parametervalues[sindex..findex].collect do |name|
136: @states[name]
137: end.reverse
138: else
139: list = @parametervalues[findex..sindex].collect do |name|
140: @states[name]
141: end
142: end
143:
144: # The first result is the current state, so don't return it.
145: list[1..-1]
146: end
Add an interface.
# File lib/puppet/type/zone.rb, line 223
223: def add(str)
224: interface, ip = ipsplit(str)
225: "add net
226: set address=#{ip}
227: set physical=#{interface}
228: end
229: "
230: end
Add a directory to our list of inherited directories.
# File lib/puppet/type/zone.rb, line 288
288: def add(dir)
289: "add inherit-pkg-dir\nset dir=#{dir}\nend"
290: end
# File lib/puppet/type/zone.rb, line 272
272: def configtext
273: "add rctl\nset name=zone.cpu-shares\nadd value (priv=privileged,limit=#{self.should},action=none)\nend"
274: end
# File lib/puppet/type/zone.rb, line 256
256: def configtext
257: "set autoboot=#{self.should}"
258: end
# File lib/puppet/type/zone.rb, line 264
264: def configtext
265: "set pool=#{self.should}"
266: end
Convert a string into the component interface and address
# File lib/puppet/type/zone.rb, line 233
233: def ipsplit(str)
234: interface, address = str.split(':')
235: return interface, address
236: end
# File lib/puppet/type/zone.rb, line 382
382: def retrieve
383: provider.flush
384: if hash = provider.properties() and hash[:ensure] != :absent
385: result = setstatus(hash)
386: result
387: else
388: # Return all properties as absent.
389: return properties().inject({}) do | prophash, property|
390: prophash[property] = :absent
391: prophash
392: end
393: end
394: end
# File lib/puppet/type/zone.rb, line 148
148: def retrieve
149: provider.properties[:ensure]
150: end
Remove an interface.
# File lib/puppet/type/zone.rb, line 239
239: def rm(str)
240: interface, ip = ipsplit(str)
241: # Reality seems to disagree with the documentation here; the docs
242: # specify that braces are required, but they're apparently only
243: # required if you're specifying multiple values.
244: "remove net address=#{ip}"
245: end
# File lib/puppet/type/zone.rb, line 292
292: def rm(dir)
293: # Reality seems to disagree with the documentation here; the docs
294: # specify that braces are required, but they're apparently only
295: # required if you're specifying multiple values.
296: "remove inherit-pkg-dir dir=#{dir}"
297: end
Take the results of a listing and set everything appropriately.
# File lib/puppet/type/zone.rb, line 397
397: def setstatus(hash)
398: prophash = {}
399: hash.each do |param, value|
400: next if param == :name
401: case self.class.attrtype(param)
402: when :property:
403: # Only try to provide values for the properties we're managing
404: if prop = self.property(param)
405: prophash[prop] = value
406: end
407: else
408: self[param] = value
409: end
410: end
411: return prophash
412: end
# File lib/puppet/type/zone.rb, line 152
152: def sync
153: method = nil
154: if up?
155: direction = :up
156: else
157: direction = :down
158: end
159:
160: # We need to get the state we're currently in and just call
161: # everything between it and us.
162: self.class.state_sequence(self.retrieve, self.should).each do |state|
163: if method = state[direction]
164: warned = false
165: while provider.processing?
166: unless warned
167: info "Waiting for zone to finish processing"
168: warned = true
169: end
170: sleep 1
171: end
172: provider.send(method)
173: else
174: raise Puppet::DevError, "Cannot move %s from %s" %
175: [direction, st[:name]]
176: end
177: end
178:
179: return ("zone_" + self.should.to_s).intern
180: end