2

I am building a custom package provider, and I am not sure what the query method is supposed to return.

Eg of a package provider:

https://github.com/puppetlabs/puppet/blob/master/lib/puppet/provider/package/dpkg.rb

Found example of package provider, but no documentation of what each method is supposed to do.

Thanks!

Karan
  • 14,824
  • 24
  • 91
  • 157

1 Answers1

1

The query method is called by the Puppet::Provider::Package base type. The properties method populates the property_hash using the query method:

  # Look up the current status.
  def properties
    if @property_hash.empty?
      @property_hash = query || {:ensure => :absent}
      @property_hash[:ensure] = :absent if @property_hash.empty?
    end
    @property_hash.dup
  end

In the rubydoc of Puppet::Provider it says the following about the property_hash:

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 {instances}, {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).

Thus, query should return a hash that reflects the current state of the package expressed in Puppet's package properties.

This is not documented AFAIK. I figured it out by reverse engineering.

Hope this helps. Good luck!

Lodewijk Bogaards
  • 19,777
  • 3
  • 28
  • 52