diff options
| author | Luke Kanies <luke@puppetlabs.com> | 2011-03-25 14:34:18 -0700 |
|---|---|---|
| committer | Luke Kanies <luke@puppetlabs.com> | 2011-03-25 14:34:18 -0700 |
| commit | de2e84eb93416cebe6d5a92ee88ba9c98cd52661 (patch) | |
| tree | 9f3965b14998a7f26ace494a211cac01a10999bb /lib/puppet | |
| parent | 072baff5b5cec91d31a581d416225b70f425b2f0 (diff) | |
| parent | e16a38349c596c4a6ea682173e0cc704dedc98a7 (diff) | |
| download | puppet-de2e84eb93416cebe6d5a92ee88ba9c98cd52661.tar.gz puppet-de2e84eb93416cebe6d5a92ee88ba9c98cd52661.tar.xz puppet-de2e84eb93416cebe6d5a92ee88ba9c98cd52661.zip | |
Merge branch 'tickets/master/6850-resource_type_listing_and_converting' into next
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/indirector/resource_type/parser.rb | 9 | ||||
| -rw-r--r-- | lib/puppet/module.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/parser/type_loader.rb | 28 | ||||
| -rw-r--r-- | lib/puppet/resource/type.rb | 6 |
4 files changed, 39 insertions, 6 deletions
diff --git a/lib/puppet/indirector/resource_type/parser.rb b/lib/puppet/indirector/resource_type/parser.rb index 8b1bed0a9..fd5b3938a 100644 --- a/lib/puppet/indirector/resource_type/parser.rb +++ b/lib/puppet/indirector/resource_type/parser.rb @@ -10,7 +10,10 @@ class Puppet::Indirector::ResourceType::Parser < Puppet::Indirector::Code # This is a bit ugly. [:hostclass, :definition, :node].each do |type| - if r = krt.send(type, request.key) + # We have to us 'find_<type>' here because it will + # load any missing types from disk, whereas the plain + # '<type>' method only returns from memory. + if r = krt.send("find_#{type}", [""], request.key) return r end end @@ -20,7 +23,9 @@ class Puppet::Indirector::ResourceType::Parser < Puppet::Indirector::Code def search(request) raise ArgumentError, "Only '*' is acceptable as a search request" unless request.key == "*" krt = request.environment.known_resource_types - result = [krt.hostclasses.values, krt.definitions.values, krt.nodes.values].flatten + # Make sure we've got all of the types loaded. + krt.loader.import_all + result = [krt.hostclasses.values, krt.definitions.values, krt.nodes.values].flatten.reject { |t| t.name == "" } return nil if result.empty? result end diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb index 43266b2b5..059591ed8 100644 --- a/lib/puppet/module.rb +++ b/lib/puppet/module.rb @@ -138,7 +138,7 @@ class Puppet::Module # Find this module in the modulepath. def path - environment.modulepath.collect { |path| File.join(path, name) }.find { |d| FileTest.exist?(d) } + environment.modulepath.collect { |path| File.join(path, name) }.find { |d| FileTest.directory?(d) } end # Find all plugin directories. This is used by the Plugins fileserving mount. diff --git a/lib/puppet/parser/type_loader.rb b/lib/puppet/parser/type_loader.rb index 140c9f2ca..1fba73d0b 100644 --- a/lib/puppet/parser/type_loader.rb +++ b/lib/puppet/parser/type_loader.rb @@ -92,6 +92,34 @@ class Puppet::Parser::TypeLoader end end + def import_all + require 'find' + + module_names = [] + # Collect the list of all known modules + environment.modulepath.each do |path| + Dir.chdir(path) do + Dir.glob("*").each do |dir| + next unless FileTest.directory?(dir) + module_names << dir + end + end + end + + module_names.uniq! + # And then load all files from each module, but (relying on system + # behavior) only load files from the first module of a given name. E.g., + # given first/foo and second/foo, only files from first/foo will be loaded. + module_names.each do |name| + mod = Puppet::Module.new(name, environment) + Find.find(File.join(mod.path, "manifests")) do |path| + if path =~ /\.pp$/ or path =~ /\.rb$/ + import(path) + end + end + end + end + def known_resource_types environment.known_resource_types end diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index b9cf6991a..48d8c1f48 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -34,13 +34,13 @@ class Puppet::Resource::Type end def to_pson_data_hash - data = [:code, :doc, :line, :file, :parent].inject({}) do |hash, param| - next hash unless value = self.send(param) + data = [:doc, :line, :file, :parent].inject({}) do |hash, param| + next hash unless (value = self.send(param)) and (value != "") hash[param.to_s] = value hash end - data['arguments'] = arguments.dup + data['arguments'] = arguments.dup unless arguments.empty? data['name'] = name data['type'] = type |
