Class: Puppet::Parser::Resource
- Includes:
- YamlTrimmer, Resource::TypeCollectionHelper, Util, Util::Errors, Util::Logging, Util::MethodHelper
- Defined in:
- lib/puppet/parser/resource.rb
Overview
The primary difference between this class and its parent is that this class has rules on who can set parameters
Defined Under Namespace
Classes: Param
Constant Summary
Constants included from YamlTrimmer
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 inherited from Resource
Resource::ATTRIBUTES, Resource::Reference, Resource::YAML_ATTRIBUTES
Constants included from Indirector
Constants included from Util::Tagging
Instance Attribute Summary collapse
- #catalog ⇒ Object
- #collector_id ⇒ Object
- #evaluated ⇒ Object
- #exported ⇒ Object
- #file ⇒ Object
- #line ⇒ Object
- #override ⇒ Object
- #parameters ⇒ Object readonly
- #scope ⇒ Object
- #source ⇒ Object
- #translated ⇒ Object
- #virtual ⇒ Object
Attributes inherited from Resource
#strict, #title, #type, #validate_parameters
Class Method Summary collapse
-
.relationship_parameter?(name) ⇒ Boolean
Determine whether the provided parameter name is a relationship parameter.
Instance Method Summary collapse
- #[](param) ⇒ Object
-
#add_edge_to_stage ⇒ Object
Process the stage metaparameter for a class.
- #eachparam ⇒ Object
- #environment ⇒ Object
-
#evaluate ⇒ Object
Retrieve the associated definition and evaluate it.
- #evaluated? ⇒ Boolean
-
#finish ⇒ Object
Do any finishing work on this object, called before evaluation or before storage/translation.
-
#finished? ⇒ Boolean
Has this resource already been finished?.
-
#initialize(*args) ⇒ Resource
constructor
A new instance of Resource.
-
#isomorphic? ⇒ Boolean
Is this resource modeling an isomorphic resource type?.
-
#merge(resource) ⇒ Object
Merge an override resource in.
-
#metaparam_compatibility_mode? ⇒ Boolean
This only mattered for clients < 0.25, which we don’t support any longer.
- #name ⇒ Object
- #override? ⇒ Boolean
-
#raw_tagged?(tag_array) ⇒ Boolean
Answers if this resource is tagged with at least one of the tags given in downcased string form.
-
#set_parameter(param, value = nil) ⇒ Object
(also: #[]=)
Define a parameter in our resource.
- #to_hash ⇒ Object
-
#to_ral ⇒ Object
Convert this resource to a RAL resource.
-
#translated? ⇒ Boolean
Set up some boolean test methods.
Methods included from YamlTrimmer
Methods included from Util::Logging
#clear_deprecation_warnings, #deprecation_warning, #format_exception, #get_deprecation_offender, #log_and_raise, #log_deprecations_to_file, #log_exception, #puppet_deprecation_warning, #send_log
Methods included from Util::Errors
#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail
Methods included from Util::MethodHelper
#requiredopts, #set_options, #symbolize_options
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 Resource::TypeCollectionHelper
Methods inherited from Resource
#==, #builtin?, #builtin_type?, #class?, #copy_as_resource, #each, #environment=, from_data_hash, from_pson, #include?, #inspect, #key_attributes, #prune_parameters, #ref, #resolve, #resource_type, #resource_type=, #set_default_parameters, #stage?, #to_data_hash, #to_manifest, #to_pson, #to_pson_data_hash, #to_ref, #to_s, #to_yaml_properties, #uniqueness_key, #valid_parameter?, #validate_complete, #validate_parameter, value_to_pson_data, #yaml_property_munge
Methods included from Util::Pson
Methods included from Indirector
Methods included from Util::Tagging
Constructor Details
#initialize(*args) ⇒ Resource
Returns a new instance of Resource.
115 116 117 118 119 120 121 |
# File 'lib/puppet/parser/resource.rb', line 115 def initialize(*args) raise ArgumentError, "Resources require a hash as last argument" unless args.last.is_a? Hash raise ArgumentError, "Resources require a scope" unless args.last[:scope] super @source ||= scope.source end |
Instance Attribute Details
#collector_id ⇒ Object
20 21 22 |
# File 'lib/puppet/parser/resource.rb', line 20 def collector_id @collector_id end |
#evaluated ⇒ Object
21 22 23 |
# File 'lib/puppet/parser/resource.rb', line 21 def evaluated @evaluated end |
#exported ⇒ Object
24 25 26 |
# File 'lib/puppet/parser/resource.rb', line 24 def exported @exported end |
#override ⇒ Object
21 22 23 |
# File 'lib/puppet/parser/resource.rb', line 21 def override @override end |
#parameters ⇒ Object (readonly)
24 25 26 |
# File 'lib/puppet/parser/resource.rb', line 24 def parameters @parameters end |
#translated ⇒ Object
21 22 23 |
# File 'lib/puppet/parser/resource.rb', line 21 def translated @translated end |
Class Method Details
.relationship_parameter?(name) ⇒ Boolean
Determine whether the provided parameter name is a relationship parameter.
27 28 29 30 |
# File 'lib/puppet/parser/resource.rb', line 27 def self.relationship_parameter?(name) @relationship_names ||= Puppet::Type.relationship_params.collect { |p| p.name } @relationship_names.include?(name) end |
Instance Method Details
#[](param) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/puppet/parser/resource.rb', line 37 def [](param) param = param.intern if param == :title return self.title end if @parameters.has_key?(param) @parameters[param].value else nil end end |
#add_edge_to_stage ⇒ Object
Process the stage metaparameter for a class. A containment edge is drawn from the class to the stage. The stage for containment defaults to main, if none is specified.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/puppet/parser/resource.rb', line 62 def add_edge_to_stage return unless self.class? unless stage = catalog.resource(:stage, self[:stage] || (scope && scope.resource && scope.resource[:stage]) || :main) raise ArgumentError, "Could not find stage #{self[:stage] || :main} specified by #{self}" end self[:stage] ||= stage.title unless stage.title == :main catalog.add_edge(stage, self) end |
#eachparam ⇒ Object
49 50 51 52 53 |
# File 'lib/puppet/parser/resource.rb', line 49 def eachparam @parameters.each do |name, param| yield param end end |
#environment ⇒ Object
55 56 57 |
# File 'lib/puppet/parser/resource.rb', line 55 def environment scope.environment end |
#evaluate ⇒ Object
Retrieve the associated definition and evaluate it.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/puppet/parser/resource.rb', line 74 def evaluate return if evaluated? @evaluated = true if klass = resource_type and ! builtin_type? finish evaluated_code = klass.evaluate_code(self) return evaluated_code elsif builtin? devfail "Cannot evaluate a builtin type (#{type})" else self.fail "Cannot find definition #{type}" end end |
#evaluated? ⇒ Boolean
35 |
# File 'lib/puppet/parser/resource.rb', line 35 def evaluated?; !!@evaluated; end |
#finish ⇒ Object
Do any finishing work on this object, called before evaluation or before storage/translation.
102 103 104 105 106 107 108 |
# File 'lib/puppet/parser/resource.rb', line 102 def finish return if finished? @finished = true add_defaults validate end |
#finished? ⇒ Boolean
Has this resource already been finished?
111 112 113 |
# File 'lib/puppet/parser/resource.rb', line 111 def finished? @finished end |
#isomorphic? ⇒ Boolean
Is this resource modeling an isomorphic resource type?
124 125 126 127 128 129 130 |
# File 'lib/puppet/parser/resource.rb', line 124 def isomorphic? if builtin_type? return resource_type.isomorphic? else return true end end |
#merge(resource) ⇒ Object
Merge an override resource in. This will throw exceptions if any overrides aren’t allowed.
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/puppet/parser/resource.rb', line 134 def merge(resource) # Test the resource scope, to make sure the resource is even allowed # to override. unless self.source.object_id == resource.source.object_id || resource.source.child_of?(self.source) raise Puppet::ParseError.new("Only subclasses can override parameters", resource.line, resource.file) end # Some of these might fail, but they'll fail in the way we want. resource.parameters.each do |name, param| override_parameter(param) end end |
#metaparam_compatibility_mode? ⇒ Boolean
This only mattered for clients < 0.25, which we don’t support any longer. …but, since this hasn’t been deprecated, and at least some functions used it, deprecate now rather than just eliminate. –daniel 2012-07-15
149 150 151 152 |
# File 'lib/puppet/parser/resource.rb', line 149 def Puppet.deprecation_warning "metaparam_compatibility_mode? is obsolete since < 0.25 clients are really, really not supported any more" false end |
#name ⇒ Object
154 155 156 |
# File 'lib/puppet/parser/resource.rb', line 154 def name self[:name] || self.title end |
#override? ⇒ Boolean
34 |
# File 'lib/puppet/parser/resource.rb', line 34 def override?; !!@override; end |
#raw_tagged?(tag_array) ⇒ Boolean
Answers if this resource is tagged with at least one of the tags given in downcased string form.
The method is a faster variant of the tagged? method that does no conversion of its arguments.
The match takes into account the tags that a resource will inherit from its container but have not been set yet. It does not take tags set via resource defaults as these will never be set on the resource itself since all resources always have tags that are automatically assigned.
206 207 208 |
# File 'lib/puppet/parser/resource.rb', line 206 def raw_tagged?(tag_array) super || ((scope_resource = scope.resource) && !scope_resource.equal?(self) && scope_resource.raw_tagged?(tag_array)) end |
#set_parameter(param, value = nil) ⇒ Object Also known as: []=
Define a parameter in our resource. if we ever receive a parameter named ‘tag’, set the resource tags with its value.
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/puppet/parser/resource.rb', line 164 def set_parameter(param, value = nil) if ! param.is_a?(Puppet::Parser::Resource::Param) param = Puppet::Parser::Resource::Param.new( :name => param, :value => value, :source => self.source ) end tag(*param.value) if param.name == :tag # And store it in our parameter hash. @parameters[param.name] = param end |
#to_hash ⇒ Object
178 179 180 181 182 183 184 185 |
# File 'lib/puppet/parser/resource.rb', line 178 def to_hash @parameters.inject({}) do |hash, ary| param = ary[1] # Skip "undef" and nil values. hash[param.name] = param.value if param.value != :undef && !param.value.nil? hash end end |
#to_ral ⇒ Object
Convert this resource to a RAL resource.
188 189 190 |
# File 'lib/puppet/parser/resource.rb', line 188 def to_ral copy_as_resource.to_ral end |
#translated? ⇒ Boolean
Set up some boolean test methods
33 |
# File 'lib/puppet/parser/resource.rb', line 33 def translated?; !!@translated; end |