Class: Puppet::Provider
- Extended by:
- Confiner, Util, Util::Docs, Util::Logging, Util::Warnings
- Includes:
- Comparable, Util, Util::Errors, Util::Warnings
- Defined in:
- lib/vendor/puppet/provider.rb
Overview
The container class for implementations.
Direct Known Subclasses
AixObject, Exec, Ldap, NameService, NetworkDevice, Package, ParsedFile
Defined Under Namespace
Modules: Confiner, Mount Classes: AixObject, Cisco, Confine, ConfineCollection, Exec, Ldap, Naginator, NameService, NetworkDevice, Package, ParsedFile
Constant Summary
Constants included from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows
Constants included from Util::Docs
Class Attribute Summary collapse
-
.doc ⇒ Object
writeonly
Sets the attribute doc.
-
.model ⇒ Object
readonly
LAK 2007-05-09: Keep the model stuff around for backward compatibility.
-
.name ⇒ Object
Returns the value of attribute name.
-
.resource_type ⇒ Object
Returns the value of attribute resource_type.
-
.source ⇒ Object
Retrieve the data source.
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
LAK 2007-05-09: Keep the model stuff around for backward compatibility.
-
#resource ⇒ Object
Returns the value of attribute resource.
Attributes included from Util::Docs
Class Method Summary collapse
- .command(name) ⇒ Object
-
.commands(hash) ⇒ Object
Define commands that are not optional.
-
.declared_feature?(name) ⇒ Boolean
Is the provided feature a declared feature?.
-
.default? ⇒ Boolean
Does this implementation match all of the default requirements? If defaults are empty, we return false.
-
.defaultfor(hash) ⇒ Object
Store how to determine defaults.
- .initvars ⇒ Object
-
.instances ⇒ Object
The method for returning a list of provider instances.
-
.make_command_methods(name) ⇒ Object
Create the methods for a given command.
-
.mk_resource_methods ⇒ Object
Create getter/setter methods for each property our resource type supports.
-
.mkmodelmethods ⇒ Object
Create getter/setter methods for each property our resource type supports.
-
.optional_commands(hash) ⇒ Object
Define one or more binaries we’ll be using.
- .specificity ⇒ Object
-
.supports_parameter?(param) ⇒ Boolean
Does this provider support the specified parameter?.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#clear ⇒ Object
Remove the reference to the resource, so GC can clean up.
-
#command(name) ⇒ Object
Retrieve a named command.
-
#get(param) ⇒ Object
Get a parameter value.
-
#initialize(resource = nil) ⇒ Provider
constructor
A new instance of Provider.
- #name ⇒ Object
-
#set(params) ⇒ Object
Set passed params as the current values.
- #to_s ⇒ Object
Methods included from Util::Logging
clear_deprecation_warnings, deprecation_warning, send_log
Methods included from Util
absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, execfail, execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, threadlock, uri_to_path, wait_for_output, which, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::Docs
desc, dochook, doctable, markdown_definitionlist, markdown_header, nodoc?, pad, scrub
Methods included from Util::Warnings
clear_warnings, notice_once, warnonce
Methods included from Confiner
confine, confine_collection, suitable?
Methods included from Util::Errors
#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail
Constructor Details
#initialize(resource = nil) ⇒ Provider
Returns a new instance of Provider.
245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/vendor/puppet/provider.rb', line 245 def initialize(resource = nil) if resource.is_a?(Hash) # We don't use a duplicate here, because some providers (ParsedFile, at least) # use the hash here for later events. @property_hash = resource elsif resource @resource = resource # LAK 2007-05-09: Keep the model stuff around for backward compatibility @model = resource @property_hash = {} else @property_hash = {} end end |
Class Attribute Details
.doc=(value) ⇒ Object (writeonly)
Sets the attribute doc
28 29 30 |
# File 'lib/vendor/puppet/provider.rb', line 28 def doc=(value) @doc = value end |
.model ⇒ Object (readonly)
LAK 2007-05-09: Keep the model stuff around for backward compatibility
26 27 28 |
# File 'lib/vendor/puppet/provider.rb', line 26 def model @model end |
.name ⇒ Object
Returns the value of attribute name.
18 19 20 |
# File 'lib/vendor/puppet/provider.rb', line 18 def name @name end |
.resource_type ⇒ Object
Returns the value of attribute resource_type.
27 28 29 |
# File 'lib/vendor/puppet/provider.rb', line 27 def resource_type @resource_type end |
.source ⇒ Object
Retrieve the data source. Defaults to the provider name.
176 177 178 |
# File 'lib/vendor/puppet/provider.rb', line 176 def self.source @source ||= self.name end |
Instance Attribute Details
#model ⇒ Object (readonly)
LAK 2007-05-09: Keep the model stuff around for backward compatibility
32 33 34 |
# File 'lib/vendor/puppet/provider.rb', line 32 def model @model end |
#resource ⇒ Object
Returns the value of attribute resource.
33 34 35 |
# File 'lib/vendor/puppet/provider.rb', line 33 def resource @resource end |
Class Method Details
.command(name) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vendor/puppet/provider.rb', line 35 def self.command(name) name = name.intern if defined?(@commands) and command = @commands[name] # nothing elsif superclass.respond_to? :command and command = superclass.command(name) # nothing else raise Puppet::DevError, "No command #{name} defined for provider #{self.name}" end which(command) end |
.commands(hash) ⇒ Object
Define commands that are not optional.
50 51 52 53 54 |
# File 'lib/vendor/puppet/provider.rb', line 50 def self.commands(hash) optional_commands(hash) do |name, path| confine :exists => path, :for_binary => true end end |
.declared_feature?(name) ⇒ Boolean
Is the provided feature a declared feature?
57 58 59 |
# File 'lib/vendor/puppet/provider.rb', line 57 def self.declared_feature?(name) defined?(@declared_features) and @declared_features.include?(name) end |
.default? ⇒ Boolean
Does this implementation match all of the default requirements? If defaults are empty, we return false.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/vendor/puppet/provider.rb', line 63 def self.default? return false if @defaults.empty? if @defaults.find do |fact, values| values = [values] unless values.is_a? Array if fval = Facter.value(fact).to_s and fval != "" fval = fval.to_s.downcase.intern else return false end # If any of the values match, we're a default. if values.find do |value| fval == value.to_s.downcase.intern end false else true end end return false else return true end end |
.defaultfor(hash) ⇒ Object
Store how to determine defaults.
87 88 89 90 91 |
# File 'lib/vendor/puppet/provider.rb', line 87 def self.defaultfor(hash) hash.each do |d,v| @defaults[d] = v end end |
.initvars ⇒ Object
97 98 99 100 |
# File 'lib/vendor/puppet/provider.rb', line 97 def self.initvars @defaults = {} @commands = {} end |
.instances ⇒ Object
The method for returning a list of provider instances. Note that it returns providers, preferably with values already filled in, not resources.
104 105 106 |
# File 'lib/vendor/puppet/provider.rb', line 104 def self.instances raise Puppet::DevError, "Provider #{self.name} has not defined the 'instances' class method" end |
.make_command_methods(name) ⇒ Object
Create the methods for a given command.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vendor/puppet/provider.rb', line 109 def self.make_command_methods(name) # Now define a method for that command unless singleton_class.method_defined?(name) (name) do |*args| raise Puppet::Error, "Command #{name} is missing" unless command(name) if args.empty? cmd = [command(name)] else cmd = [command(name)] + args end # This might throw an ExecutionFailure, but the system above # will catch it, if so. return execute(cmd) end # And then define an instance method that just calls the class method. # We need both, so both instances and classes can easily run the commands. unless method_defined?(name) define_method(name) do |*args| self.class.send(name, *args) end end end end |
.mk_resource_methods ⇒ Object
Create getter/setter methods for each property our resource type supports. They all get stored in @property_hash. This method is useful for those providers that use prefetch and flush.
145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/vendor/puppet/provider.rb', line 145 def self.mk_resource_methods [resource_type.validproperties, resource_type.parameters].flatten.each do |attr| attr = attr.intern next if attr == :name define_method(attr) do @property_hash[attr] || :absent end define_method(attr.to_s + "=") do |val| @property_hash[attr] = val end end end |
.mkmodelmethods ⇒ Object
Create getter/setter methods for each property our resource type supports. They all get stored in @property_hash. This method is useful for those providers that use prefetch and flush.
137 138 139 140 |
# File 'lib/vendor/puppet/provider.rb', line 137 def self.mkmodelmethods warnonce "Provider.mkmodelmethods is deprecated; use Provider.mk_resource_methods" mk_resource_methods end |
.optional_commands(hash) ⇒ Object
Define one or more binaries we’ll be using. If a block is passed, yield the name and path to the block (really only used by ‘commands’).
163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/vendor/puppet/provider.rb', line 163 def self.optional_commands(hash) hash.each do |name, path| name = name.intern @commands[name] = path yield(name, path) if block_given? # Now define the class and instance methods. make_command_methods(name) end end |
.specificity ⇒ Object
93 94 95 |
# File 'lib/vendor/puppet/provider.rb', line 93 def self.specificity (@defaults.length * 100) + ancestors.select { |a| a.is_a? Class }.length end |
.supports_parameter?(param) ⇒ Boolean
Does this provider support the specified parameter?
181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/vendor/puppet/provider.rb', line 181 def self.supports_parameter?(param) if param.is_a?(Class) klass = param else unless klass = resource_type.attrclass(param) raise Puppet::DevError, "'#{param}' is not a valid parameter for #{resource_type.name}" end end return true unless features = klass.required_features !!satisfies?(*features) end |
Instance Method Details
#<=>(other) ⇒ Object
283 284 285 286 287 288 |
# File 'lib/vendor/puppet/provider.rb', line 283 def <=>(other) # We can only have ordering against other providers. return nil unless other.is_a? Puppet::Provider # Otherwise, order by the providers class name. return self.class.name <=> other.class.name end |
#clear ⇒ Object
Remove the reference to the resource, so GC can clean up.
230 231 232 233 |
# File 'lib/vendor/puppet/provider.rb', line 230 def clear @resource = nil @model = nil end |
#command(name) ⇒ Object
Retrieve a named command.
236 237 238 |
# File 'lib/vendor/puppet/provider.rb', line 236 def command(name) self.class.command(name) end |
#get(param) ⇒ Object
Get a parameter value.
241 242 243 |
# File 'lib/vendor/puppet/provider.rb', line 241 def get(param) @property_hash[param.intern] || :absent end |
#name ⇒ Object
260 261 262 263 264 265 266 267 268 |
# File 'lib/vendor/puppet/provider.rb', line 260 def name if n = @property_hash[:name] return n elsif self.resource resource.name else raise Puppet::DevError, "No resource and no name in property hash in #{self.class.name} instance" end end |
#set(params) ⇒ Object
Set passed params as the current values.
271 272 273 274 275 |
# File 'lib/vendor/puppet/provider.rb', line 271 def set(params) params.each do |param, value| @property_hash[param.intern] = value end end |
#to_s ⇒ Object
277 278 279 |
# File 'lib/vendor/puppet/provider.rb', line 277 def to_s "#{@resource}(provider=#{self.class.name})" end |