diff options
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/parser/collector.rb | 6 | ||||
-rw-r--r-- | lib/puppet/parser/resource.rb | 4 | ||||
-rw-r--r-- | lib/puppet/reports/store.rb | 3 | ||||
-rw-r--r-- | lib/puppet/resource.rb | 52 | ||||
-rw-r--r-- | lib/puppet/util/rails/reference_serializer.rb | 2 |
5 files changed, 47 insertions, 20 deletions
diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb index 044518793..67bd336bb 100644 --- a/lib/puppet/parser/collector.rb +++ b/lib/puppet/parser/collector.rb @@ -41,9 +41,7 @@ class Puppet::Parser::Collector # overrided those resources objects.each do |res| unless @collected.include?(res.ref) - res = Puppet::Parser::Resource.new( - :type => res.type, - :title => res.title, + newres = Puppet::Parser::Resource.new(res.type, res.title, :params => overrides[:params], :file => overrides[:file], :line => overrides[:line], @@ -51,7 +49,7 @@ class Puppet::Parser::Collector :scope => overrides[:scope] ) - scope.compiler.add_override(res) + scope.compiler.add_override(newres) end end end diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index 36f1fbe93..3f6d73df3 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -108,7 +108,9 @@ class Puppet::Parser::Resource < Puppet::Resource end def initialize(type, title, options) - self.type = type + @scope = options[:scope] + + self.relative_type = type self.title = title @params = {} diff --git a/lib/puppet/reports/store.rb b/lib/puppet/reports/store.rb index 04eff82f9..a74527566 100644 --- a/lib/puppet/reports/store.rb +++ b/lib/puppet/reports/store.rb @@ -18,7 +18,8 @@ Puppet::Reports.register_report(:store) do :desc => "Client dir for %s" % client, :owner => 'service', :group => 'service' - } + }, + :noop => [false, "Used by settings internally."] ) config.use("reportclient-#{client}".to_sym) diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index ec1fd2eae..630e8a823 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -13,7 +13,8 @@ class Puppet::Resource extend Puppet::Util::Pson include Enumerable attr_accessor :file, :line, :catalog, :exported, :virtual, :validate_parameters - attr_reader :type, :title, :namespaces + attr_reader :title, :namespaces + attr_writer :relative_type require 'puppet/indirector' extend Puppet::Indirector @@ -145,8 +146,6 @@ class Puppet::Resource # Create our resource. def initialize(type, title = nil, attributes = {}) - self.type, self.title = extract_type_and_title(type, title) - @parameters = {} @namespaces = [""] @@ -159,6 +158,13 @@ class Puppet::Resource send(attr.to_s + "=", value) end + # We do namespaces first, and use tmp variables, so our title + # canonicalization works (i.e., namespaces are set and resource + # types can be looked up) + tmp_type, tmp_title = extract_type_and_title(type, title) + self.type = tmp_type + self.title = tmp_title + tag(self.type) tag(self.title) if valid_tag?(self.title) end @@ -174,14 +180,19 @@ class Puppet::Resource end def title=(value) - if @type and klass = Puppet::Type.type(@type.to_s.downcase) + if klass = resource_type and klass.respond_to?(:canonicalize_ref) value = klass.canonicalize_ref(value) end @title = value end + # Canonize the type so we know it's always consistent. + def relative_type + munge_type_name(@relative_type) + end + def resource_type - case type.to_s.downcase + case relative_type.to_s.downcase when "class"; find_hostclass when "node"; find_node else @@ -290,13 +301,18 @@ class Puppet::Resource self end - # Canonize the type so we know it's always consistent. - def type=(value) - if value.nil? or value.to_s.downcase == "component" - @type = "Class" + def type + munge_type_name(if r = resource_type + resource_type.name else - @type = value.to_s.split("::").collect { |s| s.capitalize }.join("::") - end + relative_type + end) + end + + # Only allow people to set the relative type, + # so we force it to be looked up each time. + def type=(value) + @relative_type = value end def valid_parameter?(name) @@ -319,11 +335,11 @@ class Puppet::Resource end def find_builtin_resource_type - Puppet::Type.type(type.to_s.downcase.to_sym) + Puppet::Type.type(relative_type.to_s.downcase.to_sym) end def find_defined_resource_type - known_resource_types.find_definition(namespaces, type.to_s.downcase) + known_resource_types.find_definition(namespaces, relative_type.to_s.downcase) end # Produce a canonical method name. @@ -369,4 +385,14 @@ class Puppet::Resource else raise ArgumentError, "No title provided and #{argtype.inspect} is not a valid resource reference" end end + + def munge_type_name(value) + return :main if value == "" + + if value.nil? or value.to_s.downcase == "component" + "Class" + else + value.to_s.split("::").collect { |s| s.capitalize }.join("::") + end + end end diff --git a/lib/puppet/util/rails/reference_serializer.rb b/lib/puppet/util/rails/reference_serializer.rb index 63f109cec..a23f2cbea 100644 --- a/lib/puppet/util/rails/reference_serializer.rb +++ b/lib/puppet/util/rails/reference_serializer.rb @@ -15,7 +15,7 @@ module Puppet::Util::ReferenceSerializer def serialize_value(val) case val - when Puppet::Parser::Resource::Reference + when Puppet::Resource YAML.dump(val) when true, false # The database does this for us, but I prefer the |