diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2010-07-28 14:54:23 -0700 |
|---|---|---|
| committer | Jesse Wolfe <jes5199@gmail.com> | 2010-07-30 14:28:31 -0700 |
| commit | 6dbd4771265173a9d4c3e7756c35c9ca371ca394 (patch) | |
| tree | 835faf9ed49da69b9d2059ed1ebba8cde485d21d /lib/puppet/parser | |
| parent | 871e6fd58223cad241bcc14f165b3ab1e6e257e6 (diff) | |
| download | puppet-6dbd4771265173a9d4c3e7756c35c9ca371ca394.tar.gz puppet-6dbd4771265173a9d4c3e7756c35c9ca371ca394.tar.xz puppet-6dbd4771265173a9d4c3e7756c35c9ca371ca394.zip | |
[#4397]+[#4344] Move type-name resolution out of Puppet::Resource into the AST resources.
Move type-name resolution out of Puppet::Resource into the AST resources.
Move find_resource_type out of Puppet::Resource into Scope
Thus, never pass unqualified type names to Puppet::Resource objects.
Thus, Puppet::Resource objects don't need the namespace property,
and Puppet::Resource objects never consult the harddrive to look for
.pp files that might contain their type definitions,
Thus, performance is improved.
Also removes the temporary fix for #4257 that caused #4397
(The code was too eager to look for a class in the topscope)
Paired-With: Paul Berry <paul@puppetlabs.com>
Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
Diffstat (limited to 'lib/puppet/parser')
| -rw-r--r-- | lib/puppet/parser/ast/resource.rb | 6 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/resource_reference.rb | 25 | ||||
| -rw-r--r-- | lib/puppet/parser/resource.rb | 6 | ||||
| -rw-r--r-- | lib/puppet/parser/scope.rb | 14 |
4 files changed, 41 insertions, 10 deletions
diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb index 1b063c984..9149b06c3 100644 --- a/lib/puppet/parser/ast/resource.rb +++ b/lib/puppet/parser/ast/resource.rb @@ -33,11 +33,11 @@ class Resource < AST::ResourceReference # This is where our implicit iteration takes place; if someone # passed an array as the name, then we act just like the called us # many times. + resource_type = scope.find_resource_type(type) resource_titles.flatten.collect { |resource_title| exceptwrap :type => Puppet::ParseError do - - resource = Puppet::Parser::Resource.new( - type, resource_title, + resource = Puppet::Parser::Resource.new( + resource_type.name, resource_title, :parameters => paramobjects, :file => self.file, :line => self.line, diff --git a/lib/puppet/parser/ast/resource_reference.rb b/lib/puppet/parser/ast/resource_reference.rb index 5d8334335..5b1b0aa3a 100644 --- a/lib/puppet/parser/ast/resource_reference.rb +++ b/lib/puppet/parser/ast/resource_reference.rb @@ -7,8 +7,29 @@ class Puppet::Parser::AST::ResourceReference < Puppet::Parser::AST::Branch # Evaluate our object, but just return a simple array of the type # and name. def evaluate(scope) - titles = Array(title.safeevaluate(scope)).collect { |t| Puppet::Resource.new(type, t, :namespaces => scope.namespaces) } - return(titles.length == 1 ? titles.pop : titles) + a_type = type + titles = Array(title.safeevaluate(scope)) + + case type.downcase + when "class" + # resolve the titles + titles = titles.collect do |a_title| + hostclass = scope.find_hostclass(a_title) + hostclass ? hostclass.name : a_title + end + when "node" + # no-op + else + # resolve the type + resource_type = scope.find_resource_type(type) + a_type = resource_type.name if resource_type + end + + resources = titles.collect{ |a_title| + Puppet::Resource.new(a_type, a_title) + } + + return(resources.length == 1 ? resources.pop : resources) end def to_s diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index 3c451929e..8a5ae886c 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -102,9 +102,9 @@ class Puppet::Parser::Resource < Puppet::Resource end def initialize(*args) + raise ArgumentError, "Resources require a scope" unless args.last[:scope] super - raise ArgumentError, "Resources require a scope" unless scope @source ||= scope.source end @@ -140,10 +140,6 @@ class Puppet::Parser::Resource < Puppet::Resource self[:name] || self.title end - def namespaces - scope.namespaces - end - # A temporary occasion, until I get paths in the scopes figured out. def path to_s diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index ae0f9ea4a..2ca28d824 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -474,6 +474,20 @@ class Puppet::Parser::Scope end end + def find_resource_type(type) + # It still works fine without the type == 'class' short-cut, but it is a lot slower. + return nil if ["class", "node"].include? type.to_s.downcase + find_builtin_resource_type(type) || find_defined_resource_type(type) + end + + def find_builtin_resource_type(type) + Puppet::Type.type(type.to_s.downcase.to_sym) + end + + def find_defined_resource_type(type) + environment.known_resource_types.find_definition(namespaces, type.to_s.downcase) + end + private def extend_with_functions_module |
