Class: Puppet::Indirector::ResourceType::Parser
- Defined in:
- lib/puppet/indirector/resource_type/parser.rb
Overview
The main terminus for Puppet::Resource::Type
This exposes the known resource types from within Puppet. Only find and search are supported. When a request is received, Puppet will attempt to load all resource types (by parsing manifests and modules) and returns a description of the resource types found. The format of these objects is documented at Resource::Type.
Constant Summary
Constants included from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE
Constants included from Util::POSIX
Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS
Constants included from Util::SymbolicFileMode
Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit
Constants included from Util::Docs
Instance Attribute Summary
Attributes included from Util::Docs
Instance Method Summary collapse
-
#find(request) ⇒ Puppet::Resource::Type?
Find will return the first resource_type with the given name.
- #resource_types_in(environment) ⇒ Object
-
#search(request) ⇒ Array<Puppet::Resource::Type>?
Search for resource types using a regular expression.
Methods inherited from Terminus
abstract_terminus?, #allow_remote_requests?, const2name, #indirection, indirection_name, inherited, #initialize, mark_as_abstract_terminus, model, #model, #name, name2const, register_terminus_class, terminus_class, terminus_classes, #terminus_type, #validate, #validate_key, #validate_model
Methods included from Util::InstanceLoader
#instance_docs, #instance_hash, #instance_load, #instance_loader, #instance_loading?, #loaded_instance, #loaded_instances
Methods included from Util
absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, deterministic_rand, execfail, execpipe, execute, exit_on_fail, logmethods, memory, path_to_uri, pretty_backtrace, proxy, replace_file, safe_posix_fork, symbolizehash, thinmark, uri_to_path, which, withenv, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::SymbolicFileMode
#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Methods included from Util::Docs
#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub
Constructor Details
This class inherits a constructor from Puppet::Indirector::Terminus
Instance Method Details
#find(request) ⇒ Puppet::Resource::Type?
Find will return the first resource_type with the given name. It is not possible to specify the kind of the resource type.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/puppet/indirector/resource_type/parser.rb', line 25 def find(request) Puppet.override(:squelch_parse_errors => true) do krt = resource_types_in(request.environment) # This is a bit ugly. [:hostclass, :definition, :node].each do |type| # 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 nil end end |
#resource_types_in(environment) ⇒ Object
97 98 99 100 |
# File 'lib/puppet/indirector/resource_type/parser.rb', line 97 def resource_types_in(environment) environment.check_for_reparse environment.known_resource_types end |
#search(request) ⇒ Array<Puppet::Resource::Type>?
Search for resource types using a regular expression. Unlike ‘find`, this allows you to filter the results by the “kind” of the resource type (“class”, “defined_type”, or “node”). All three are searched if no `kind` filter is given. This also accepts the special string “`*`” to return all resource type objects.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/puppet/indirector/resource_type/parser.rb', line 57 def search(request) Puppet.override(:squelch_parse_errors => true) do krt = resource_types_in(request.environment) # Make sure we've got all of the types loaded. krt.loader.import_all result_candidates = case request.[:kind] when "class" krt.hostclasses.values when "defined_type" krt.definitions.values when "node" krt.nodes.values when nil result_candidates = [krt.hostclasses.values, krt.definitions.values, krt.nodes.values] else raise ArgumentError, "Unrecognized kind filter: " + "'#{request.[:kind]}', expected one " + " of 'class', 'defined_type', or 'node'." end result = result_candidates.flatten.reject { |t| t.name == "" } return nil if result.empty? return result if request.key == "*" # Strip the regex of any wrapping slashes that might exist key = request.key.sub(/^\//, '').sub(/\/$/, '') begin regex = Regexp.new(key) rescue => detail raise ArgumentError, "Invalid regex '#{request.key}': #{detail}", detail.backtrace end result.reject! { |t| t.name.to_s !~ regex } return nil if result.empty? result end end |