Class: Puppet::Type
- Extended by:
- Enumerable, MetaType::Manager, Util, Util::ClassGen, Util::Logging, Util::ProviderFeatures, Util::Warnings
- Includes:
- Enumerable, FileCollection::Lookup, Util, Util::Cacher, Util::Errors, Util::LogPaths, Util::Logging, Util::Tagging
- Defined in:
- lib/puppet/type.rb
Defined Under Namespace
Classes: RelationshipMetaparam
Class Attribute Summary collapse
-
.defaultprovider ⇒ Object
Find the default provider.
-
.name ⇒ Object
readonly
Returns the value of attribute name.
-
.properties ⇒ Object
readonly
Returns the value of attribute properties.
-
.providerloader ⇒ Object
Returns the value of attribute providerloader.
-
.self_refresh ⇒ Object
Returns the value of attribute self_refresh.
Instance Attribute Summary collapse
-
#catalog ⇒ Object
The catalog that this resource is stored in.
-
#exported ⇒ Object
is the resource exported.
- #noop ⇒ Object
-
#original_parameters ⇒ Object
readonly
Returns the value of attribute original_parameters.
-
#provider ⇒ Object
Returns the value of attribute provider.
-
#title ⇒ Object
Retrieve the title of an object.
-
#virtual ⇒ Object
is the resource virtual (it should not :-)).
Attributes included from Util::Docs
Attributes included from FileCollection::Lookup
Attributes included from Util::Cacher::Expirer
Class Method Summary collapse
-
.[](name) ⇒ Object
retrieve a named instance of the current type.
-
.[]=(name, object) ⇒ Object
add an instance by name to the class list of instances.
-
.alias(name, obj) ⇒ Object
Create an alias.
-
.allattrs ⇒ Object
All parameters, in the appropriate order.
-
.attr_alias(param) ⇒ Object
Retrieve an attribute alias, if there is one.
-
.attrclass(name) ⇒ Object
Find the class associated with any given attribute.
-
.attrtype(attr) ⇒ Object
What type of parameter are we dealing with? Cache the results, because this method gets called so many times.
-
.autorequire(name, &block) ⇒ Object
Specify a block for generating a list of objects to autorequire.
-
.clear ⇒ Object
remove all of the instances of a single type.
-
.create(args) ⇒ Object
Force users to call this, so that we can merge objects if necessary.
-
.delete(resource) ⇒ Object
remove a specified object.
-
.depthfirst? ⇒ Boolean
this is a retarded hack method to get around the difference between component children and file children.
-
.each ⇒ Object
iterate across each of the type’s instances.
-
.eachautorequire ⇒ Object
Yield each of those autorequires in turn, yo.
- .eachmetaparam ⇒ Object
-
.ensurable(&block) ⇒ Object
Create the ‘ensure’ class.
-
.ensurable? ⇒ Boolean
Should we add the ‘ensure’ property to this class?.
-
.handle_param_options(name, options) ⇒ Object
Deal with any options passed into parameters.
-
.has_key?(name) ⇒ Boolean
does the type have an object with the given name?.
-
.hash2resource(hash) ⇒ Object
Convert a simple hash into a Resource instance.
-
.initvars ⇒ Object
all of the variables that must be initialized for each subclass.
-
.instances ⇒ Object
Retrieve all known instances.
-
.isomorphic? ⇒ Boolean
Is this type’s name isomorphic with the object? That is, if the name conflicts, does it necessarily mean that the objects conflict? Defaults to true.
- .key_attribute_parameters ⇒ Object
- .key_attributes ⇒ Object
-
.metaparam?(param) ⇒ Boolean
Is the parameter in question a meta-parameter?.
-
.metaparamclass(name) ⇒ Object
Find the metaparameter class associated with a given metaparameter name.
- .metaparamdoc(metaparam) ⇒ Object
- .metaparams ⇒ Object
-
.newmetaparam(name, options = {}, &block) ⇒ Object
Create a new metaparam.
-
.newparam(name, options = {}, &block) ⇒ Object
Create a new parameter.
-
.newproperty(name, options = {}, &block) ⇒ Object
Create a new property.
- .newstate(name, options = {}, &block) ⇒ Object
-
.paramclass(name) ⇒ Object
Find the parameter class associated with a given parameter name.
- .paramdoc(param) ⇒ Object
-
.parameters ⇒ Object
Return the parameter names.
-
.propertybyname(name) ⇒ Object
Return the property class associated with a name.
-
.provide(name, options = {}, &block) ⇒ Object
Create a new provider of a type.
-
.provider(name) ⇒ Object
Retrieve a provider by name.
- .provider_hash ⇒ Object
- .provider_hash_by_type(type) ⇒ Object
-
.providers ⇒ Object
Just list all of the providers.
-
.providers_by_source ⇒ Object
Return a list of one suitable provider per source, with the default provider first.
-
.providify ⇒ Object
Make sure we have a :provider parameter defined.
- .relationship_params ⇒ Object
-
.set_attr_alias(hash) ⇒ Object
Create an alias to an existing attribute.
- .states ⇒ Object
-
.suitableprovider ⇒ Object
Return an array of all of the suitable providers.
- .title_patterns ⇒ Object
- .to_s ⇒ Object
- .unprovide(name) ⇒ Object
-
.valid_parameter?(name) ⇒ Boolean
This is a forward-compatibility method - it’s the validity interface we’ll use in Puppet::Resource.
-
.validate(&block) ⇒ Object
Create a block to validate that our object is set up entirely.
- .validattr?(name) ⇒ Boolean
-
.validparameter?(name) ⇒ Boolean
does the name reflect a valid parameter?.
-
.validproperties ⇒ Object
Return the list of validproperties.
-
.validproperty?(name) ⇒ Boolean
does the name reflect a valid property?.
- .validprovider?(name) ⇒ Boolean
Instance Method Summary collapse
-
#[](name) ⇒ Object
abstract accessing parameters and properties, and normalize access to always be symbols, not strings This returns a value, not an object.
-
#[]=(name, value) ⇒ Object
Abstract setting parameters and properties, and normalize access to always be symbols, not strings.
-
#add_property_parameter(prop_name) ⇒ Object
Create a new property if it is valid but doesn’t exist Returns: true if a new parameter was added, false otherwise.
-
#attr_alias(name) ⇒ Object
Return either the attribute alias or the attribute.
-
#autorequire(rel_catalog = nil) ⇒ Object
Figure out of there are any objects we can automatically add as dependencies.
-
#builddepends ⇒ Object
Build the dependencies associated with an individual object.
-
#currentpropvalues ⇒ Object
Get a hash of the current properties.
-
#delete(attr) ⇒ Object
remove a property from the object; useful in testing or in cleanup when an error has been encountered.
-
#deleting? ⇒ Boolean
Are we deleting this resource?.
- #depthfirst? ⇒ Boolean
-
#eachproperty ⇒ Object
iterate across the existing properties.
-
#event(options = {}) ⇒ Object
Create a transaction event.
-
#expirer ⇒ Object
Let the catalog determine whether a given cached value is still valid or has expired.
- #exported? ⇒ Boolean
-
#finish ⇒ Object
Set up all of our autorequires.
-
#flush ⇒ Object
Flush the provider, if it supports it.
-
#initialize(resource) ⇒ Type
constructor
initialize the type instance.
-
#insync?(is) ⇒ Boolean
if all contained objects are in sync, then we’re in sync FIXME I don’t think this is used on the type instances any more, it’s really only used for testing.
- #isomorphic? ⇒ Boolean
-
#log(msg) ⇒ Object
create a log at specified level.
-
#managed? ⇒ Boolean
is the instance a managed instance? A ‘yes’ here means that the instance was created from the language, vs.
-
#name ⇒ Object
For now, leave the ‘name’ method functioning like it used to.
-
#name_var ⇒ Object
The name_var is the key_attribute in the case that there is only one.
-
#newattr(name) ⇒ Object
Create the actual attribute instance.
-
#noop? ⇒ Boolean
Are we running in noop mode?.
-
#parameter(name) ⇒ Object
return the value of a parameter.
- #parameters ⇒ Object
-
#parent ⇒ Object
Look up our parent in the catalog, if we have one.
-
#pathbuilder ⇒ Object
Create the path for logging and such.
-
#properties ⇒ Object
Return all of the property objects, in the order specified in the class.
-
#property(name) ⇒ Object
Return an actual property instance by name; to return the value, use ‘resource’ LAK:NOTE(20081028) Since the ‘parameter’ method is now a superset of this method, this one should probably go away at some point.
-
#propertydefined?(name) ⇒ Boolean
Is the named property defined?.
-
#purging ⇒ Object
Mark that we’re purging.
-
#purging? ⇒ Boolean
Is this resource being purged? Used by transactions to forbid deletion when there are dependencies.
-
#ref ⇒ Object
Return the “type” style reference.
-
#remove(rmdeps = true) ⇒ Object
Remove an object.
-
#retrieve ⇒ Object
retrieve the current value of all contained properties.
- #retrieve_resource ⇒ Object
- #self_refresh? ⇒ Boolean
-
#set_default(attr) ⇒ Object
For any parameters or properties that have defaults and have not yet been set, set them now.
-
#should(name) ⇒ Object
retrieve the ‘should’ value for a specified property.
-
#tags=(list) ⇒ Object
Define the initial list of tags.
-
#to_hash ⇒ Object
Convert our object to a hash.
- #to_resource ⇒ Object
-
#to_s ⇒ Object
convert to a string.
-
#to_trans(ret = true) ⇒ Object
Convert to a transportable object.
- #type ⇒ Object
- #uniqueness_key ⇒ Object
-
#value(name) ⇒ Object
Return a specific value for an attribute.
- #version ⇒ Object
- #virtual? ⇒ Boolean
Methods included from Util::Logging
Methods included from Util
activerecord_version, benchmark, chuser, classproxy, execfail, execpipe, execute, logmethods, memory, proxy, recmkdir, secure_open, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, threadlock, which, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from MetaType::Manager
allclear, eachtype, loadall, newtype, rmtype, typeloader
Methods included from Util::ClassGen
Methods included from Util::MethodHelper
#requiredopts, #set_options, #symbolize_options
Methods included from Util::Warnings
clear_warnings, notice_once, warnonce
Methods included from Util::ProviderFeatures
feature, feature_module, featuredocs, features, provider_feature
Methods included from Util::Docs
#desc, #dochook, #doctable, #nodoc?, #pad, scrub
Methods included from Util::Tagging
Methods included from FileCollection::Lookup
#file, #file=, #file_collection
Methods included from Util::Cacher
Methods included from Util::Cacher::Expirer
#dependent_data_expired?, #expire
Methods included from Util::LogPaths
Methods included from Util::Errors
#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail
Constructor Details
#initialize(resource) ⇒ Type
initialize the type instance
1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 |
# File 'lib/puppet/type.rb', line 1708 def initialize(resource) raise Puppet::DevError, "Got TransObject instead of Resource or hash" if resource.is_a?(Puppet::TransObject) 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 + "=" if val = resource.send(getter) self.send(setter, val) end end @tags = resource. @original_parameters = resource.to_hash set_name(@original_parameters) set_default(:provider) set_parameters(@original_parameters) self.validate if self.respond_to?(:validate) end |
Class Attribute Details
.defaultprovider ⇒ Object
Find the default provider.
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 |
# File 'lib/puppet/type.rb', line 1355 def self.defaultprovider unless @defaultprovider suitable = suitableprovider # Find which providers are a default for this system. defaults = suitable.find_all { |provider| provider.default? } # If we don't have any default we use suitable providers defaults = suitable if defaults.empty? max = defaults.collect { |provider| provider.specificity }.max defaults = defaults.find_all { |provider| provider.specificity == max } retval = nil if defaults.length > 1 Puppet.warning( "Found multiple default providers for #{self.name}: #{defaults.collect { |i| i.name.to_s }.join(", ")}; using #{defaults[0].name}" ) retval = defaults.shift elsif defaults.length == 1 retval = defaults.shift else raise Puppet::DevError, "Could not find a default provider for #{self.name}" end @defaultprovider = retval end @defaultprovider end |
.name ⇒ Object (readonly)
Returns the value of attribute name.
1624 1625 1626 |
# File 'lib/puppet/type.rb', line 1624 def name @name end |
.properties ⇒ Object (readonly)
Returns the value of attribute properties.
33 34 35 |
# File 'lib/puppet/type.rb', line 33 def properties @properties end |
.providerloader ⇒ Object
Returns the value of attribute providerloader.
1350 1351 1352 |
# File 'lib/puppet/type.rb', line 1350 def providerloader @providerloader end |
.self_refresh ⇒ Object
Returns the value of attribute self_refresh.
1625 1626 1627 |
# File 'lib/puppet/type.rb', line 1625 def self_refresh @self_refresh end |
Instance Attribute Details
#catalog ⇒ Object
The catalog that this resource is stored in.
1679 1680 1681 |
# File 'lib/puppet/type.rb', line 1679 def catalog @catalog end |
#exported ⇒ Object
is the resource exported
1682 1683 1684 |
# File 'lib/puppet/type.rb', line 1682 def exported @exported end |
#noop ⇒ Object
745 746 747 |
# File 'lib/puppet/type.rb', line 745 def noop noop? end |
#original_parameters ⇒ Object (readonly)
Returns the value of attribute original_parameters.
1705 1706 1707 |
# File 'lib/puppet/type.rb', line 1705 def original_parameters @original_parameters end |
#provider ⇒ Object
Returns the value of attribute provider.
1346 1347 1348 |
# File 'lib/puppet/type.rb', line 1346 def provider @provider end |
#title ⇒ Object
Retrieve the title of an object. If no title was set separately, then use the object’s name.
1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 |
# File 'lib/puppet/type.rb', line 1840 def title unless @title if self.class.validparameter?(name_var) @title = self[:name] elsif self.class.validproperty?(name_var) @title = self.should(name_var) else self.devfail "Could not find namevar #{name_var} for #{self.class.name}" end end @title end |
#virtual ⇒ Object
is the resource virtual (it should not :-))
1685 1686 1687 |
# File 'lib/puppet/type.rb', line 1685 def virtual @virtual end |
Class Method Details
.[](name) ⇒ Object
retrieve a named instance of the current type
754 755 756 757 |
# File 'lib/puppet/type.rb', line 754 def self.[](name) raise "Global resource access is deprecated" @objects[name] || @aliases[name] end |
.[]=(name, object) ⇒ Object
add an instance by name to the class list of instances
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 |
# File 'lib/puppet/type.rb', line 760 def self.[]=(name,object) raise "Global resource storage is deprecated" newobj = nil if object.is_a?(Puppet::Type) newobj = object else raise Puppet::DevError, "must pass a Puppet::Type object" end if exobj = @objects[name] and self.isomorphic? msg = "Object '#{newobj.class.name}[#{name}]' already exists" msg += ("in file #{object.file} at line #{object.line}") if exobj.file and exobj.line msg += ("and cannot be redefined in file #{object.file} at line #{object.line}") if object.file and object.line error = Puppet::Error.new(msg) raise error else #Puppet.info("adding %s of type %s to class list" % # [name,object.class]) @objects[name] = newobj end end |
.alias(name, obj) ⇒ Object
Create an alias. We keep these in a separate hash so that we don’t encounter the objects multiple times when iterating over them.
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 |
# File 'lib/puppet/type.rb', line 785 def self.alias(name, obj) raise "Global resource aliasing is deprecated" if @objects.include?(name) unless @objects[name] == obj raise Puppet::Error.new( "Cannot create alias #{name}: object already exists" ) end end if @aliases.include?(name) unless @aliases[name] == obj raise Puppet::Error.new( "Object #{@aliases[name].name} already has alias #{name}" ) end end @aliases[name] = obj end |
.allattrs ⇒ Object
All parameters, in the appropriate order. The key_attributes come first, then the provider, then the properties, and finally the params and metaparams in the order they were specified in the files.
44 45 46 |
# File 'lib/puppet/type.rb', line 44 def self.allattrs key_attributes | (parameters & [:provider]) | properties.collect { |property| property.name } | parameters | end |
.attr_alias(param) ⇒ Object
Retrieve an attribute alias, if there is one.
49 50 51 |
# File 'lib/puppet/type.rb', line 49 def self.attr_alias(param) @attr_aliases[symbolize(param)] end |
.attrclass(name) ⇒ Object
Find the class associated with any given attribute.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/puppet/type.rb', line 62 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 self.attrtype(name) when :property; @validproperties[name] when :meta; @@metaparamhash[name] when :param; @paramhash[name] end end @attrclasses[name] end |
.attrtype(attr) ⇒ Object
What type of parameter are we dealing with? Cache the results, because this method gets called so many times.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/puppet/type.rb', line 79 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 |
.autorequire(name, &block) ⇒ Object
Specify a block for generating a list of objects to autorequire. This makes it so that you don’t have to manually specify things that you clearly require.
1544 1545 1546 1547 |
# File 'lib/puppet/type.rb', line 1544 def self.autorequire(name, &block) @autorequires ||= {} @autorequires[name] = block end |
.clear ⇒ Object
remove all of the instances of a single type
807 808 809 810 811 812 813 814 815 816 |
# File 'lib/puppet/type.rb', line 807 def self.clear raise "Global resource removal is deprecated" if defined?(@objects) @objects.each do |name, obj| obj.remove(true) end @objects.clear end @aliases.clear if defined?(@aliases) end |
.create(args) ⇒ Object
Force users to call this, so that we can merge objects if necessary.
820 821 822 823 824 |
# File 'lib/puppet/type.rb', line 820 def self.create(args) # LAK:DEP Deprecation notice added 12/17/2008 Puppet.warning "Puppet::Type.create is deprecated; use Puppet::Type.new" new(args) end |
.delete(resource) ⇒ Object
remove a specified object
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 |
# File 'lib/puppet/type.rb', line 827 def self.delete(resource) raise "Global resource removal is deprecated" return unless defined?(@objects) @objects.delete(resource.title) if @objects.include?(resource.title) @aliases.delete(resource.title) if @aliases.include?(resource.title) if @aliases.has_value?(resource) names = [] @aliases.each do |name, otherres| if otherres == resource names << name end end names.each { |name| @aliases.delete(name) } end end |
.depthfirst? ⇒ Boolean
this is a retarded hack method to get around the difference between component children and file children
603 604 605 |
# File 'lib/puppet/type.rb', line 603 def self.depthfirst? @depthfirst end |
.each ⇒ Object
iterate across each of the type’s instances
844 845 846 847 848 849 850 |
# File 'lib/puppet/type.rb', line 844 def self.each raise "Global resource iteration is deprecated" return unless defined?(@objects) @objects.each { |name,instance| yield instance } end |
.eachautorequire ⇒ Object
Yield each of those autorequires in turn, yo.
1550 1551 1552 1553 1554 1555 |
# File 'lib/puppet/type.rb', line 1550 def self.eachautorequire @autorequires ||= {} @autorequires.each { |type, block| yield(type, block) } end |
.eachmetaparam ⇒ Object
92 93 94 |
# File 'lib/puppet/type.rb', line 92 def self. @@metaparams.each { |p| yield p.name } end |
.ensurable(&block) ⇒ Object
Create the ‘ensure’ class. This is a separate method so other types can easily call it and create their own ‘ensure’ values.
98 99 100 101 102 103 104 105 106 |
# File 'lib/puppet/type.rb', line 98 def self.ensurable(&block) if block_given? self.newproperty(:ensure, :parent => Puppet::Property::Ensure, &block) else self.newproperty(:ensure, :parent => Puppet::Property::Ensure) do self.defaultvalues end end end |
.ensurable? ⇒ Boolean
Should we add the ‘ensure’ property to this class?
109 110 111 112 113 114 115 116 117 |
# File 'lib/puppet/type.rb', line 109 def self.ensurable? # If the class has all three of these methods defined, then it's # ensurable. ens = [:exists?, :create, :destroy].inject { |set, method| set &&= self.public_method_defined?(method) } ens end |
.handle_param_options(name, options) ⇒ Object
Deal with any options passed into parameters.
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/puppet/type.rb', line 120 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 return true end end end end |
.has_key?(name) ⇒ Boolean
does the type have an object with the given name?
853 854 855 856 |
# File 'lib/puppet/type.rb', line 853 def self.has_key?(name) raise "Global resource access is deprecated" @objects.has_key?(name) end |
.hash2resource(hash) ⇒ Object
Convert a simple hash into a Resource instance.
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 |
# File 'lib/puppet/type.rb', line 893 def self.hash2resource(hash) hash = hash.inject({}) { |result, ary| result[ary[0].to_sym] = ary[1]; result } 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.name, title) [:catalog].each do |attribute| if value = hash[attribute] hash.delete(attribute) resource.send(attribute.to_s + "=", value) end end hash.each do |param, value| resource[param] = value end resource end |
.initvars ⇒ Object
all of the variables that must be initialized for each subclass
1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 |
# File 'lib/puppet/type.rb', line 1634 def self.initvars # all of the instances of this class @objects = Hash.new @aliases = Hash.new @defaults = {} @parameters ||= [] @validproperties = {} @properties = [] @parameters = [] @paramhash = {} @attr_aliases = {} @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 } @doc ||= "" end |
.instances ⇒ Object
Retrieve all known instances. Either requires providers or must be overridden.
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 |
# File 'lib/puppet/type.rb', line 859 def self.instances raise Puppet::DevError, "#{self.name} has no providers and has not overridden 'instances'" 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 if other = provider_instances[instance.name] Puppet.warning "%s %s found in both %s and %s; skipping the %s version" % [self.name.to_s.capitalize, instance.name, other.class.name, instance.class.name, instance.class.name] next end provider_instances[instance.name] = instance new(:name => instance.name, :provider => instance, :audit => :all) end end.flatten.compact end |
.isomorphic? ⇒ Boolean
Is this type’s name isomorphic with the object? That is, if the name conflicts, does it necessarily mean that the objects conflict? Defaults to true.
563 564 565 566 567 568 569 |
# File 'lib/puppet/type.rb', line 563 def self.isomorphic? if defined?(@isomorphic) return @isomorphic else return true end end |
.key_attribute_parameters ⇒ Object
179 180 181 182 183 184 185 |
# File 'lib/puppet/type.rb', line 179 def self.key_attribute_parameters @key_attribute_parameters ||= ( params = @parameters.find_all { |param| param.isnamevar? or param.name == :name } ) end |
.key_attributes ⇒ Object
187 188 189 |
# File 'lib/puppet/type.rb', line 187 def self.key_attributes key_attribute_parameters.collect { |p| p.name } end |
.metaparam?(param) ⇒ Boolean
Is the parameter in question a meta-parameter?
133 134 135 |
# File 'lib/puppet/type.rb', line 133 def self.(param) @@metaparamhash.include?(symbolize(param)) end |
.metaparamclass(name) ⇒ Object
Find the metaparameter class associated with a given metaparameter name.
138 139 140 |
# File 'lib/puppet/type.rb', line 138 def self.(name) @@metaparamhash[symbolize(name)] end |
.metaparamdoc(metaparam) ⇒ Object
146 147 148 |
# File 'lib/puppet/type.rb', line 146 def self.() @@metaparamhash[].doc end |
.metaparams ⇒ Object
142 143 144 |
# File 'lib/puppet/type.rb', line 142 def self. @@metaparams.collect { |param| param.name } end |
.newmetaparam(name, options = {}, &block) ⇒ Object
Create a new metaparam. Requires a block and a name, stores it in the
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/puppet/type.rb', line 152 def self.(name, = {}, &block) @@metaparams ||= [] @@metaparamhash ||= {} name = symbolize(name) 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 = {}, &block) ⇒ Object
Create a new parameter. Requires a block and a name, stores it in the
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/puppet/type.rb', line 208 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 = {}, &block) ⇒ Object
Create a new property. The first parameter must be the name of the property; this is how users will refer to the property when creating new instances. The second parameter is a hash of options; the options are:
-
:parent: The parent class for the property. Defaults to Puppet::Property. -
:retrieve: The method to call on the provider or @parent object (if the provider is not set) to retrieve the current value.
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/puppet/type.rb', line 243 def self.newproperty(name, = {}, &block) name = symbolize(name) # 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 #{.inspect}" end raise Puppet::DevError, "Class #{self.name} already has a property named #{name}" if @validproperties.include?(name) if parent = [: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 |
.newstate(name, options = {}, &block) ⇒ Object
232 233 234 235 |
# File 'lib/puppet/type.rb', line 232 def self.newstate(name, = {}, &block) Puppet.warning "newstate() has been deprecrated; use newproperty(#{name})" newproperty(name, , &block) end |
.paramclass(name) ⇒ Object
Find the parameter class associated with a given parameter name.
297 298 299 |
# File 'lib/puppet/type.rb', line 297 def self.paramclass(name) @paramhash[name] end |
.paramdoc(param) ⇒ Object
286 287 288 |
# File 'lib/puppet/type.rb', line 286 def self.paramdoc(param) @paramhash[param].doc end |
.parameters ⇒ Object
Return the parameter names
291 292 293 294 |
# File 'lib/puppet/type.rb', line 291 def self.parameters return [] unless defined?(@parameters) @parameters.collect { |klass| klass.name } end |
.propertybyname(name) ⇒ Object
Return the property class associated with a name
302 303 304 |
# File 'lib/puppet/type.rb', line 302 def self.propertybyname(name) @validproperties[name] end |
.provide(name, options = {}, &block) ⇒ Object
Create a new provider of a type. This method must be called directly on the type that it’s implementing.
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 |
# File 'lib/puppet/type.rb', line 1416 def self.provide(name, = {}, &block) name = Puppet::Util.symbolize(name) if unprovide(name) Puppet.debug "Reloading #{name} #{self.name} provider" end parent = if pname = [:parent] .delete(:parent) if pname.is_a? Class pname else if provider = self.provider(pname) provider else raise Puppet::DevError, "Could not find parent provider #{pname} of #{name}" end end else Puppet::Provider end [:resource_type] ||= self self.providify provider = genclass( name, :parent => parent, :hash => provider_hash, :prefix => "Provider", :block => block, :include => feature_module, :extend => feature_module, :attributes => ) provider end |
.provider(name) ⇒ Object
Retrieve a provider by name.
1395 1396 1397 1398 1399 1400 1401 |
# File 'lib/puppet/type.rb', line 1395 def self.provider(name) name = Puppet::Util.symbolize(name) # If we don't have it yet, try loading it. @providerloader.load(name) unless provider_hash.has_key?(name) provider_hash[name] end |
.provider_hash ⇒ Object
1390 1391 1392 |
# File 'lib/puppet/type.rb', line 1390 def self.provider_hash Puppet::Type.provider_hash_by_type(self.name) end |
.provider_hash_by_type(type) ⇒ Object
1385 1386 1387 1388 |
# File 'lib/puppet/type.rb', line 1385 def self.provider_hash_by_type(type) @provider_hashes ||= {} @provider_hashes[type] ||= {} end |
.providers ⇒ Object
Just list all of the providers.
1404 1405 1406 |
# File 'lib/puppet/type.rb', line 1404 def self.providers provider_hash.keys end |
.providers_by_source ⇒ Object
Return a list of one suitable provider per source, with the default provider first.
881 882 883 884 885 886 887 888 889 890 |
# File 'lib/puppet/type.rb', line 881 def self.providers_by_source # Put the default provider first, then the rest of the suitable providers. sources = [] [defaultprovider, suitableprovider].flatten.uniq.collect do |provider| next if sources.include?(provider.source) sources << provider.source provider end.compact end |
.providify ⇒ Object
Make sure we have a :provider parameter defined. Only gets called if there are providers.
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 |
# File 'lib/puppet/type.rb', line 1459 def self.providify return if @paramhash.has_key? :provider newparam(:provider) do desc "The specific backend for #{self.name.to_s} to use. You will seldom need to specify this -- Puppet will usually discover the appropriate provider for your platform." # This is so we can refer back to the type to get a list of # providers for documentation. class << self attr_accessor :parenttype end # We need to add documentation for each provider. def self.doc @doc + " Available providers are:\n\n" + parenttype.providers.sort { |a,b| a.to_s <=> b.to_s }.collect { |i| "* **#{i}**: #{parenttype().provider(i).doc}" }.join("\n") end defaultto { @resource.class.defaultprovider.name } 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 provider = @resource.class.provider(provider_class) raise ArgumentError, "Invalid #{@resource.class.name} provider '#{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.parenttype = self end |
.relationship_params ⇒ Object
1200 1201 1202 |
# File 'lib/puppet/type.rb', line 1200 def self.relationship_params RelationshipMetaparam.subclasses end |
.set_attr_alias(hash) ⇒ Object
Create an alias to an existing attribute. This will cause the aliased attribute to be valid when setting and retrieving values on the instance.
55 56 57 58 59 |
# File 'lib/puppet/type.rb', line 55 def self.set_attr_alias(hash) hash.each do |new, old| @attr_aliases[symbolize(new)] = symbolize(old) end end |
.states ⇒ Object
36 37 38 39 |
# File 'lib/puppet/type.rb', line 36 def self.states warnonce "The states method is deprecated; use properties" properties end |
.suitableprovider ⇒ Object
Return an array of all of the suitable providers.
1518 1519 1520 1521 1522 1523 1524 1525 |
# File 'lib/puppet/type.rb', line 1518 def self.suitableprovider providerloader.loadall 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 ⇒ Object
191 192 193 194 195 196 197 198 199 200 |
# File 'lib/puppet/type.rb', line 191 def self.title_patterns case key_attributes.length when 0; [] when 1; identity = lambda {|x| x} [ [ /(.*)/m, [ [key_attributes.first, identity ] ] ] ] else raise Puppet::DevError,"you must specify title patterns when there are two or more key attributes" end end |
.to_s ⇒ Object
1663 1664 1665 1666 1667 1668 1669 |
# File 'lib/puppet/type.rb', line 1663 def self.to_s if defined?(@name) "Puppet::Type::#{@name.to_s.capitalize}" else super end end |
.unprovide(name) ⇒ Object
1509 1510 1511 1512 1513 1514 1515 |
# File 'lib/puppet/type.rb', line 1509 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
This is a forward-compatibility method - it’s the validity interface we’ll use in Puppet::Resource.
338 339 340 |
# File 'lib/puppet/type.rb', line 338 def self.valid_parameter?(name) validattr?(name) end |
.validate(&block) ⇒ Object
Create a block to validate that our object is set up entirely. This will be run before the object is operated on.
1673 1674 1675 1676 |
# File 'lib/puppet/type.rb', line 1673 def self.validate(&block) define_method(:validate, &block) #@validate = block end |
.validattr?(name) ⇒ Boolean
306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/puppet/type.rb', line 306 def self.validattr?(name) name = symbolize(name) return true if name == :name @validattrs ||= {} unless @validattrs.include?(name) @validattrs[name] = !!(self.validproperty?(name) or self.validparameter?(name) or self.(name)) end @validattrs[name] end |
.validparameter?(name) ⇒ Boolean
does the name reflect a valid parameter?
332 333 334 335 |
# File 'lib/puppet/type.rb', line 332 def self.validparameter?(name) raise Puppet::DevError, "Class #{self} has not defined parameters" unless defined?(@parameters) !!(@paramhash.include?(name) or @@metaparamhash.include?(name)) end |
.validproperties ⇒ Object
Return the list of validproperties
325 326 327 328 329 |
# File 'lib/puppet/type.rb', line 325 def self.validproperties return {} unless defined?(@parameters) @validproperties.keys end |
.validproperty?(name) ⇒ Boolean
does the name reflect a valid property?
319 320 321 322 |
# File 'lib/puppet/type.rb', line 319 def self.validproperty?(name) name = symbolize(name) @validproperties.include?(name) && @validproperties[name] end |
Instance Method Details
#[](name) ⇒ Object
abstract accessing parameters and properties, and normalize access to always be symbols, not strings This returns a value, not an object. It returns the ‘is’ value, but you can also specifically return ‘is’ and ‘should’ values using ‘object.is(:property)’ or ‘object.should(:property)’.
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/puppet/type.rb', line 380 def [](name) name = attr_alias(name) fail("Invalid parameter #{name}(#{name.inspect})") unless self.class.validattr?(name) if name == :name && nv = name_var name = nv end if obj = @parameters[name] # Note that if this is a property, then the value is the "should" value, # not the current value. obj.value else return nil end end |
#[]=(name, value) ⇒ Object
Abstract setting parameters and properties, and normalize access to always be symbols, not strings. This sets the ‘should’ value on properties, and otherwise just sets the appropriate parameter.
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/puppet/type.rb', line 401 def []=(name,value) name = attr_alias(name) fail("Invalid parameter #{name}") unless self.class.validattr?(name) if name == :name && nv = name_var name = nv end raise Puppet::Error.new("Got nil value for #{name}") if value.nil? property = self.newattr(name) if property begin # make sure the parameter doesn't have any errors property.value = value rescue => detail error = Puppet::Error.new("Parameter #{name} failed: #{detail}") error.set_backtrace(detail.backtrace) raise error end end nil end |
#add_property_parameter(prop_name) ⇒ Object
Create a new property if it is valid but doesn’t exist Returns: true if a new parameter was added, false otherwise
359 360 361 362 363 364 365 |
# File 'lib/puppet/type.rb', line 359 def add_property_parameter(prop_name) if self.class.validproperty?(prop_name) && !@parameters[prop_name] self.newattr(prop_name) return true end false end |
#attr_alias(name) ⇒ Object
Return either the attribute alias or the attribute.
343 344 345 346 347 348 349 350 |
# File 'lib/puppet/type.rb', line 343 def attr_alias(name) name = symbolize(name) if synonym = self.class.attr_alias(name) return synonym else return name end end |
#autorequire(rel_catalog = nil) ⇒ Object
Figure out of there are any objects we can automatically add as dependencies.
1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 |
# File 'lib/puppet/type.rb', line 1559 def autorequire(rel_catalog = nil) rel_catalog ||= catalog raise(Puppet::DevError, "You cannot add relationships without a catalog") unless rel_catalog reqs = [] self.class.eachautorequire { |type, block| # Ignore any types we can't find, although that would be a bit odd. next unless typeobj = Puppet::Type.type(type) # Retrieve the list of names from the block. next unless list = self.instance_eval(&block) list = [list] unless list.is_a?(Array) # Collect the current prereqs list.each { |dep| # Support them passing objects directly, to save some effort. unless dep.is_a? Puppet::Type # Skip autorequires that we aren't managing unless dep = rel_catalog.resource(type, dep) next end end reqs << Puppet::Relationship.new(dep, self) } } reqs end |
#builddepends ⇒ Object
Build the dependencies associated with an individual object.
1590 1591 1592 1593 1594 1595 1596 1597 |
# File 'lib/puppet/type.rb', line 1590 def builddepends # Handle the requires self.class.relationship_params.collect do |klass| if param = @parameters[klass.name] param.to_edges end end.flatten.reject { |r| r.nil? } end |
#currentpropvalues ⇒ Object
Get a hash of the current properties. Returns a hash with the actual property instance as the key and the current value as the, um, value.
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 |
# File 'lib/puppet/type.rb', line 711 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 return properties.inject({}) do | prophash, property| if property.name == :ensure ensure_state = property.retrieve prophash[property] = ensure_state else if ensure_state == :absent prophash[property] = :absent else prophash[property] = property.retrieve end end prophash end end |
#delete(attr) ⇒ Object
remove a property from the object; useful in testing or in cleanup when an error has been encountered
429 430 431 432 433 434 435 436 |
# File 'lib/puppet/type.rb', line 429 def delete(attr) attr = symbolize(attr) if @parameters.has_key?(attr) @parameters.delete(attr) else raise Puppet::DevError.new("Undefined attribute '#{attr}' in #{self}") end end |
#deleting? ⇒ Boolean
Are we deleting this resource?
353 354 355 |
# File 'lib/puppet/type.rb', line 353 def deleting? obj = @parameters[:ensure] and obj.should == :absent end |
#depthfirst? ⇒ Boolean
607 608 609 |
# File 'lib/puppet/type.rb', line 607 def depthfirst? self.class.depthfirst? end |
#eachproperty ⇒ Object
iterate across the existing properties
439 440 441 442 443 444 |
# File 'lib/puppet/type.rb', line 439 def eachproperty # properties is a private method properties.each { |property| yield property } end |
#event(options = {}) ⇒ Object
Create a transaction event. Called by Transaction or by a property.
448 449 450 |
# File 'lib/puppet/type.rb', line 448 def event( = {}) Puppet::Transaction::Event.new({:resource => self, :file => file, :line => line, :tags => }.merge()) end |
#expirer ⇒ Object
Let the catalog determine whether a given cached value is still valid or has expired.
454 455 456 |
# File 'lib/puppet/type.rb', line 454 def expirer catalog end |
#exported? ⇒ Boolean
1892 |
# File 'lib/puppet/type.rb', line 1892 def exported?; !!@exported; end |
#finish ⇒ Object
Set up all of our autorequires.
1782 1783 1784 1785 1786 1787 1788 1789 1790 |
# File 'lib/puppet/type.rb', line 1782 def finish # 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| if param = @parameters[klass.name] param.validate_relationship end end.flatten.reject { |r| r.nil? } end |
#flush ⇒ Object
Flush the provider, if it supports it. This is called by the transaction.
635 636 637 |
# File 'lib/puppet/type.rb', line 635 def flush self.provider.flush if self.provider and self.provider.respond_to?(:flush) end |
#insync?(is) ⇒ Boolean
if all contained objects are in sync, then we’re in sync FIXME I don’t think this is used on the type instances any more, it’s really only used for testing
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 |
# File 'lib/puppet/type.rb', line 642 def insync?(is) insync = true if property = @parameters[:ensure] unless is.include? property raise Puppet::DevError, "The is value is not in the is array for '#{property.name}'" end ensureis = is[property] if property.safe_insync?(ensureis) and property.should == :absent return true end end properties.each { |property| unless is.include? property raise Puppet::DevError, "The is value is not in the is array for '#{property.name}'" end propis = is[property] unless property.safe_insync?(propis) property.debug("Not in sync: #{propis.inspect} vs #{property.should.inspect}") insync = false #else # property.debug("In sync") end } #self.debug("#{self} sync status is #{insync}") insync end |
#isomorphic? ⇒ Boolean
571 572 573 |
# File 'lib/puppet/type.rb', line 571 def isomorphic? self.class.isomorphic? end |
#log(msg) ⇒ Object
create a log at specified level
1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 |
# File 'lib/puppet/type.rb', line 1688 def log(msg) Puppet::Util::Log.create( :level => @parameters[:loglevel].value, :message => msg, :source => self ) end |
#managed? ⇒ Boolean
is the instance 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
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
# File 'lib/puppet/type.rb', line 579 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 if @managed return @managed else @managed = false properties.each { |property| s = property.should if s and ! property.class.unmanaged @managed = true break end } return @managed end end |
#name ⇒ Object
For now, leave the ‘name’ method functioning like it used to. Once ‘title’ works everywhere, I’ll switch it.
1794 1795 1796 |
# File 'lib/puppet/type.rb', line 1794 def name self[:name] end |
#name_var ⇒ Object
The name_var is the key_attribute in the case that there is only one.
370 371 372 373 |
# File 'lib/puppet/type.rb', line 370 def name_var key_attributes = self.class.key_attributes (key_attributes.length == 1) && key_attributes.first end |
#newattr(name) ⇒ Object
Create the actual attribute instance. Requires either the attribute name or class as the first argument, then an optional hash of attributes to set during initialization.
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
# File 'lib/puppet/type.rb', line 467 def newattr(name) if name.is_a?(Class) klass = name name = klass.name end unless klass = self.class.attrclass(name) 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) } info "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
Are we running in noop mode?
733 734 735 736 737 738 739 740 741 742 743 |
# File 'lib/puppet/type.rb', line 733 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
return the value of a parameter
489 490 491 |
# File 'lib/puppet/type.rb', line 489 def parameter(name) @parameters[name.to_sym] end |
#parameters ⇒ Object
493 494 495 |
# File 'lib/puppet/type.rb', line 493 def parameters @parameters.dup end |
#parent ⇒ Object
Look up our parent in the catalog, if we have one.
1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 |
# File 'lib/puppet/type.rb', line 1799 def parent return nil unless catalog unless defined?(@parent) if parents = catalog.adjacent(self, :direction => :in) # We should never have more than one parent, so let's just ignore # it if we happen to. @parent = parents.shift else @parent = nil end end @parent end |
#pathbuilder ⇒ Object
Create the path for logging and such.
918 919 920 921 922 923 924 |
# File 'lib/puppet/type.rb', line 918 def pathbuilder if p = parent [p.pathbuilder, self.ref].flatten else [self.ref] end end |
#properties ⇒ Object
Return all of the property objects, in the order specified in the class.
556 557 558 |
# File 'lib/puppet/type.rb', line 556 def properties self.class.properties.collect { |prop| @parameters[prop.name] }.compact end |
#property(name) ⇒ Object
Return an actual property instance by name; to return the value, use ‘resource’ LAK:NOTE(20081028) Since the ‘parameter’ method is now a superset of this method, this one should probably go away at some point.
506 507 508 |
# File 'lib/puppet/type.rb', line 506 def property(name) (obj = @parameters[symbolize(name)] and obj.is_a?(Puppet::Property)) ? obj : nil end |
#propertydefined?(name) ⇒ Boolean
Is the named property defined?
498 499 500 501 |
# File 'lib/puppet/type.rb', line 498 def propertydefined?(name) name = name.intern unless name.is_a? Symbol @parameters.include?(name) end |
#purging ⇒ Object
Mark that we’re purging.
1824 1825 1826 |
# File 'lib/puppet/type.rb', line 1824 def purging @purging = true end |
#purging? ⇒ Boolean
Is this resource being purged? Used by transactions to forbid deletion when there are dependencies.
1830 1831 1832 1833 1834 1835 1836 |
# File 'lib/puppet/type.rb', line 1830 def purging? if defined?(@purging) @purging else false end end |
#ref ⇒ Object
Return the “type” style reference.
1815 1816 1817 |
# File 'lib/puppet/type.rb', line 1815 def ref "#{self.class.name.to_s.capitalize}[#{self.title}]" end |
#remove(rmdeps = true) ⇒ Object
Remove an object. The argument determines whether the object’s subscriptions get eliminated, too.
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'lib/puppet/type.rb', line 613 def remove(rmdeps = true) # 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 self.provider @provider.clear @provider = nil end end |
#retrieve ⇒ Object
retrieve the current value of all contained properties
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
# File 'lib/puppet/type.rb', line 676 def retrieve fail "Provider #{provider.class.name} is not functional on this host" if self.provider.is_a?(Puppet::Provider) and ! provider.class.suitable? result = Puppet::Resource.new(type, title) # Provide the name, so we know we'll always refer to a real thing result[:name] = self[:name] unless self[:name] == title if ensure_prop = property(:ensure) or (self.class.validattr?(:ensure) and ensure_prop = newattr(:ensure)) 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 ⇒ Object
702 703 704 705 706 |
# File 'lib/puppet/type.rb', line 702 def retrieve_resource resource = retrieve resource = Resource.new(type, title, :parameters => resource) if resource.is_a? Hash resource end |
#self_refresh? ⇒ Boolean
1819 1820 1821 |
# File 'lib/puppet/type.rb', line 1819 def self_refresh? self.class.self_refresh end |
#set_default(attr) ⇒ Object
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.
513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/puppet/type.rb', line 513 def set_default(attr) return unless klass = self.class.attrclass(attr) return unless klass.method_defined?(:default) return if @parameters.include?(klass.name) return unless parameter = newattr(klass.name) if value = parameter.default and ! value.nil? parameter.value = value else @parameters.delete(parameter.name) end end |
#should(name) ⇒ Object
retrieve the ‘should’ value for a specified property
459 460 461 462 |
# File 'lib/puppet/type.rb', line 459 def should(name) name = attr_alias(name) (prop = @parameters[name] and prop.is_a?(Puppet::Property)) ? prop.should : nil end |
#tags=(list) ⇒ Object
Define the initial list of tags.
1600 1601 1602 1603 |
# File 'lib/puppet/type.rb', line 1600 def (list) tag(self.class.name) tag(*list) end |
#to_hash ⇒ Object
Convert our object to a hash. This just includes properties.
528 529 530 531 532 533 534 535 536 |
# File 'lib/puppet/type.rb', line 528 def to_hash rethash = {} @parameters.each do |name, obj| rethash[name] = obj.value end rethash end |
#to_resource ⇒ Object
1885 1886 1887 1888 1889 |
# File 'lib/puppet/type.rb', line 1885 def to_resource # this 'type instance' versus 'resource' distinction seems artificial # I'd like to see it collapsed someday ~JW self.to_trans.to_resource end |
#to_s ⇒ Object
convert to a string
1855 1856 1857 |
# File 'lib/puppet/type.rb', line 1855 def to_s self.ref end |
#to_trans(ret = true) ⇒ Object
Convert to a transportable object
1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 |
# File 'lib/puppet/type.rb', line 1860 def to_trans(ret = true) trans = TransObject.new(self.title, self.class.name) values = retrieve_resource values.each do |name, value| name = name.name if name.respond_to? :name trans[name] = value end @parameters.each do |name, param| # Avoid adding each instance name twice next if param.class.isnamevar? and param.value == self.title # We've already got property values next if param.is_a?(Puppet::Property) trans[name] = param.value end trans. = self. # FIXME I'm currently ignoring 'parent' and 'path' trans end |
#type ⇒ Object
538 539 540 |
# File 'lib/puppet/type.rb', line 538 def type self.class.name end |
#uniqueness_key ⇒ Object
202 203 204 |
# File 'lib/puppet/type.rb', line 202 def uniqueness_key self.class.key_attributes.sort_by { |attribute_name| attribute_name.to_s }.map{ |attribute_name| self[attribute_name] } end |
#value(name) ⇒ Object
Return a specific value for an attribute.
543 544 545 546 547 |
# File 'lib/puppet/type.rb', line 543 def value(name) name = attr_alias(name) (obj = @parameters[name] and obj.respond_to?(:value)) ? obj.value : nil end |
#version ⇒ Object
549 550 551 552 |
# File 'lib/puppet/type.rb', line 549 def version return 0 unless catalog catalog.version end |
#virtual? ⇒ Boolean
1891 |
# File 'lib/puppet/type.rb', line 1891 def virtual?; !!@virtual; end |