Method: Puppet::Provider::DscBaseProvider#get

Defined in:
lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb

#get(context, names = nil) ⇒ Hash

Attempts to retrieve an instance of the DSC resource, invoking the ‘Get` method and passing any namevars as the Properties to Invoke-DscResource. The result object, if any, is compared to the specified properties in the Puppet Resource to decide whether it needs to be created, updated, deleted, or whether it is in the desired state.

Parameters:

  • context (Object)

    the Puppet runtime context to operate in and send feedback to

  • names (Hash) (defaults to: nil)

    the hash of namevar properties and their values to use to get the resource

Returns:

  • (Hash)

    returns a hash representing the current state of the object, if it exists



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb', line 128

def get(context, names = nil)
  # Relies on the get_simple_filter feature to pass the namevars
  # as an array containing the namevar parameters as a hash.
  # This hash is functionally the same as a should hash as
  # passed to the invocable_resource method.
  context.debug('Collecting data from the DSC Resource')

  # If the resource has already been queried, do not bother querying for it again
  cached_results = fetch_cached_hashes(@cached_query_results, names)
  return cached_results unless cached_results.empty?

  if @cached_canonicalized_resource.empty?
    mandatory_properties = {}
  else
    canonicalized_resource = @cached_canonicalized_resource[0].dup
    mandatory_properties = canonicalized_resource.select do |attribute, _value|
      (mandatory_get_attributes(context) - namevar_attributes(context)).include?(attribute)
    end
    # If dsc_psdscrunascredential was specified, re-add it here.
    mandatory_properties[:dsc_psdscrunascredential] = canonicalized_resource[:dsc_psdscrunascredential] if canonicalized_resource.key?(:dsc_psdscrunascredential)
  end
  names.collect do |name|
    name = { name: name } if name.is_a? String
    invoke_get_method(context, name.merge(mandatory_properties))
  end
end