diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-02-07 06:47:10 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-02-07 06:47:10 +0000 |
commit | d4031312ecddc6fab15b5bc9693b8af0a23a57b8 (patch) | |
tree | ba48576ea294a4a72201a18e093bca4d6ce1537d /lib/puppet/provider | |
parent | f6f72f2288e3e3427abf0883a7ec507becc90f08 (diff) | |
download | puppet-d4031312ecddc6fab15b5bc9693b8af0a23a57b8.tar.gz puppet-d4031312ecddc6fab15b5bc9693b8af0a23a57b8.tar.xz puppet-d4031312ecddc6fab15b5bc9693b8af0a23a57b8.zip |
Merging the state-rename branch. This includes the diff from version 2156 to 2168. All states should now be properties, with backward compatibility for the types that restricted themselves to the methods.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2169 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/provider')
-rw-r--r-- | lib/puppet/provider/nameservice.rb | 16 | ||||
-rw-r--r-- | lib/puppet/provider/nameservice/netinfo.rb | 18 | ||||
-rw-r--r-- | lib/puppet/provider/package/up2date.rb | 2 | ||||
-rwxr-xr-x | lib/puppet/provider/parsedfile.rb | 50 | ||||
-rw-r--r-- | lib/puppet/provider/user/pw.rb | 8 | ||||
-rw-r--r-- | lib/puppet/provider/user/useradd.rb | 8 | ||||
-rw-r--r-- | lib/puppet/provider/zone/solaris.rb | 14 |
7 files changed, 57 insertions, 59 deletions
diff --git a/lib/puppet/provider/nameservice.rb b/lib/puppet/provider/nameservice.rb index dc4aadcc9..377393973 100644 --- a/lib/puppet/provider/nameservice.rb +++ b/lib/puppet/provider/nameservice.rb @@ -24,7 +24,7 @@ class Puppet::Provider::NameService < Puppet::Provider objects = [] listbyname do |name| obj = nil - check = model.validstates + check = model.validproperties if obj = model[name] obj[:check] = check else @@ -119,8 +119,8 @@ class Puppet::Provider::NameService < Puppet::Provider private - def op(state) - @ops[state.name] || ("-" + state.name) + def op(property) + @ops[property.name] || ("-" + property.name) end end @@ -202,7 +202,7 @@ class Puppet::Provider::NameService < Puppet::Provider return nil end - # again, needs to be set by the ind. state or its + # again, needs to be set by the ind. property or its # parent cmd = self.deletecmd type = "delete" @@ -293,7 +293,7 @@ class Puppet::Provider::NameService < Puppet::Provider # Convert the Etc struct into a hash. def info2hash(info) hash = {} - self.class.model.validstates.each do |param| + self.class.model.validproperties.each do |param| method = posixmethod(param) if info.respond_to? method hash[param] = info.send(posixmethod(param)) @@ -313,10 +313,10 @@ class Puppet::Provider::NameService < Puppet::Provider def method_missing(name, *args) name = name.to_s - # Make sure it's a valid state. We go up our class structure instead of + # Make sure it's a valid property. We go up our class structure instead of # our model's because the model is fake during testing. - unless self.class.model.validstate?(name.sub("=",'')) - raise Puppet::DevError, "%s is not a valid %s state" % + unless self.class.model.validproperty?(name.sub("=",'')) + raise Puppet::DevError, "%s is not a valid %s property" % [name, @model.class.name] end diff --git a/lib/puppet/provider/nameservice/netinfo.rb b/lib/puppet/provider/nameservice/netinfo.rb index b5e3d0536..134ef37e9 100644 --- a/lib/puppet/provider/nameservice/netinfo.rb +++ b/lib/puppet/provider/nameservice/netinfo.rb @@ -62,7 +62,7 @@ class NetInfo < Puppet::Provider::NameService end def self.list - report(@model.validstates).collect do |hash| + report(@model.validproperties).collect do |hash| @model.hash2obj(hash) end end @@ -92,7 +92,7 @@ class NetInfo < Puppet::Provider::NameService cmd << key.to_s else raise Puppet::DevError, - "Could not find netinfokey for state %s" % + "Could not find netinfokey for property %s" % self.class.name end end @@ -136,7 +136,7 @@ class NetInfo < Puppet::Provider::NameService # Because our stupid type can't create the whole thing at once, # we have to do this hackishness. Yay. if arg == :present - @model.class.validstates.each do |name| + @model.class.validproperties.each do |name| next if name == :ensure next unless val = @model.should(name) || autogen(name) self.send(name.to_s + "=", val) @@ -157,9 +157,9 @@ class NetInfo < Puppet::Provider::NameService # Retrieve everything about this object at once, instead of separately. def getinfo(refresh = false) if refresh or (! defined? @infohash or ! @infohash) - states = [:name] + self.class.model.validstates - states.delete(:ensure) if states.include? :ensure - @infohash = single_report(*states) + properties = [:name] + self.class.model.validproperties + properties.delete(:ensure) if properties.include? :ensure + @infohash = single_report(*properties) end return @infohash @@ -179,7 +179,7 @@ class NetInfo < Puppet::Provider::NameService cmd += value else raise Puppet::DevError, - "Could not find netinfokey for state %s" % + "Could not find netinfokey for property %s" % self.class.name end cmd @@ -191,8 +191,8 @@ class NetInfo < Puppet::Provider::NameService end # Get a report for a single resource, not the whole table - def single_report(*states) - self.class.report(*states).find do |hash| hash[:name] == @model[:name] end + def single_report(*properties) + self.class.report(*properties).find do |hash| hash[:name] == @model[:name] end end def setuserlist(group, list) diff --git a/lib/puppet/provider/package/up2date.rb b/lib/puppet/provider/package/up2date.rb index 85a0ddde6..c11be0947 100644 --- a/lib/puppet/provider/package/up2date.rb +++ b/lib/puppet/provider/package/up2date.rb @@ -9,8 +9,6 @@ Puppet.type(:package).provide :up2date, :parent => :rpm do def install up2date "-u", @model[:name] - #@states[:ensure].retrieve - #if @states[:ensure].is == :absent unless self.query raise Puppet::ExecutionFailure.new( "Could not find package %s" % self.name diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb index ddb18ff17..a685c7250 100755 --- a/lib/puppet/provider/parsedfile.rb +++ b/lib/puppet/provider/parsedfile.rb @@ -17,7 +17,7 @@ class Puppet::Provider::ParsedFile < Puppet::Provider attr_accessor :default_target, :target end - attr_accessor :state_hash + attr_accessor :property_hash def self.clean(hash) newhash = hash.dup @@ -119,14 +119,14 @@ class Puppet::Provider::ParsedFile < Puppet::Provider # Create attribute methods for each of the model's non-metaparam attributes. def self.model=(model) - [model.validstates, model.parameters].flatten.each do |attr| + [model.validproperties, model.parameters].flatten.each do |attr| attr = symbolize(attr) define_method(attr) do # If it's not a valid field for this record type (which can happen # when different platforms support different fields), then just # return the should value, so the model shuts up. - if @state_hash[attr] or self.class.valid_attr?(self.class.name, attr) - @state_hash[attr] || :absent + if @property_hash[attr] or self.class.valid_attr?(self.class.name, attr) + @property_hash[attr] || :absent else @model.should(attr) end @@ -137,19 +137,19 @@ class Puppet::Provider::ParsedFile < Puppet::Provider modeltarget = @model[:target] || self.class.default_target # If they're the same, then just mark that one as modified - if @state_hash[:target] and @state_hash[:target] == modeltarget + if @property_hash[:target] and @property_hash[:target] == modeltarget self.class.modified(modeltarget) else # Always mark the modeltarget as modified, and if there's - # and old state_hash target, mark it as modified and replace + # and old property_hash target, mark it as modified and replace # it. self.class.modified(modeltarget) - if @state_hash[:target] - self.class.modified(@state_hash[:target]) + if @property_hash[:target] + self.class.modified(@property_hash[:target]) end - @state_hash[:target] = modeltarget + @property_hash[:target] = modeltarget end - @state_hash[attr] = val + @property_hash[attr] = val end end @model = model @@ -185,16 +185,16 @@ class Puppet::Provider::ParsedFile < Puppet::Provider r[:ensure] = :present end - # Set current state on any existing resource instances. + # Set current property on any existing resource instances. target_records(target).find_all { |i| i.is_a?(Hash) }.each do |record| # Find any model instances whose names match our instances. if instance = self.model[record[:name]] next unless instance.provider.is_a?(self) - instance.provider.state_hash = record + instance.provider.property_hash = record elsif self.respond_to?(:match) if instance = self.match(record) record[:name] = instance[:name] - instance.provider.state_hash = record + instance.provider.property_hash = record end end end @@ -260,12 +260,12 @@ class Puppet::Provider::ParsedFile < Puppet::Provider end def create - @model.class.validstates.each do |state| - if value = @model.should(state) - @state_hash[state] = value + @model.class.validproperties.each do |property| + if value = @model.should(property) + @property_hash[property] = value end end - self.class.modified(@state_hash[:target] || self.class.default_target) + self.class.modified(@property_hash[:target] || self.class.default_target) return (@model.class.name.to_s + "_created").intern end @@ -276,7 +276,7 @@ class Puppet::Provider::ParsedFile < Puppet::Provider end def exists? - if @state_hash[:ensure] == :absent or @state_hash[:ensure].nil? + if @property_hash[:ensure] == :absent or @property_hash[:ensure].nil? return false else return true @@ -289,24 +289,24 @@ class Puppet::Provider::ParsedFile < Puppet::Provider # If the target isn't set, then this is our first modification, so # mark it for flushing. - unless @state_hash[:target] - @state_hash[:target] = @model[:target] || self.class.default_target - self.class.modified(@state_hash[:target]) + unless @property_hash[:target] + @property_hash[:target] = @model[:target] || self.class.default_target + self.class.modified(@property_hash[:target]) end - @state_hash[:name] ||= @model.name + @property_hash[:name] ||= @model.name - self.class.flush(@state_hash) + self.class.flush(@property_hash) end def initialize(model) super - # See if there's already a matching state_hash in the records list; + # See if there's already a matching property_hash in the records list; # else, use a default value. # We provide a default for 'ensure' here, because the provider will # override it if the thing exists, but it won't touch it if it doesn't # exist. - @state_hash = self.class.record?(model[:name]) || + @property_hash = self.class.record?(model[:name]) || {:record_type => self.class.name, :ensure => :absent} end end diff --git a/lib/puppet/provider/user/pw.rb b/lib/puppet/provider/user/pw.rb index bc81e5ce5..9b85a22f9 100644 --- a/lib/puppet/provider/user/pw.rb +++ b/lib/puppet/provider/user/pw.rb @@ -21,12 +21,12 @@ Puppet::Type.type(:user).provide :pw, :parent => Puppet::Provider::NameService:: def addcmd cmd = [command(:pw), "useradd", @model[:name]] - @model.class.validstates.each do |state| - next if state == :ensure + @model.class.validproperties.each do |property| + next if property == :ensure # the value needs to be quoted, mostly because -c might # have spaces in it - if value = @model.should(state) and value != "" - cmd << flag(state) << value + if value = @model.should(property) and value != "" + cmd << flag(property) << value end end diff --git a/lib/puppet/provider/user/useradd.rb b/lib/puppet/provider/user/useradd.rb index d8adb8c69..55cc2d5dd 100644 --- a/lib/puppet/provider/user/useradd.rb +++ b/lib/puppet/provider/user/useradd.rb @@ -19,12 +19,12 @@ Puppet::Type.type(:user).provide :useradd, :parent => Puppet::Provider::NameServ def addcmd cmd = [command(:add)] - @model.class.validstates.each do |state| - next if state == :ensure + @model.class.validproperties.each do |property| + next if property == :ensure # the value needs to be quoted, mostly because -c might # have spaces in it - if value = @model.should(state) and value != "" - cmd << flag(state) << value + if value = @model.should(property) and value != "" + cmd << flag(property) << value end end # stupid fedora diff --git a/lib/puppet/provider/zone/solaris.rb b/lib/puppet/provider/zone/solaris.rb index e4871f812..572f137b0 100644 --- a/lib/puppet/provider/zone/solaris.rb +++ b/lib/puppet/provider/zone/solaris.rb @@ -45,9 +45,9 @@ set zonepath=%s # Then perform all of our configuration steps. It's annoying # that we need this much internal info on the model. - @model.send(:states).each do |state| - if state.is_a? ZoneConfigState and ! state.insync? - str += state.configtext + "\n" + @model.send(:properties).each do |property| + if property.is_a? ZoneConfigProperty and ! property.insync? + str += property.configtext + "\n" end end @@ -64,7 +64,7 @@ set zonepath=%s end # We need a way to test whether a zone is in process. Our 'ensure' - # state models the static states, but we need to handle the temporary ones. + # property models the static states, but we need to handle the temporary ones. def processing? if hash = statushash() case hash[:ensure] @@ -121,14 +121,14 @@ set zonepath=%s # Now retrieve the configuration itself and set appropriately. getconfig() else - @states.each do |name, state| - state.is = :absent + @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 states. + # 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] |