lib/puppet/provider/zone/solaris.rb in puppet-0.22.4 vs lib/puppet/provider/zone/solaris.rb in puppet-0.23.0

- old
+ new

@@ -2,53 +2,48 @@ desc "Provider for Solaris Zones." commands :adm => "/usr/sbin/zoneadm", :cfg => "/usr/sbin/zonecfg" defaultfor :operatingsystem => :solaris + mk_resource_methods + # Convert the output of a list into a hash def self.line2hash(line) fields = [:id, :name, :ensure, :path] - hash = {} + properties = {} line.split(":").each_with_index { |value, index| - hash[fields[index]] = value + properties[fields[index]] = value } # Configured but not installed zones do not have IDs - if hash[:id] == "-" - hash.delete(:id) + if properties[:id] == "-" + properties.delete(:id) end - return hash + properties[:ensure] = symbolize(properties[:ensure]) + + return properties end - def self.list + def self.instances adm(:list, "-cp").split("\n").collect do |line| - hash = line2hash(line) - - obj = nil - unless obj = @model[hash[:name]] - obj = @model.create(:name => hash[:name]) - end - - obj.setstatus(hash) - - obj + new(line2hash(line)) end end # Perform all of our configuration steps. def configure # If the thing is entirely absent, then we need to create the config. str = %{create -b set zonepath=%s -} % @model[:path] +} % @resource[:path] # Then perform all of our configuration steps. It's annoying - # that we need this much internal info on the model. - @model.send(:properties).each do |property| - if property.is_a? ZoneConfigProperty and ! property.insync? + # that we need this much internal info on the resource. + @resource.send(:properties).each do |property| + if property.is_a? ZoneConfigProperty and ! property.insync?(properties[property.name]) str += property.configtext + "\n" end end str += "commit\n" @@ -57,18 +52,43 @@ def destroy zonecfg :delete, "-F" end + def exists? + properties[:ensure] != :absent + end + + # Clear out the cached values. + def flush + @property_hash.clear + end + def install zoneadm :install end + # Look up the current status. + def properties + if @property_hash.empty? + @property_hash = status || {} + if @property_hash.empty? + @property_hash[:ensure] = :absent + else + @resource.class.validproperties.each do |name| + @property_hash[name] ||= :absent + end + end + + end + @property_hash.dup + end + # We need a way to test whether a zone is in process. Our 'ensure' # property models the static states, but we need to handle the temporary ones. def processing? - if hash = statushash() + if hash = status() case hash[:ensure] when "incomplete", "ready", "shutting_down" true else false @@ -90,11 +110,10 @@ when /^(\S+):\s*$/: name = $1 current = nil # reset it when /^(\S+):\s*(.+)$/: hash[$1.intern] = $2 - #self.is = [$1.intern, $2] when /^\s+(\S+):\s*(.+)$/: if name unless hash.include? name hash[name] = [] end @@ -109,31 +128,19 @@ end else debug "Ignoring zone output '%s'" % line end end + return hash end - def retrieve - if hash = statushash() - setstatus(hash) - - # Now retrieve the configuration itself and set appropriately. - getconfig() - else - @properties.each do |name, property| - property.is = :absent - end - end - end - # Execute a configuration string. Can't be private because it's called # by the properties. def setconfig(str) - command = "#{command(:cfg)} -z %s -f -" % @model[:name] - debug "Executing '%s' in zone %s with '%s'" % [command, @model[:name], str] + command = "#{command(:cfg)} -z %s -f -" % @resource[:name] + debug "Executing '%s' in zone %s with '%s'" % [command, @resource[:name], str] IO.popen(command, "w") do |pipe| pipe.puts str end unless $? == 0 @@ -141,12 +148,12 @@ end end def start # Check the sysidcfg stuff - if cfg = @model[:sysidcfg] - path = File.join(@model[:path], "root", "etc", "sysidcfg") + if cfg = @resource[:sysidcfg] + path = File.join(@resource[:path], "root", "etc", "sysidcfg") unless File.exists?(path) begin File.open(path, "w", 0600) do |f| f.puts cfg @@ -162,18 +169,25 @@ zoneadm :boot end # Return a hash of the current status of this zone. - def statushash + def status begin - output = adm "-z", @model[:name], :list, "-p" + output = adm "-z", @resource[:name], :list, "-p" rescue Puppet::ExecutionFailure return nil end - return self.class.line2hash(output.chomp) + main = self.class.line2hash(output.chomp) + + # Now add in the configuration information + config_status.each do |name, value| + main[name] = value + end + + main end def stop zoneadm :halt end @@ -186,23 +200,44 @@ zoneadm :uninstall, "-F" end private + # Turn the results of getconfig into status information. + def config_status + config = getconfig() + result = {} + + result[:autoboot] = config[:autoboot] ? config[:autoboot].intern : :absent + result[:pool] = config[:pool] + result[:shares] = config[:shares] + if dir = config["inherit-pkg-dir"] + result[:inherit] = dir.collect { |dirs| dirs[:dir] } + end + if net = config["net"] + result[:ip] = net.collect { |params| "%s:%s" % [params[:physical], params[:address]] } + end + + result + end + def zoneadm(*cmd) begin - adm("-z", @model[:name], *cmd) + adm("-z", @resource[:name], *cmd) rescue Puppet::ExecutionFailure => detail self.fail "Could not %s zone: %s" % [cmd[0], detail] end end def zonecfg(*cmd) + # You apparently can't get the configuration of the global zone + return "" if self.name == "global" + begin - cfg("-z", @model[:name], *cmd) + cfg("-z", self.name, *cmd) rescue Puppet::ExecutionFailure => detail self.fail "Could not %s zone: %s" % [cmd[0], detail] end end end -# $Id: solaris.rb 2169 2007-02-07 06:47:10Z luke $ +# $Id: solaris.rb 2577 2007-06-14 03:39:23Z luke $