Class: Puppet::Provider

Inherits:
Object show all
Extended by:
Confiner, Util, Util::Docs, Util::Logging, Util::Warnings
Includes:
Comparable, Util, Util::Errors, Util::Warnings
Defined in:
lib/puppet/provider.rb

Overview

Note:

An instance of a Provider is associated with one resource.

Note:

Class level methods are only called once to configure the provider (when the type is created), and not for each resource the provider is operating on. The instance methods are however called for each resource.

A Provider is an implementation of the actions that manage resources (of some type) on a system. This class is the base class for all implementation of a Puppet Provider.

Concepts:

  • Confinement - confinement restricts providers to only be applicable under certain conditions. It is possible to confine a provider several different ways:
    • the included Confiner#confine method which provides filtering on fact, feature, existence of files, or a free form predicate.
    • the Provider.commands method that filters on the availability of given system commands.
  • Property hash - the important instance variable @property_hash contains all current state values for properties (it is lazily built). It is important that these values are managed appropriately in the methods Provider.instances, Provider.prefetch, and in methods that alters the current state (those that change the lifecycle (creates, destroys), or alters some value reflected backed by a property).
  • Flush - is a hook that is called once per resource when everything has been applied. The intent is that an implementation may defer modification of the current state typically done in property setters and instead record information that allows flush to perform the changes more efficiently.
  • Execution Methods - The execution methods provides access to execution of arbitrary commands. As a convenience execution methods are available on both the instance and the class of a provider since a lot of provider logic switch between these contexts fairly freely.
  • System Entity/Resource - this documentation uses the term “system entity” for system resources to make it clear if talking about a resource on the system being managed (e.g. a file in the file system) or about a description of such a resource (e.g. a Puppet Resource).
  • Resource Type - this is an instance of Type that describes a classification of instances of Resource (e.g. the File resource type describes all instances of file resources). (The term is used to contrast with “type” in general, and specifically to contrast with the implementation class of Resource or a specific Type).

Defined Under Namespace

Classes: CommandDefiner

Constant Summary

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Methods included from Util

exit_on_fail, exit_on_fail, which, which

Methods included from Confiner

confine, confine_collection, suitable?

Class Attribute Details

+ (???) model (readonly) deprecatedprivate

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.

Deprecated.

This attribute is available for backwards compatibility reasons.

TODO:

Original = “LAK 2007-05-09: Keep the model stuff around for backward compatibility” Is this really needed? The comment about backwards compatibility was made in 2007.

A model kept for backwards compatibility.

Returns:

  • (???)

    A model kept for backwards compatibility.



74
75
76
# File 'lib/puppet/provider.rb', line 74

def model
  @model
end

Class Method Details

+ create_class_and_instance_method(name, &block)  private

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.

This method returns an undefined value.

This method is used to generate a method for a command.



436
437
438
439
440
441
442
443
444
445
446
# File 'lib/puppet/provider.rb', line 436

def self.create_class_and_instance_method(name, &block)
  unless singleton_class.method_defined?(name)
    meta_def(name, &block)
  end

  unless method_defined?(name)
    define_method(name) do |*args|
      self.class.send(name, *args)
    end
  end
end

+ (Object) make_command_methods(name)  deprecatedprivate

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.

Deprecated.

Use commands, optional_commands, or has_command instead. This was not meant to be part of a public API

Creates the methods for a given command.



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/puppet/provider.rb', line 381

def self.make_command_methods(name)
  Puppet.deprecation_warning "Provider.make_command_methods is deprecated; use Provider.commands or Provider.optional_commands instead for creating command methods"

  # Now define a method for that command
  unless singleton_class.method_defined?(name)
    meta_def(name) do |*args|
      # This might throw an ExecutionFailure, but the system above
      # will catch it, if so.
      command = Puppet::Provider::Command.new(name, command(name), Puppet::Util, Puppet::Util::Execution)
      return command.execute(*args)
    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