Class: Puppet::Type
- Extended by:
- Enumerable, CompilableResourceType, MetaType::Manager, Util, Util::ClassGen, Util::Logging, Util::ProviderFeatures, Util::Warnings
- Includes:
- Comparable, Enumerable, Util, Util::Errors, Util::Logging, Util::Tagging
- Defined in:
- lib/puppet/type.rb
Defined Under Namespace
Classes: RelationshipMetaparam
Constant Summary
Constants included from Util
Util::ALNUM, Util::ALPHA, Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE, Util::ESCAPED, Util::HEX, Util::HttpProxy, Util::PUPPET_STACK_INSERTION_FRAME, Util::RESERVED, Util::RFC_3986_URI_REGEX, Util::UNRESERVED, Util::UNSAFE
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
Constants included from Util::Tagging
Class Attribute Summary collapse
-
.defaultprovider ⇒ Puppet::Provider?
The default provider, or the most suitable provider if no default provider was set.
-
.name ⇒ String
readonly
The name of the resource type; e.g., “File”.
-
.properties ⇒ Array<Puppet::Property>
readonly
The returned lists contains instances if Puppet::Property or its subclasses.
-
.providerloader ⇒ Object
private
The loader of providers to use when loading providers from disk.
-
.self_refresh ⇒ Boolean
True if the type should send itself a refresh event on change.
Instance Attribute Summary collapse
-
#catalog ⇒ ??? TODO
The catalog that this resource is stored in.
-
#exported ⇒ Boolean
Flag indicating if this type is exported.
-
#file ⇒ String
The file from which this type originates from.
-
#line ⇒ Integer
The line in #file from which this type originates from.
-
#noop ⇒ Boolean
Returns the ‘noop` run mode status of this.
-
#original_parameters ⇒ Hash
readonly
private
Hash of parameters originally defined.
-
#provider ⇒ Puppet::Provider?
The provider that has been selected for the instance of the resource type.
-
#title ⇒ String
Returns the title of this object, or its name if title was not explicitly set.
-
#virtual ⇒ Boolean
Flag indicating if the type is virtual (it should not be).
Attributes included from Util::Docs
Class Method Summary collapse
-
.allattrs ⇒ Array<String>
Returns all the attribute names of the type in the appropriate order.
-
.apply_to ⇒ Symbol
private
Makes this type apply to ‘:host` if not already applied to something else.
-
.apply_to_all ⇒ Symbol
private
Makes this type applicable to ‘:both` (i.e. `:host` and `:device`).
-
.apply_to_device ⇒ Symbol
private
Makes this type applicable to ‘:device`.
-
.apply_to_host ⇒ Symbol
private
Makes this type applicable to ‘:host`.
-
.attrclass(name) ⇒ Class?
Returns the class associated with the given attribute name.
-
.attrtype(attr) ⇒ Symbol
Returns the attribute type (‘:property`, `;param`, `:meta`).
- .autobefore(name, &block) ⇒ Object
- .autonotify(name, &block) ⇒ Object
-
.autorequire(name) {| | ... } ⇒ void
Adds a block producing a single name (or list of names) of the given resource type name to autorelate.
- .autosubscribe(name, &block) ⇒ Object
-
.can_apply_to(target) ⇒ Boolean
private
Returns true if this type is applicable to the given target.
-
.eachautobefore {|type, block| ... } ⇒ void
Provides iteration over added auto-requirements (see Type.autobefore).
-
.eachautonotify {|type, block| ... } ⇒ void
Provides iteration over added auto-requirements (see Type.autonotify).
-
.eachautorequire {|type, block| ... } ⇒ void
Provides iteration over added auto-requirements (see Type.autorequire).
-
.eachautosubscribe {|type, block| ... } ⇒ void
Provides iteration over added auto-requirements (see Type.autosubscribe).
-
.eachmetaparam {|p| ... } ⇒ void
Provides iteration over meta-parameters.
-
.ensurable {|| ... } ⇒ void
Creates a new ‘ensure` property with configured default values or with configuration by an optional block.
-
.ensurable? ⇒ Boolean
Returns true if the type implements the default behavior expected by being ensurable “by default”.
-
.handle_param_options(name, options) ⇒ void
Processes the options for a named parameter.
-
.hash2resource(hash) ⇒ Puppet::Resource
Converts a simple hash into a Resource instance.
-
.initvars ⇒ void
Initializes all of the variables that must be initialized for each subclass.
-
.instances ⇒ Object
Retrieves all known instances.
-
.isomorphic? ⇒ Boolean
Returns true if the type’s notion of name is the identity of a resource.
-
.key_attribute_parameters ⇒ Array<Puppet::Parameter>
Returns the list of parameters that comprise the composite key / “uniqueness key”.
-
.key_attributes ⇒ Array<String>
Returns cached Type.key_attribute_parameters names.
-
.metaparam?(param) ⇒ Boolean
Is the given parameter a meta-parameter?.
-
.metaparamclass(name) ⇒ Class?
Returns the meta-parameter class associated with the given meta-parameter name.
-
.metaparamdoc(metaparam) ⇒ String
Returns the documentation for a given meta-parameter of this type.
-
.metaparams ⇒ Array<String>
Returns all meta-parameter names.
-
.needs_ensure_retrieved ⇒ Object
Says if the ensure property should be retrieved if the resource is ensurable Defaults to true.
-
.newmetaparam(name, options = {}) {|| ... } ⇒ Class<inherits Puppet::Parameter>
Creates a new meta-parameter.
-
.newparam(name, options = {}) {|| ... } ⇒ Class<inherits Puppet::Parameter>
Creates a new parameter.
-
.newproperty(name, options = {}) {|| ... } ⇒ Class<inherits Puppet::Property>
Creates a new property.
-
.paramclass(name) ⇒ Puppet::Parameter
Returns the parameter class associated with the given parameter name.
- .paramdoc(param) ⇒ Object
-
.parameters ⇒ Array<String>
Returns the parameter names.
-
.parameters_to_include ⇒ Array<Symbol>
Returns any parameters that should be included by default in puppet resource’s output.
-
.propertybyname(name) ⇒ Puppet::Property
Returns the property class ??? associated with the given property name.
-
.provide(name, options = {}, &block) ⇒ Puppet::Provider
Creates a new provider of a type.
-
.provider(name) ⇒ Puppet::Provider?
Returns the provider having the given name.
-
.provider_hash ⇒ Hash{ ??? => Puppet::Provider}
Returns a hash of WHAT EXACTLY for this type.
-
.provider_hash_by_type(type) ⇒ Hash{??? => Puppet::Provider}
Returns a hash of WHAT EXACTLY for the given type.
-
.providers ⇒ Array<String>
Returns a list of loaded providers by name.
-
.providers_by_source ⇒ Array<Puppet::Provider>
Returns a list of one suitable provider per source, with the default provider first.
-
.providify ⇒ void
Ensures there is a ‘:provider` parameter defined.
- .relationship_params ⇒ Object
-
.suitableprovider ⇒ Array<Puppet::Provider>
Returns a list of suitable providers for the given type.
-
.title_patterns ⇒ Array<Array<Regexp, Array<Array <Symbol, Proc>>>>?
private
Returns a mapping from the title string to setting of attribute values.
-
.to_s ⇒ String
Returns the name of this type (if specified) or the parent type #to_s.
-
.unprovide(name) ⇒ Object
Removes the implementation class of a given provider.
-
.valid_parameter?(name) ⇒ Boolean
Returns whether or not the given name is the name of a property, parameter or meta-parameter.
-
.validate {|| ... } ⇒ void
Creates a ‘validate` method that is used to validate a resource before it is operated on.
-
.validattr?(name) ⇒ Boolean
Returns whether or not the given name is the name of a property, parameter or meta-parameter.
-
.validparameter?(name) ⇒ Boolean
Returns true if the given name is the name of an existing parameter.
-
.validproperties ⇒ Array<Symbol>, {}
Returns a list of valid property names, or an empty hash if there are none.
-
.validproperty?(name) ⇒ Boolean
Returns true if the given name is the name of an existing property.
-
.validprovider?(name) ⇒ Boolean
Returns true if the given name is a reference to a provider and if this is a suitable provider for this type.
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Compares this type against the given other (type) and returns -1, 0, or +1 depending on the order.
-
#[](name) ⇒ Object
Gets the ‘should’ (wanted state) value of a parameter or property by name.
-
#[]=(name, value) ⇒ Object
Sets the ‘should’ (wanted state) value of a property, or the value of a parameter.
-
#add_property_parameter(prop_name) ⇒ Boolean
Creates a new property value holder for the resource if it is valid and does not already exist.
-
#ancestors ⇒ Array<???>
Returns the ancestors - WHAT? This implementation always returns an empty list.
-
#appliable_to_device? ⇒ Boolean
private
Returns true if a resource of this type can be evaluated on a ‘network device’ kind of hosts.
-
#appliable_to_host? ⇒ Boolean
private
Returns true if a resource of this type can be evaluated on a regular generalized computer (ie not an appliance like a network device).
- #autobefore(rel_catalog = nil) ⇒ Object
- #autonotify(rel_catalog = nil) ⇒ Object
-
#autorelation(rel_type, rel_catalog = nil) ⇒ Object
Adds dependencies to the catalog from added autorelations.
- #autorequire(rel_catalog = nil) ⇒ Object
- #autosubscribe(rel_catalog = nil) ⇒ Object
-
#builddepends ⇒ Array<Puppet::Relationship>
Builds the dependencies associated with this resource.
-
#copy_metaparams(parameters) ⇒ Void
Copies all of a resource’s metaparameters (except ‘alias`) to a generated child resource.
-
#currentpropvalues ⇒ Hash{Puppet::Property => Object}
Returns a hash of the current properties and their values.
-
#delete(attr) ⇒ Object
Removes an attribute from the object; useful in testing or in cleanup when an error has been encountered.
-
#deleting? ⇒ Boolean
Returns true if the wanted state of the resource is that it should be absent (i.e. to be deleted).
-
#depthfirst? ⇒ Boolean
Returns true if the search should be done in depth-first order.
-
#eachparameter {|parameter| ... } ⇒ void
Iterates over all parameters with value currently set.
-
#eachproperty {|property| ... } ⇒ void
Iterates over the properties that were set on this resource.
-
#event(options = {}) ⇒ Puppet::Transaction::Event
Creates a transaction event.
-
#exported? ⇒ Boolean
Returns whether the resource is exported or not.
-
#finish ⇒ Array<Puppet::Parameter>
Finishes any outstanding processing.
-
#flush ⇒ ????
Flushes the provider if supported by the provider, else no action.
-
#initialize(resource) ⇒ Type
constructor
Creates an instance of Type from a hash or a Resource.
-
#isomorphic? ⇒ Boolean
(see isomorphic?).
-
#log(msg) ⇒ void
Creates a log entry with the given message at the log level specified by the parameter ‘loglevel`.
-
#managed? ⇒ Boolean
Returns true if the instance is a managed instance.
-
#name ⇒ String
Returns the resource’s name.
-
#name_var ⇒ Symbol, Boolean
Returns the name of the namevar if there is only one or false otherwise.
-
#newattr(name) ⇒ Object
Registers an attribute to this resource type instance.
-
#noop? ⇒ Boolean
Returns the ‘noop` run mode status of this.
-
#parameter(name) ⇒ Object
Returns the value of this object’s parameter given by name.
-
#parameters ⇒ Hash{String => Object}
Returns a shallow copy of this object’s hash of attributes by name.
-
#parameters_with_value ⇒ Array<Puppet::Parameter>
Return the parameters, metaparams, and properties that have a value or were set by a default.
-
#parent ⇒ Puppet::Type?
Returns the parent of this in the catalog.
-
#path ⇒ String
Returns a string representation of the resource’s containment path in the catalog.
-
#pathbuilder ⇒ Object
private
Returns an array of strings representing the containment hierarchy (types/classes) that make up the path to the resource from the root of the catalog.
-
#pre_run_check ⇒ void
abstract
Lifecycle method for a resource.
-
#present?(current_values) ⇒ Boolean
Given the hash of current properties, should this resource be treated as if it currently exists on the system.
-
#properties ⇒ Array<Puppet::Property>
Returns all of the property objects, in the order specified in the class.
-
#property(name) ⇒ Puppet::Property
Returns a Property instance by name.
-
#propertydefined?(name) ⇒ Boolean
Returns whether the attribute given by name has been added to this resource or not.
-
#purging ⇒ Object
Marks the object as “being purged”.
-
#purging? ⇒ Boolean
Returns whether this resource is being purged or not.
-
#ref ⇒ String
Returns a reference to this as a string in “Type” format.
-
#remove ⇒ void
Removes this object (FROM WHERE?).
-
#retrieve ⇒ Puppet::Resource
Retrieves the current value of all contained properties.
-
#retrieve_resource ⇒ Puppet::Resource
private
Retrieve the current state of the system as a Puppet::Resource.
- #self_refresh? ⇒ Boolean
- #set_default(attr) ⇒ void
-
#should(name) ⇒ Object?
Returns the ‘should’ (wanted state) value for a specified property, or nil if the given attribute name is not a property (i.e. if it is a parameter, meta-parameter, or does not exist).
-
#suitable? ⇒ Boolean
Returns true if this is something else than a ‘:provider`, or if it is a provider and it is suitable, or if there is a default provider.
-
#tags=(list) ⇒ void
Sets the initial list of tags to associate to this resource.
-
#to_hash ⇒ Hash{ ??? => ??? }
A hash of WHAT?.
-
#to_resource ⇒ Puppet::Resource
Convert this resource type instance to a Puppet::Resource.
-
#to_s ⇒ Object
Produces a reference to this in reference format.
-
#type ⇒ String
The name of this object’s class.
-
#uniqueness_key ⇒ Object
Produces a resource’s uniqueness_key (or composite key).
-
#validate_resource ⇒ void
Optionally validate the resource.
-
#value(name) ⇒ Object?
The value of the attribute having the given name, or nil if the given name is not an attribute, or the referenced attribute does not respond to ‘:value`.
-
#version ⇒ ???
The version of the catalog or 0 if there is no catalog.
-
#virtual? ⇒ Boolean
Returns whether the resource is virtual or not.
Methods included from Util::Logging
clear_deprecation_warnings, debug, deprecation_warning, format_backtrace, format_exception, get_deprecation_offender, log_and_raise, log_deprecations_to_file, log_exception, puppet_deprecation_warning, send_log, setup_facter_logging!, warn_once
Methods included from Util
absolute_path?, benchmark, chuser, clear_environment, create_erb, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, format_backtrace_array, format_puppetstack_frame, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, resolve_stackframe, rfc2396_escape, safe_posix_fork, set_env, skip_external_facts, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, uri_unescape, which, withenv, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, groups_of, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::SymbolicFileMode
#display_mode, #normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Methods included from Util::Warnings
clear_warnings, debug_once, maybe_log, notice_once, warnonce
Methods included from Util::ClassGen
Methods included from CompilableResourceType
Methods included from MetaType::Manager
allclear, clear_misses, eachtype, loadall, newtype, rmtype, typeloader
Methods included from Util::ProviderFeatures
feature, feature_module, featuredocs, features, provider_feature
Methods included from Util::Docs
#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub
Methods included from Util::Tagging
#merge_into, #merge_tags_from, #raw_tagged?, #set_tags, #tag, #tag_if_valid, #tagged?, #tags, #valid_tag?
Methods included from Util::Errors
#adderrorcontext, #devfail, #error_context, error_location, error_location_with_space, error_location_with_unknowns, #exceptwrap, #fail
Constructor Details
#initialize(hash) ⇒ Type #initialize(resource) ⇒ Type
Unclear if this is a new Type or a new instance of a given type (the initialization ends with calling validate - which seems like validation of an instance of a given type, not a new meta type.
Explain what the Hash and Resource are. There seems to be two different types of resources; one that causes the title to be set to resource.title, and one that causes the title to be resource.ref (“for components”) - what is a component?
Creates an instance of Type from a hash or a Resource.
2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 |
# File 'lib/puppet/type.rb', line 2313 def initialize(resource) resource = self.class.hash2resource(resource) unless resource.is_a?(Puppet::Resource) # The list of parameter/property instances. @parameters = {} # Set the title first, so any failures print correctly. if resource.type.to_s.downcase.to_sym == self.class.name self.title = resource.title else # This should only ever happen for components self.title = resource.ref end [:file, :line, :catalog, :exported, :virtual].each do |getter| setter = getter.to_s + "=" val = resource.send(getter) send(setter, val) if val end (resource) @original_parameters = resource.to_hash set_name(@original_parameters) set_default(:provider) set_parameters(@original_parameters) validate_resource set_sensitive_parameters(resource.sensitive_parameters) end |
Class Attribute Details
.defaultprovider ⇒ Puppet::Provider?
a warning will be issued if no default provider has been configured and a search for the most suitable provider returns more than one equally suitable provider.
The default provider, or the most suitable provider if no default provider was set.
1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 |
# File 'lib/puppet/type.rb', line 1704 def self.defaultprovider return @defaultprovider if @defaultprovider suitable = suitableprovider # Find which providers are a default for this system. defaults = suitable.find_all(&:default?) # If we don't have any default we use suitable providers defaults = suitable if defaults.empty? max = defaults.collect(&:specificity).max defaults = defaults.find_all { |provider| provider.specificity == max } if defaults.length > 1 Puppet.warning(_("Found multiple default providers for %{name}: %{provider_list}; using %{selected_provider}") % { name: name, provider_list: defaults.collect { |i| i.name.to_s }.join(", "), selected_provider: defaults[0].name }) end @defaultprovider = defaults.shift unless defaults.empty? end |
.name ⇒ String (readonly)
Returns the name of the resource type; e.g., “File”.
2183 2184 2185 |
# File 'lib/puppet/type.rb', line 2183 def name @name end |
.properties ⇒ Array<Puppet::Property> (readonly)
The returned lists contains instances if Puppet::Property or its subclasses.
116 117 118 |
# File 'lib/puppet/type.rb', line 116 def properties @properties end |
.providerloader ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The loader of providers to use when loading providers from disk. Although it looks like this attribute provides a way to operate with different loaders of providers that is not the case; the attribute is written when a new type is created, and should not be changed thereafter.
1690 1691 1692 |
# File 'lib/puppet/type.rb', line 1690 def providerloader @providerloader end |
.self_refresh ⇒ Boolean
Returns true if the type should send itself a refresh event on change.
2187 2188 2189 |
# File 'lib/puppet/type.rb', line 2187 def self_refresh @self_refresh end |
Instance Attribute Details
#catalog ⇒ ??? TODO
what does this mean “this resource” (sounds like this if for an instance of the type, not the meta Type), but not sure if this is about the catalog where the meta Type is included)
Returns The catalog that this resource is stored in.
2268 2269 2270 |
# File 'lib/puppet/type.rb', line 2268 def catalog @catalog end |
#exported ⇒ Boolean
Returns Flag indicating if this type is exported.
2271 2272 2273 |
# File 'lib/puppet/type.rb', line 2271 def exported @exported end |
#file ⇒ String
Returns The file from which this type originates from.
2260 2261 2262 |
# File 'lib/puppet/type.rb', line 2260 def file @file end |
#line ⇒ Integer
Returns The line in #file from which this type originates from.
2263 2264 2265 |
# File 'lib/puppet/type.rb', line 2263 def line @line end |
#noop ⇒ Boolean
Returns the ‘noop` run mode status of this.
1143 1144 1145 |
# File 'lib/puppet/type.rb', line 1143 def noop noop? end |
#original_parameters ⇒ Hash (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns hash of parameters originally defined.
2293 2294 2295 |
# File 'lib/puppet/type.rb', line 2293 def original_parameters @original_parameters end |
#provider ⇒ Puppet::Provider?
The provider that has been selected for the instance of the resource type.
1680 1681 1682 |
# File 'lib/puppet/type.rb', line 1680 def provider @provider end |
#title ⇒ String
it is somewhat confusing that if the name_var is a valid parameter, it is assumed to be the name_var called :name, but if it is a property, it uses the name_var. It is further confusing as Type in some respects supports multiple namevars.
Returns the title of this object, or its name if title was not explicitly set. If the title is not already set, it will be computed by looking up the #name_var and using that value as the title.
2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 |
# File 'lib/puppet/type.rb', line 2566 def title unless @title if self.class.validparameter?(name_var) @title = self[:name] elsif self.class.validproperty?(name_var) @title = should(name_var) else devfail "Could not find namevar #{name_var} for #{self.class.name}" end end @title end |
#virtual ⇒ Boolean
Returns Flag indicating if the type is virtual (it should not be).
2274 2275 2276 |
# File 'lib/puppet/type.rb', line 2274 def virtual @virtual end |
Class Method Details
.allattrs ⇒ Array<String>
Returns all the attribute names of the type in the appropriate order. The key_attributes come first, then the provider, then the properties, and finally the parameters and metaparams, all in the order they were specified in the respective files.
125 126 127 |
# File 'lib/puppet/type.rb', line 125 def self.allattrs key_attributes | (parameters & [:provider]) | properties.collect(&:name) | parameters | end |
.apply_to ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Makes this type apply to ‘:host` if not already applied to something else.
253 254 255 |
# File 'lib/puppet/type.rb', line 253 def self.apply_to @apply_to ||= :host end |
.apply_to_all ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Makes this type applicable to ‘:both` (i.e. `:host` and `:device`).
246 247 248 |
# File 'lib/puppet/type.rb', line 246 def self.apply_to_all @apply_to = :both end |
.apply_to_device ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Makes this type applicable to ‘:device`.
230 231 232 |
# File 'lib/puppet/type.rb', line 230 def self.apply_to_device @apply_to = :device end |
.apply_to_host ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Makes this type applicable to ‘:host`.
238 239 240 |
# File 'lib/puppet/type.rb', line 238 def self.apply_to_host @apply_to = :host end |
.attrclass(name) ⇒ Class?
Returns the class associated with the given attribute name.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/puppet/type.rb', line 133 def self.attrclass(name) @attrclasses ||= {} # We cache the value, since this method gets called such a huge number # of times (as in, hundreds of thousands in a given run). unless @attrclasses.include?(name) @attrclasses[name] = case attrtype(name) when :property; @validproperties[name] when :meta; @@metaparamhash[name] when :param; @paramhash[name] end end @attrclasses[name] end |
.attrtype(attr) ⇒ Symbol
Returns the attribute type (‘:property`, `;param`, `:meta`).
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/puppet/type.rb', line 153 def self.attrtype(attr) @attrtypes ||= {} unless @attrtypes.include?(attr) @attrtypes[attr] = case when @validproperties.include?(attr); :property when @paramhash.include?(attr); :param when @@metaparamhash.include?(attr); :meta end end @attrtypes[attr] end |
.autobefore(name, &block) ⇒ Object
2003 2004 2005 2006 |
# File 'lib/puppet/type.rb', line 2003 def self.autobefore(name, &block) @autobefores ||= {} @autobefores[name] = block end |
.autonotify(name, &block) ⇒ Object
2013 2014 2015 2016 |
# File 'lib/puppet/type.rb', line 2013 def self.autonotify(name, &block) @autonotifies ||= {} @autonotifies[name] = block end |
.autorequire(name) {| | ... } ⇒ void
This method returns an undefined value.
Adds a block producing a single name (or list of names) of the given resource type name to autorelate.
The four relationship types require, before, notify, and subscribe are all supported.
Be careful with notify and subscribe as they may have unintended consequences.
Resources in the catalog that have the named type and a title that is included in the result will be linked to the calling resource as a requirement.
1998 1999 2000 2001 |
# File 'lib/puppet/type.rb', line 1998 def self.autorequire(name, &block) @autorequires ||= {} @autorequires[name] = block end |
.autosubscribe(name, &block) ⇒ Object
2008 2009 2010 2011 |
# File 'lib/puppet/type.rb', line 2008 def self.autosubscribe(name, &block) @autosubscribes ||= {} @autosubscribes[name] = block end |
.can_apply_to(target) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if this type is applicable to the given target.
262 263 264 |
# File 'lib/puppet/type.rb', line 262 def self.can_apply_to(target) [target == :device ? :device : :host, :both].include?(apply_to) end |
.eachautobefore {|type, block| ... } ⇒ void
This method returns an undefined value.
Provides iteration over added auto-requirements (see autobefore).
2035 2036 2037 2038 2039 2040 |
# File 'lib/puppet/type.rb', line 2035 def self.eachautobefore @autobefores ||= {} @autobefores.each { |type, block| yield(type, block) } end |
.eachautonotify {|type, block| ... } ⇒ void
This method returns an undefined value.
Provides iteration over added auto-requirements (see autonotify).
2059 2060 2061 2062 2063 2064 |
# File 'lib/puppet/type.rb', line 2059 def self.eachautonotify @autonotifies ||= {} @autonotifies.each { |type, block| yield(type, block) } end |
.eachautorequire {|type, block| ... } ⇒ void
This method returns an undefined value.
Provides iteration over added auto-requirements (see autorequire).
2023 2024 2025 2026 2027 2028 |
# File 'lib/puppet/type.rb', line 2023 def self.eachautorequire @autorequires ||= {} @autorequires.each { |type, block| yield(type, block) } end |
.eachautosubscribe {|type, block| ... } ⇒ void
This method returns an undefined value.
Provides iteration over added auto-requirements (see autosubscribe).
2047 2048 2049 2050 2051 2052 |
# File 'lib/puppet/type.rb', line 2047 def self.eachautosubscribe @autosubscribes ||= {} @autosubscribes.each { |type, block| yield(type, block) } end |
.eachmetaparam {|p| ... } ⇒ void
This method returns an undefined value.
Provides iteration over meta-parameters.
170 171 172 |
# File 'lib/puppet/type.rb', line 170 def self. @@metaparams.each { |p| yield p.name } end |
.ensurable ⇒ void .ensurable({ ... }) ⇒ void
This method will be automatically called without a block if the type implements the methods specified by ensurable?. It is recommended to always call this method and not rely on this automatic specification to clearly state that the type is ensurable.
This method returns an undefined value.
Creates a new ‘ensure` property with configured default values or with configuration by an optional block. This method is a convenience method for creating a property `ensure` with default accepted values. If no block is specified, the new `ensure` property will accept the default symbolic values `:present`, and `:absent` - see Property::Ensure. If something else is wanted, pass a block and make calls to Property.newvalue from this block to define each possible value. If a block is passed, the defaults are not automatically added to the set of valid values.
194 195 196 197 198 199 200 201 202 |
# File 'lib/puppet/type.rb', line 194 def self.ensurable(&block) if block_given? newproperty(:ensure, :parent => Puppet::Property::Ensure, &block) else newproperty(:ensure, :parent => Puppet::Property::Ensure) do defaultvalues end end end |
.ensurable? ⇒ Boolean
Returns true if the type implements the default behavior expected by being ensurable “by default”. A type is ensurable by default if it responds to ‘:exists`, `:create`, and `:destroy`. If a type implements these methods and have not already specified that it is ensurable, it will be made so with the defaults specified in ensurable.
210 211 212 213 214 215 216 |
# File 'lib/puppet/type.rb', line 210 def self.ensurable? # If the class has all three of these methods defined, then it's # ensurable. [:exists?, :create, :destroy].all? { |method| public_method_defined?(method) } end |
.handle_param_options(name, options) ⇒ void
This method returns an undefined value.
Processes the options for a named parameter.
272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/puppet/type.rb', line 272 def self.(name, ) # If it's a boolean parameter, create a method to test the value easily if [:boolean] define_method(name.to_s + "?") do val = self[name] if val == :true or val == true true end end end end |
.hash2resource(hash) ⇒ Puppet::Resource
as opposed to a complex hash? Other raised exceptions?
Converts a simple hash into a Resource instance.
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 |
# File 'lib/puppet/type.rb', line 1198 def self.hash2resource(hash) hash = hash.each_with_object({}) { |ary, result| result[ary[0].to_sym] = ary[1]; } title = hash.delete(:title) title ||= hash[:name] title ||= hash[key_attributes.first] if key_attributes.length == 1 raise Puppet::Error, "Title or name must be provided" unless title # Now create our resource. resource = Puppet::Resource.new(self, title) resource.catalog = hash.delete(:catalog) sensitive = hash.delete(:sensitive_parameters) if sensitive resource.sensitive_parameters = sensitive end hash.each do |param, value| resource[param] = value end resource end |
.initvars ⇒ void
Does the explanation make sense?
This method returns an undefined value.
Initializes all of the variables that must be initialized for each subclass.
2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 |
# File 'lib/puppet/type.rb', line 2198 def self.initvars # all of the instances of this class @objects = Hash.new @aliases = Hash.new @defaults = {} @parameters ||= [] @validproperties = {} @properties = [] @parameters = [] @paramhash = {} @paramdoc = Hash.new { |hash, key| key = key.intern if key.is_a?(String) if hash.include?(key) hash[key] else "Param Documentation for #{key} not found" end } # rubocop:disable Naming/MemoizedInstanceVariableName @doc ||= "" # rubocop:enable Naming/MemoizedInstanceVariableName end |
.instances ⇒ Object
Retrieves them from where? Known to whom?
Retrieves all known instances. Either requires providers or must be overridden.
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 |
# File 'lib/puppet/type.rb', line 1151 def self.instances raise Puppet::DevError, _("%{name} has no providers and has not overridden 'instances'") % { name: name } if provider_hash.empty? # Put the default provider first, then the rest of the suitable providers. provider_instances = {} providers_by_source.collect do |provider| provider.instances.collect do |instance| # We always want to use the "first" provider instance we find, unless the resource # is already managed and has a different provider set title = instance.respond_to?(:title) ? instance.title : instance.name other = provider_instances[title] if other Puppet.debug { "%s %s found in both %s and %s; skipping the %s version" % [name.to_s.capitalize, title, other.class.name, instance.class.name, instance.class.name] } next end provider_instances[title] = instance result = new(:name => instance.name, :provider => instance, :title => title) properties.each { |name| result.newattr(name) } result end end.flatten.compact end |
.isomorphic? ⇒ Boolean
Returns true if the type’s notion of name is the identity of a resource. See the overview of this class for a longer explanation of the concept isomorphism. Defaults to true.
932 933 934 935 936 937 938 |
# File 'lib/puppet/type.rb', line 932 def self.isomorphic? if defined?(@isomorphic) @isomorphic else true end end |
.key_attribute_parameters ⇒ Array<Puppet::Parameter>
Returns the list of parameters that comprise the composite key / “uniqueness key”. All parameters that return true from #isnamevar? or is named ‘:name` are included in the returned result.
376 377 378 379 380 |
# File 'lib/puppet/type.rb', line 376 def self.key_attribute_parameters @key_attribute_parameters ||= @parameters.find_all { |param| param.isnamevar? or param.name == :name } end |
.key_attributes ⇒ Array<String>
Returns cached key_attribute_parameters names. Key attributes are properties and parameters that comprise a composite key or “uniqueness key”.
387 388 389 390 391 392 |
# File 'lib/puppet/type.rb', line 387 def self.key_attributes # This is a cache miss around 0.05 percent of the time. --daniel 2012-07-17 # rubocop:disable Naming/MemoizedInstanceVariableName @key_attributes_cache ||= key_attribute_parameters.collect(&:name) # rubocop:enable Naming/MemoizedInstanceVariableName end |
.metaparam?(param) ⇒ Boolean
Is the given parameter a meta-parameter?
287 288 289 |
# File 'lib/puppet/type.rb', line 287 def self.(param) @@metaparamhash.include?(param.intern) end |
.metaparamclass(name) ⇒ Class?
Returns the meta-parameter class associated with the given meta-parameter name. Accepts a ‘nil` name, and return nil.
297 298 299 300 301 |
# File 'lib/puppet/type.rb', line 297 def self.(name) return nil if name.nil? @@metaparamhash[name.intern] end |
.metaparamdoc(metaparam) ⇒ String
Returns the documentation for a given meta-parameter of this type.
316 317 318 |
# File 'lib/puppet/type.rb', line 316 def self.() @@metaparamhash[].doc end |
.metaparams ⇒ Array<String>
Returns all meta-parameter names.
306 307 308 |
# File 'lib/puppet/type.rb', line 306 def self. @@metaparams.collect(&:name) end |
.needs_ensure_retrieved ⇒ Object
Says if the ensure property should be retrieved if the resource is ensurable Defaults to true. Some resource type classes can override it
1041 1042 1043 |
# File 'lib/puppet/type.rb', line 1041 def self.needs_ensure_retrieved true end |
.newmetaparam(name, options = {}) {|| ... } ⇒ Class<inherits Puppet::Parameter>
Verify that this description is ok
Creates a new meta-parameter. This creates a new meta-parameter that is added to this and all inheriting types.
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/puppet/type.rb', line 337 def self.(name, = {}, &block) @@metaparams ||= [] @@metaparamhash ||= {} name = name.intern param = genclass( name, :parent => [:parent] || Puppet::Parameter, :prefix => "MetaParam", :hash => @@metaparamhash, :array => @@metaparams, :attributes => [:attributes], &block ) # Grr. param.required_features = [:required_features] if [:required_features] (name, ) param. = true param end |
.newparam(name, options = {}) {|| ... } ⇒ Class<inherits Puppet::Parameter>
Creates a new parameter.
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'lib/puppet/type.rb', line 462 def self.newparam(name, = {}, &block) [:attributes] ||= {} param = genclass( name, :parent => [:parent] || Puppet::Parameter, :attributes => [:attributes], :block => block, :prefix => "Parameter", :array => @parameters, :hash => @paramhash ) (name, ) # Grr. param.required_features = [:required_features] if [:required_features] param.isnamevar if [:namevar] param end |
.newproperty(name, options = {}) {|| ... } ⇒ Class<inherits Puppet::Property>
Creates a new property.
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
# File 'lib/puppet/type.rb', line 503 def self.newproperty(name, = {}, &block) name = name.intern # This is here for types that might still have the old method of defining # a parent class. unless .is_a? Hash raise Puppet::DevError, _("Options must be a hash, not %{type}") % { type: .inspect } end raise Puppet::DevError, _("Class %{class_name} already has a property named %{property}") % { class_name: self.name, property: name } if @validproperties.include?(name) parent = [:parent] if parent .delete(:parent) else parent = Puppet::Property end # We have to create our own, new block here because we want to define # an initial :retrieve method, if told to, and then eval the passed # block if available. prop = genclass(name, :parent => parent, :hash => @validproperties, :attributes => ) do # If they've passed a retrieve method, then override the retrieve # method on the class. if [:retrieve] define_method(:retrieve) do provider.send([:retrieve]) end end class_eval(&block) if block end # If it's the 'ensure' property, always put it first. if name == :ensure @properties.unshift prop else @properties << prop end prop end |
.paramclass(name) ⇒ Puppet::Parameter
Returns the parameter class associated with the given parameter name.
558 559 560 |
# File 'lib/puppet/type.rb', line 558 def self.paramclass(name) @paramhash[name] end |
.paramdoc(param) ⇒ Object
546 547 548 |
# File 'lib/puppet/type.rb', line 546 def self.paramdoc(param) @paramhash[param].doc end |
.parameters ⇒ Array<String>
Returns the parameter names
551 552 553 554 555 |
# File 'lib/puppet/type.rb', line 551 def self.parameters return [] unless defined?(@parameters) @parameters.collect(&:name) end |
.parameters_to_include ⇒ Array<Symbol>
Returns any parameters that should be included by default in puppet resource’s output
396 397 398 |
# File 'lib/puppet/type.rb', line 396 def self.parameters_to_include [] end |
.propertybyname(name) ⇒ Puppet::Property
Returns the property class ??? associated with the given property name
563 564 565 |
# File 'lib/puppet/type.rb', line 563 def self.propertybyname(name) @validproperties[name] end |
.provide(name, options = {}, &block) ⇒ Puppet::Provider
Fix Confusing Explanations! Is this a new provider of a Type (metatype), or a provider of an instance of Type (a resource), or a Provider (the implementation of a Type’s behavior). CONFUSED. It calls magically named methods like “providify” …
Creates a new provider of a type. This method must be called directly on the type that it’s implementing.
1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 |
# File 'lib/puppet/type.rb', line 1788 def self.provide(name, = {}, &block) name = name.intern if unprovide(name) Puppet.debug { "Reloading #{name} #{self.name} provider" } end pname = [:parent] parent = if pname .delete(:parent) if pname.is_a? Class pname else provider = self.provider(pname) provider || raise(Puppet::DevError, _("Could not find parent provider %{parent} of %{name}") % { parent: pname, name: name }) end else Puppet::Provider end [:resource_type] ||= self providify genclass( name, :parent => parent, :hash => provider_hash, :prefix => "Provider", :block => block, :include => feature_module, :extend => feature_module, :attributes => ) end |
.provider(name) ⇒ Puppet::Provider?
Returns the provider having the given name. This will load a provider if it is not already loaded. The returned provider is the first found provider having the given name, where “first found” semantics is defined by the providerloader in use.
1745 1746 1747 1748 1749 1750 1751 |
# File 'lib/puppet/type.rb', line 1745 def self.provider(name) name = name.intern # If we don't have it yet, try loading it. @providerloader.load(name, Puppet.lookup(:current_environment)) unless provider_hash.has_key?(name) provider_hash[name] end |
.provider_hash ⇒ Hash{ ??? => Puppet::Provider}
Returns a hash of WHAT EXACTLY for this type.
1734 1735 1736 |
# File 'lib/puppet/type.rb', line 1734 def self.provider_hash Puppet::Type.provider_hash_by_type(name) end |
.provider_hash_by_type(type) ⇒ Hash{??? => Puppet::Provider}
what goes into this hash?
Returns a hash of WHAT EXACTLY for the given type
1727 1728 1729 1730 |
# File 'lib/puppet/type.rb', line 1727 def self.provider_hash_by_type(type) @provider_hashes ||= {} @provider_hashes[type] ||= {} end |
.providers ⇒ Array<String>
Returns a list of loaded providers by name. This method will not load/search for available providers.
1757 1758 1759 |
# File 'lib/puppet/type.rb', line 1757 def self.providers provider_hash.keys end |
.providers_by_source ⇒ Array<Puppet::Provider>
Needs better explanation; what does “source” mean in this context?
Returns a list of one suitable provider per source, with the default provider first.
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 |
# File 'lib/puppet/type.rb', line 1181 def self.providers_by_source # Put the default provider first (can be nil), then the rest of the suitable providers. sources = [] [defaultprovider, suitableprovider].flatten.uniq.filter_map do |provider| next if provider.nil? next if sources.include?(provider.source) sources << provider.source provider end end |
.providify ⇒ void
This method returns an undefined value.
Ensures there is a ‘:provider` parameter defined. Should only be called if there are providers.
1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 |
# File 'lib/puppet/type.rb', line 1827 def self.providify return if @paramhash.has_key? :provider param = newparam(:provider) do # We're using a hacky way to get the name of our type, since there doesn't # seem to be a correct way to introspect this at the time this code is run. # We expect that the class in which this code is executed will be something # like Puppet::Type::Ssh_authorized_key::ParameterProvider. desc <<-EOT The specific backend to use for this `#{to_s.split('::')[2].downcase}` resource. You will seldom need to specify this --- Puppet will usually discover the appropriate provider for your platform. EOT # This is so we can refer back to the type to get a list of # providers for documentation. class << self # The reference to a parent type for the parameter `:provider` used to get a list of # providers for documentation purposes. # attr_accessor :parenttype end # Provides the ability to add documentation to a provider. # def self.doc # Since we're mixing @doc with text from other sources, we must normalize # its indentation with scrub. But we don't need to manually scrub the # provider's doc string, since markdown_definitionlist sanitizes its inputs. scrub(@doc) + "Available providers are:\n\n" + parenttype.providers.sort_by(&:to_s).collect { |i| markdown_definitionlist(i, scrub(parenttype().provider(i).doc)) }.join end # For each resource, the provider param defaults to # the type's default provider defaultto { prov = @resource.class.defaultprovider prov.name if prov } validate do |provider_class| provider_class = provider_class[0] if provider_class.is_a? Array provider_class = provider_class.class.name if provider_class.is_a?(Puppet::Provider) unless @resource.class.provider(provider_class) raise ArgumentError, _("Invalid %{resource} provider '%{provider_class}'") % { resource: @resource.class.name, provider_class: provider_class } end end munge do |provider| provider = provider[0] if provider.is_a? Array provider = provider.intern if provider.is_a? String @resource.provider = provider if provider.is_a?(Puppet::Provider) provider.class.name else provider end end end param.parenttype = self end |
.relationship_params ⇒ Object
1569 1570 1571 |
# File 'lib/puppet/type.rb', line 1569 def self.relationship_params RelationshipMetaparam.subclasses end |
.suitableprovider ⇒ Array<Puppet::Provider>
This method also does some special processing which rejects a provider named ‘:fake` (for testing purposes).
Returns a list of suitable providers for the given type. A call to this method will load all providers if not already loaded and ask each if it is suitable - those that are included in the result.
1909 1910 1911 1912 1913 1914 1915 1916 |
# File 'lib/puppet/type.rb', line 1909 def self.suitableprovider providerloader.loadall(Puppet.lookup(:current_environment)) if provider_hash.empty? provider_hash.find_all { |_name, provider| provider.suitable? }.collect { |_name, provider| provider }.reject { |p| p.name == :fake } # For testing end |
.title_patterns ⇒ Array<Array<Regexp, Array<Array <Symbol, Proc>>>>?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Advanced: some logic requires this mapping to be done differently, using a different validation/pattern, breaking up the title into several parts assigning each to an individual attribute, or even use a composite identity where all namevars are seen as part of the unique identity (such computation is done by the #uniqueness method. These advanced options are rarely used (only one of the built in puppet types use this, and then only a small part of the available functionality), and the support for these advanced mappings is not implemented in a straight forward way. For these reasons, this method has been marked as private).
Returns a mapping from the title string to setting of attribute values. This default implementation provides a mapping of title to the one and only namevar present in the type’s definition.
428 429 430 431 432 433 434 435 436 |
# File 'lib/puppet/type.rb', line 428 def self.title_patterns case key_attributes.length when 0; [] when 1; [[/(.*)/m, [[key_attributes.first]]]] else raise Puppet::DevError, _("you must specify title patterns when there are two or more key attributes") end end |
.to_s ⇒ String
Returns the name of this type (if specified) or the parent type #to_s. The returned name is on the form “Puppet::Type::<name>”, where the first letter of name is capitalized.
2230 2231 2232 2233 2234 2235 2236 |
# File 'lib/puppet/type.rb', line 2230 def self.to_s if defined?(@name) "Puppet::Type::#{@name.to_s.capitalize}" else super end end |
.unprovide(name) ⇒ Object
this needs a better explanation
Removes the implementation class of a given provider.
1895 1896 1897 1898 1899 1900 1901 |
# File 'lib/puppet/type.rb', line 1895 def self.unprovide(name) if @defaultprovider and @defaultprovider.name == name @defaultprovider = nil end rmclass(name, :hash => provider_hash, :prefix => "Provider") end |
.valid_parameter?(name) ⇒ Boolean
see comment in code - how should this be documented? Are some of the other query methods deprecated? (or should be).
Returns whether or not the given name is the name of a property, parameter or meta-parameter
610 611 612 |
# File 'lib/puppet/type.rb', line 610 def self.valid_parameter?(name) validattr?(name) end |
.validate {|| ... } ⇒ void
This method returns an undefined value.
Creates a ‘validate` method that is used to validate a resource before it is operated on. The validation should raise exceptions if the validation finds errors. (It is not recommended to issue warnings as this typically just ends up in a logfile - you should fail if a validation fails). The easiest way to raise an appropriate exception is to call the method Util::Errors.fail with the message as an argument.
2249 2250 2251 2252 2253 2254 2255 2256 2257 |
# File 'lib/puppet/type.rb', line 2249 def self.validate(&block) define_method(:unsafe_validate, &block) define_method(:validate) do return if enum_for(:eachparameter).any? { |p| p.value.instance_of?(Puppet::Pops::Evaluator::DeferredValue) } unsafe_validate end end |
.validattr?(name) ⇒ Boolean
Returns whether or not the given name is the name of a property, parameter or meta-parameter
570 571 572 573 574 575 576 577 578 579 580 581 |
# File 'lib/puppet/type.rb', line 570 def self.validattr?(name) name = name.intern return true if name == :name @validattrs ||= {} unless @validattrs.include?(name) @validattrs[name] = !!(validproperty?(name) or validparameter?(name) or (name)) end @validattrs[name] end |
.validparameter?(name) ⇒ Boolean
Returns true if the given name is the name of an existing parameter
600 601 602 603 604 |
# File 'lib/puppet/type.rb', line 600 def self.validparameter?(name) raise Puppet::DevError, _("Class %{class_name} has not defined parameters") % { class_name: self } unless defined?(@parameters) !!(@paramhash.include?(name) or @@metaparamhash.include?(name)) end |
.validproperties ⇒ Array<Symbol>, {}
An empty hash is returned if there are no defined parameters (not an empty array). This looks like a bug.
Returns a list of valid property names, or an empty hash if there are none.
593 594 595 596 597 |
# File 'lib/puppet/type.rb', line 593 def self.validproperties return {} unless defined?(@parameters) @validproperties.keys end |
.validproperty?(name) ⇒ Boolean
Returns true if the given name is the name of an existing property
584 585 586 587 |
# File 'lib/puppet/type.rb', line 584 def self.validproperty?(name) name = name.intern @validproperties.include?(name) && @validproperties[name] end |
.validprovider?(name) ⇒ Boolean
How does the provider know if it is suitable for the type? Is it just suitable for the platform/ environment where this method is executing?
Returns true if the given name is a reference to a provider and if this is a suitable provider for this type.
1768 1769 1770 1771 1772 |
# File 'lib/puppet/type.rb', line 1768 def self.validprovider?(name) name = name.intern provider_hash.has_key?(name) && provider_hash[name].suitable? end |
Instance Method Details
#<=>(other) ⇒ -1, ...
Compares this type against the given other (type) and returns -1, 0, or +1 depending on the order.
100 101 102 103 104 105 106 107 |
# File 'lib/puppet/type.rb', line 100 def <=>(other) # Order is only maintained against other types, not arbitrary objects. # The natural order is based on the reference name used when comparing return nil unless other.is_a?(Puppet::CompilableResourceType) || other.class.is_a?(Puppet::CompilableResourceType) # against other type instances. ref <=> other.ref end |
#[](name) ⇒ Object
Gets the ‘should’ (wanted state) value of a parameter or property by name. To explicitly get the ‘is’ (current state) value use ‘o.is(:name)`, and to explicitly get the ’should’ value use ‘o.should(:name)`
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 |
# File 'lib/puppet/type.rb', line 648 def [](name) name = name.intern fail("Invalid parameter #{name}(#{name.inspect})") unless self.class.validattr?(name) if name == :name nv = name_var name = nv if nv end obj = @parameters[name] if obj # Note that if this is a property, then the value is the "should" value, # not the current value. obj.value else nil end end |
#[]=(name, value) ⇒ Object
Sets the ‘should’ (wanted state) value of a property, or the value of a parameter.
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 |
# File 'lib/puppet/type.rb', line 672 def []=(name, value) name = name.intern fail("no parameter named '#{name}'") unless self.class.validattr?(name) if name == :name nv = name_var name = nv if nv end raise Puppet::Error, "Got nil value for #{name}" if value.nil? property = newattr(name) if property begin # make sure the parameter doesn't have any errors property.value = value rescue Puppet::Error, ArgumentError => detail error = Puppet::ResourceError.new(_("Parameter %{name} failed on %{ref}: %{detail}") % { name: name, ref: ref, detail: detail }) adderrorcontext(error, detail) raise error end end end |
#add_property_parameter(prop_name) ⇒ Boolean
Creates a new property value holder for the resource if it is valid and does not already exist
621 622 623 624 625 626 627 |
# File 'lib/puppet/type.rb', line 621 def add_property_parameter(prop_name) if self.class.validproperty?(prop_name) && !@parameters[prop_name] newattr(prop_name) return true end false end |
#ancestors ⇒ Array<???>
WHAT IS THIS ?
Returns the ancestors - WHAT? This implementation always returns an empty list.
1009 1010 1011 |
# File 'lib/puppet/type.rb', line 1009 def ancestors [] end |
#appliable_to_device? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if a resource of this type can be evaluated on a ‘network device’ kind of hosts.
2616 2617 2618 |
# File 'lib/puppet/type.rb', line 2616 def appliable_to_device? self.class.can_apply_to(:device) end |
#appliable_to_host? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if a resource of this type can be evaluated on a regular generalized computer (ie not an appliance like a network device)
2623 2624 2625 |
# File 'lib/puppet/type.rb', line 2623 def appliable_to_host? self.class.can_apply_to(:host) end |
#autobefore(rel_catalog = nil) ⇒ Object
2117 2118 2119 |
# File 'lib/puppet/type.rb', line 2117 def autobefore(rel_catalog = nil) autorelation(:before, rel_catalog) end |
#autonotify(rel_catalog = nil) ⇒ Object
2125 2126 2127 |
# File 'lib/puppet/type.rb', line 2125 def autonotify(rel_catalog = nil) autorelation(:notify, rel_catalog) end |
#autorelation(rel_type, rel_catalog = nil) ⇒ Object
needs details - see the param rel_catalog, and type of this param
Adds dependencies to the catalog from added autorelations. See autorequire for how to add an auto-requirement.
2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 |
# File 'lib/puppet/type.rb', line 2074 def autorelation(rel_type, rel_catalog = nil) rel_catalog ||= catalog raise Puppet::DevError, _("You cannot add relationships without a catalog") unless rel_catalog reqs = [] auto_rel = "eachauto#{rel_type}".to_sym self.class.send(auto_rel) { |type, block| # Ignore any types we can't find, although that would be a bit odd. next unless Puppet::Type.type(type) # Retrieve the list of names from the block. list = instance_eval(&block) next unless list list = [list] unless list.is_a?(Array) # Collect the current prereqs list.each { |dep| next if dep.nil? # Support them passing objects directly, to save some effort. unless dep.is_a?(Puppet::Type) # Skip autorelation that we aren't managing dep = rel_catalog.resource(type, dep) next unless dep end if [:require, :subscribe].include?(rel_type) reqs << Puppet::Relationship.new(dep, self) else reqs << Puppet::Relationship.new(self, dep) end } } reqs end |
#autorequire(rel_catalog = nil) ⇒ Object
2113 2114 2115 |
# File 'lib/puppet/type.rb', line 2113 def autorequire(rel_catalog = nil) autorelation(:require, rel_catalog) end |
#autosubscribe(rel_catalog = nil) ⇒ Object
2121 2122 2123 |
# File 'lib/puppet/type.rb', line 2121 def autosubscribe(rel_catalog = nil) autorelation(:subscribe, rel_catalog) end |
#builddepends ⇒ Array<Puppet::Relationship>
Builds the dependencies associated with this resource.
2132 2133 2134 2135 2136 2137 2138 |
# File 'lib/puppet/type.rb', line 2132 def builddepends # Handle the requires self.class.relationship_params.collect do |klass| param = @parameters[klass.name] param.to_edges if param end.flatten.compact end |
#copy_metaparams(parameters) ⇒ Void
Copies all of a resource’s metaparameters (except ‘alias`) to a generated child resource
365 366 367 368 369 370 |
# File 'lib/puppet/type.rb', line 365 def (parameters) parameters.each do |name, param| self[name] = param.value if param. && name != :alias end nil end |
#currentpropvalues ⇒ Hash{Puppet::Property => Object}
Returns a hash of the current properties and their values. If a resource is absent, its value is the symbol ‘:absent`
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 |
# File 'lib/puppet/type.rb', line 1110 def currentpropvalues # It's important to use the 'properties' method here, as it follows the order # in which they're defined in the class. It also guarantees that 'ensure' # is the first property, which is important for skipping 'retrieve' on # all the properties if the resource is absent. ensure_state = false properties.each_with_object({}) do |property, prophash| if property.name == :ensure ensure_state = property.retrieve prophash[property] = ensure_state elsif ensure_state == :absent prophash[property] = :absent else prophash[property] = property.retrieve end end end |
#delete(attr) ⇒ Object
Don’t know what the attr is (name or Property/Parameter?). Guessing it is a String name…
Is it possible to delete a meta-parameter?
What does delete mean? Is it deleted from the type or is its value state ‘is’/‘should’ deleted?
Removes an attribute from the object; useful in testing or in cleanup when an error has been encountered
706 707 708 709 710 711 712 713 |
# File 'lib/puppet/type.rb', line 706 def delete(attr) attr = attr.intern if @parameters.has_key?(attr) @parameters.delete(attr) else raise Puppet::DevError, _("Undefined attribute '%{attribute}' in %{name}") % { attribute: attr, name: self } end end |
#deleting? ⇒ Boolean
Returns true if the wanted state of the resource is that it should be absent (i.e. to be deleted).
615 616 617 |
# File 'lib/puppet/type.rb', line 615 def deleting? obj = @parameters[:ensure] and obj.should == :absent end |
#depthfirst? ⇒ Boolean
What is this used for?
Returns true if the search should be done in depth-first order. This implementation always returns false.
978 979 980 |
# File 'lib/puppet/type.rb', line 978 def depthfirst? false end |
#eachparameter {|parameter| ... } ⇒ void
This method returns an undefined value.
Iterates over all parameters with value currently set.
735 736 737 |
# File 'lib/puppet/type.rb', line 735 def eachparameter parameters_with_value.each { |parameter| yield parameter } end |
#eachproperty {|property| ... } ⇒ void
This method returns an undefined value.
Iterates over the properties that were set on this resource.
718 719 720 721 722 723 |
# File 'lib/puppet/type.rb', line 718 def eachproperty # properties is a private method properties.each { |property| yield property } end |
#event(options = {}) ⇒ Puppet::Transaction::Event
Needs a better explanation “Why should I care who is calling this method?”, What do I need to know about events and how they work? Where can I read about them?
Creates a transaction event. Called by Transaction or by a property. Merges the given options with the options ‘:resource`, `:file`, `:line`, and `:tags`, initialized from values in this object. For possible options to pass (if any ????) see Puppet::Transaction::Event.
747 748 749 |
# File 'lib/puppet/type.rb', line 747 def event( = {}) Puppet::Transaction::Event.new(**{ :resource => self, :file => file, :line => line, :tags => }.merge()) end |
#exported? ⇒ Boolean
Returns whether the resource is exported or not
2610 |
# File 'lib/puppet/type.rb', line 2610 def exported?; !!@exported; end |
#finish ⇒ Array<Puppet::Parameter>
what is the expected sequence here - who is responsible for calling this? When? Is the returned type correct?
Finishes any outstanding processing. This method should be called as a final step in setup, to allow the parameters that have associated auto-require needs to be processed.
2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 |
# File 'lib/puppet/type.rb', line 2475 def finish # Call post_compile hook on every parameter that implements it. This includes all subclasses # of parameter including, but not limited to, regular parameters, metaparameters, relationship # parameters, and properties. eachparameter do |parameter| parameter.post_compile if parameter.respond_to? :post_compile end # Make sure all of our relationships are valid. Again, must be done # when the entire catalog is instantiated. self.class.relationship_params.collect do |klass| param = @parameters[klass.name] param.validate_relationship if param end.flatten.compact end |
#flush ⇒ ????
What does Flushing the provider mean? Why is it interesting to know that this is called by the transaction? (It is not explained anywhere what a transaction is).
Flushes the provider if supported by the provider, else no action. This is called by the transaction.
1035 1036 1037 |
# File 'lib/puppet/type.rb', line 1035 def flush provider.flush if provider and provider.respond_to?(:flush) end |
#isomorphic? ⇒ Boolean
check that this gets documentation (it is at the class level as well as instance).
(see isomorphic?)
942 943 944 |
# File 'lib/puppet/type.rb', line 942 def isomorphic? self.class.isomorphic? end |
#log(msg) ⇒ void
This method returns an undefined value.
Creates a log entry with the given message at the log level specified by the parameter ‘loglevel`
2279 2280 2281 2282 2283 2284 2285 2286 |
# File 'lib/puppet/type.rb', line 2279 def log(msg) Puppet::Util::Log.create( :level => @parameters[:loglevel].value, :message => msg, :source => self ) end |
#managed? ⇒ Boolean
An object that is managed always stays managed, but an object that is not managed may become managed later in its lifecycle.
Returns true if the instance is a managed instance. A ‘yes’ here means that the instance was created from the language, vs. being created in order resolve other questions, such as finding a package in a list.
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 |
# File 'lib/puppet/type.rb', line 952 def managed? # Once an object is managed, it always stays managed; but an object # that is listed as unmanaged might become managed later in the process, # so we have to check that every time unless @managed @managed = false properties.each { |property| s = property.should if s and !property.class.unmanaged @managed = true break end } end @managed end |
#name ⇒ String
There is a comment in source that this is not quite the same as ‘:title’ and that a switch should be made…
Returns the resource’s name
2497 2498 2499 |
# File 'lib/puppet/type.rb', line 2497 def name self[:name] end |
#name_var ⇒ Symbol, Boolean
Returns the name of the namevar if there is only one or false otherwise.
636 637 638 639 640 641 |
# File 'lib/puppet/type.rb', line 636 def name_var return @name_var_cache unless @name_var_cache.nil? key_attributes = self.class.key_attributes @name_var_cache = (key_attributes.length == 1) && key_attributes.first end |
#newattr(name) ⇒ Object #newattr(klass) ⇒ Object
Registers an attribute to this resource type instance. Requires either the attribute name or class as its argument. This is a noop if the named property/parameter is not supported by this resource. Otherwise, an attribute instance is created and kept in this resource’s parameters hash.
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 |
# File 'lib/puppet/type.rb', line 775 def newattr(name) if name.is_a?(Class) klass = name name = klass.name end klass = self.class.attrclass(name) unless klass raise Puppet::Error, "Resource type #{self.class.name} does not support parameter #{name}" end if provider and !provider.class.supports_parameter?(klass) missing = klass.required_features.find_all { |f| !provider.class.feature?(f) } debug "Provider %s does not support features %s; not managing attribute %s" % [provider.class.name, missing.join(", "), name] return nil end return @parameters[name] if @parameters.include?(name) @parameters[name] = klass.new(:resource => self) end |
#noop? ⇒ Boolean
Returns the ‘noop` run mode status of this.
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 |
# File 'lib/puppet/type.rb', line 1130 def noop? # If we're not a host_config, we're almost certainly part of # Settings, and we want to ignore 'noop' return false if catalog and !catalog.host_config? if defined?(@noop) @noop else Puppet[:noop] end end |
#parameter(name) ⇒ Object
Returns the value of this object’s parameter given by name
807 808 809 |
# File 'lib/puppet/type.rb', line 807 def parameter(name) @parameters[name.to_sym] end |
#parameters ⇒ Hash{String => Object}
Returns a shallow copy of this object’s hash of attributes by name. Note that his not only comprises parameters, but also properties and metaparameters. Changes to the contained parameters will have an effect on the parameters of this type, but changes to the returned hash does not.
816 817 818 |
# File 'lib/puppet/type.rb', line 816 def parameters @parameters.dup end |
#parameters_with_value ⇒ Array<Puppet::Parameter>
Return the parameters, metaparams, and properties that have a value or were set by a default. Properties are included since they are a subclass of parameter.
728 729 730 |
# File 'lib/puppet/type.rb', line 728 def parameters_with_value self.class.allattrs.filter_map { |attr| parameter(attr) } end |
#parent ⇒ Puppet::Type?
Returns the parent of this in the catalog. In case of an erroneous catalog where multiple parents have been produced, the first found (non deterministic) parent is returned.
2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 |
# File 'lib/puppet/type.rb', line 2507 def parent return nil unless catalog return @parent if @parent parents = catalog.adjacent(self, :direction => :in) @parent = if parents parents.shift else nil end end |
#path ⇒ String
Returns a string representation of the resource’s containment path in the catalog.
800 801 802 |
# File 'lib/puppet/type.rb', line 800 def path @path ||= '/' + pathbuilder.join('/') end |
#pathbuilder ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an array of strings representing the containment hierarchy (types/classes) that make up the path to the resource from the root of the catalog. This is mostly used for logging purposes.
1227 1228 1229 1230 1231 1232 1233 1234 |
# File 'lib/puppet/type.rb', line 1227 def pathbuilder p = parent if p [p.pathbuilder, ref].flatten else [ref] end end |
#pre_run_check ⇒ void
a resource type may implement this method to perform validation checks that can query the complete catalog
This method returns an undefined value.
Lifecycle method for a resource. This is called during graph creation. It should perform any consistency checking of the catalog and raise a Puppet::Error if the transaction should be aborted.
It differs from the validate method, since it is called later during initialization and can rely on self.catalog to have references to all resources that comprise the catalog.
1026 1027 |
# File 'lib/puppet/type.rb', line 1026 def pre_run_check end |
#present?(current_values) ⇒ Boolean
Given the hash of current properties, should this resource be treated as if it currently exists on the system. May need to be overridden by types that offer up more than just :absent and :present.
1102 1103 1104 |
# File 'lib/puppet/type.rb', line 1102 def present?(current_values) current_values[:ensure] != :absent end |
#properties ⇒ Array<Puppet::Property>
“what does the ‘order specified in the class’ mean? The order the properties where added in the ruby file adding a new type with new properties?
Returns all of the property objects, in the order specified in the class.
923 924 925 |
# File 'lib/puppet/type.rb', line 923 def properties self.class.properties.filter_map { |prop| @parameters[prop.name] } end |
#property(name) ⇒ Puppet::Property
832 833 834 835 836 837 838 839 |
# File 'lib/puppet/type.rb', line 832 def property(name) obj = @parameters[name.intern] if obj && obj.is_a?(Puppet::Property) obj else nil end end |
#propertydefined?(name) ⇒ Boolean
Returns whether the attribute given by name has been added to this resource or not.
822 823 824 825 |
# File 'lib/puppet/type.rb', line 822 def propertydefined?(name) name = name.intern unless name.is_a? Symbol @parameters.include?(name) end |
#purging ⇒ Object
what does this mean; “mark that we are purging” (purging what from where). How to use/when? Is this internal API in transactions?
Marks the object as “being purged”. This method is used by transactions to forbid deletion when there are dependencies.
2541 2542 2543 |
# File 'lib/puppet/type.rb', line 2541 def purging @purging = true end |
#purging? ⇒ Boolean
Returns whether this resource is being purged or not. This method is used by transactions to forbid deletion when there are dependencies.
2549 2550 2551 2552 2553 2554 2555 |
# File 'lib/puppet/type.rb', line 2549 def purging? if defined?(@purging) @purging else false end end |
#ref ⇒ String
Returns a reference to this as a string in “Type” format.
2522 2523 2524 2525 2526 |
# File 'lib/puppet/type.rb', line 2522 def ref # memoizing this is worthwhile ~ 3 percent of calls are the "first time # around" in an average run of Puppet. --daniel 2012-07-17 @ref ||= "#{self.class.name.to_s.capitalize}[#{title}]" end |
#remove ⇒ void
removes if from where?
This method returns an undefined value.
Removes this object (FROM WHERE?)
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 |
# File 'lib/puppet/type.rb', line 985 def remove # This is hackish (mmm, cut and paste), but it works for now, and it's # better than warnings. @parameters.each do |_name, obj| obj.remove end @parameters.clear @parent = nil # Remove the reference to the provider. if provider @provider.clear @provider = nil end end |
#retrieve ⇒ Puppet::Resource
As opposed to all non contained properties? How is this different than any of the other methods that also “gets” properties/parameters/etc. ?
Retrieves the current value of all contained properties. Parameters and meta-parameters are not included in the result.
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 |
# File 'lib/puppet/type.rb', line 1051 def retrieve fail "Provider #{provider.class.name} is not functional on this host" if provider.is_a?(Puppet::Provider) and !provider.class.suitable? result = Puppet::Resource.new(self.class, title) # Provide the name, so we know we'll always refer to a real thing result[:name] = self[:name] unless self[:name] == title ensure_prop = property(:ensure) if !ensure_prop && self.class.needs_ensure_retrieved && self.class.validattr?(:ensure) ensure_prop = newattr(:ensure) end if ensure_prop result[:ensure] = ensure_state = ensure_prop.retrieve else ensure_state = nil end properties.each do |property| next if property.name == :ensure if ensure_state == :absent result[property] = :absent else result[property] = property.retrieve end end result end |
#retrieve_resource ⇒ Puppet::Resource
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Retrieve the current state of the system as a Puppet::Resource. For the base Puppet::Type this does the same thing as #retrieve, but specific types are free to implement #retrieve as returning a hash, and this will call #retrieve and convert the hash to a resource. This is used when determining when syncing a resource.
1093 1094 1095 1096 1097 |
# File 'lib/puppet/type.rb', line 1093 def retrieve_resource resource = retrieve resource = Resource.new(self.class, title, :parameters => resource) if resource.is_a? Hash resource end |
#self_refresh? ⇒ Boolean
check that meaningful yardoc is produced - this method delegates to “self.class.self_refresh”
2532 2533 2534 |
# File 'lib/puppet/type.rb', line 2532 def self_refresh? self.class.self_refresh end |
#set_default(attr) ⇒ void
comment says “For any parameters or properties that have defaults and have not yet been set, set them now. This method can be handed a list of attributes, and if so it will only set defaults for those attributes.”
Needs a better explanation, and investigation about the claim an array can be passed (it is passed to self.class.attrclass to produce a class on which a check is made if it has a method class :default (does not seem to support an array…
This method returns an undefined value.
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 |
# File 'lib/puppet/type.rb', line 849 def set_default(attr) klass = self.class.attrclass(attr) return unless klass # TODO this is not a necessary check, as we define a class level attr_reader return unless klass.method_defined?(:default) return if @parameters.include?(klass.name) parameter = newattr(klass.name) return unless parameter value = parameter.default if value and !value.nil? parameter.value = value else @parameters.delete(parameter.name) end end |
#should(name) ⇒ Object?
Returns the ‘should’ (wanted state) value for a specified property, or nil if the given attribute name is not a property (i.e. if it is a parameter, meta-parameter, or does not exist).
753 754 755 756 757 758 759 760 |
# File 'lib/puppet/type.rb', line 753 def should(name) prop = @parameters[name.intern] if prop && prop.is_a?(Puppet::Property) prop.should else nil end end |
#suitable? ⇒ Boolean
Returns true if this is something else than a ‘:provider`, or if it is a provider and it is suitable, or if there is a default provider. Otherwise, false is returned.
1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 |
# File 'lib/puppet/type.rb', line 1921 def suitable? # If we don't use providers, then we consider it suitable. return true unless self.class.paramclass(:provider) # We have a provider and it is suitable. return true if provider && provider.class.suitable? # We're using the default provider and there is one. if !provider and self.class.defaultprovider self.provider = self.class.defaultprovider.name return true end # We specified an unsuitable provider, or there isn't any suitable # provider. false end |
#tags=(list) ⇒ void
This method returns an undefined value.
Sets the initial list of tags to associate to this resource.
2143 2144 2145 2146 |
# File 'lib/puppet/type.rb', line 2143 def (list) tag(self.class.name) tag(*list) end |
#to_hash ⇒ Hash{ ??? => ??? }
the comment says: “Convert our object to a hash. This just includes properties.”
this is confused, again it is the @parameters instance variable that is consulted, and each value is copied - does it contain “properties” and “parameters” or both? Does it contain meta-parameters?
Returns a hash of WHAT?. The hash is a shallow copy, any changes to the objects returned in this hash will be reflected in the original resource having these attributes.
875 876 877 878 879 880 881 882 883 |
# File 'lib/puppet/type.rb', line 875 def to_hash rethash = {} @parameters.each do |name, obj| rethash[name] = obj.value end rethash end |
#to_resource ⇒ Puppet::Resource
Convert this resource type instance to a Puppet::Resource.
2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 |
# File 'lib/puppet/type.rb', line 2590 def to_resource resource = retrieve_resource resource.(self) @parameters.each do |name, param| # Avoid adding each instance name twice next if param.class.isnamevar? and param.value == title # We've already got property values next if param.is_a?(Puppet::Property) resource[name] = param.value end resource end |
#to_s ⇒ Object
Produces a reference to this in reference format.
2583 2584 2585 |
# File 'lib/puppet/type.rb', line 2583 def to_s ref end |
#type ⇒ String
Would that be “file” for the “File” resource type? of “File” or something else?
Returns the name of this object’s class.
888 889 890 |
# File 'lib/puppet/type.rb', line 888 def type self.class.name end |
#uniqueness_key ⇒ Object
Produces a resource’s uniqueness_key (or composite key). This key is an array of all key attributes’ values. Each distinct tuple must be unique for each resource type.
443 444 445 |
# File 'lib/puppet/type.rb', line 443 def uniqueness_key self.class.key_attributes.sort_by(&:to_s).map { |attribute_name| self[attribute_name] } end |
#validate_resource ⇒ void
This method returns an undefined value.
Optionally validate the resource. This method is a noop if the type has not defined a ‘validate` method using the puppet DSL. If validation fails, then an exception will be raised with this resources as the context.
2355 2356 2357 2358 2359 2360 2361 |
# File 'lib/puppet/type.rb', line 2355 def validate_resource validate if respond_to?(:validate) rescue Puppet::Error, ArgumentError => detail error = Puppet::ResourceError.new("Validation of #{ref} failed: #{detail}") adderrorcontext(error, detail) raise error end |
#value(name) ⇒ Object?
Comment says “Return a specific value for an attribute.”, as opposed to what “An unspecific value”???
is this the ‘is’ or the ‘should’ value?
why is the return restricted to things that respond to :value? (Only non structural basic data types supported?
Returns the value of the attribute having the given name, or nil if the given name is not an attribute, or the referenced attribute does not respond to ‘:value`.
899 900 901 902 903 904 905 906 907 908 |
# File 'lib/puppet/type.rb', line 899 def value(name) name = name.intern obj = @parameters[name] if obj && obj.respond_to?(:value) obj.value else nil end end |
#version ⇒ ???
What is this used for? Needs a better explanation.
Returns the version of the catalog or 0 if there is no catalog.
912 913 914 915 916 |
# File 'lib/puppet/type.rb', line 912 def version return 0 unless catalog catalog.version end |
#virtual? ⇒ Boolean
Returns whether the resource is virtual or not
2608 |
# File 'lib/puppet/type.rb', line 2608 def virtual?; !!@virtual; end |