Skip to content

Commit

Permalink
use instance debug instead of Puppet.debug
Browse files Browse the repository at this point in the history
The instance method prepends resource information to the debug message.

Example of Puppet.debug:

    Debug: Searching for hostgroup with name dev and title dev

Example of instance #debug:

    Debug: Foreman_hostgroup[dev](provider=rest_v3): Making get request to ...
  • Loading branch information
jhoblitt committed May 23, 2022
1 parent 0a61426 commit 175b4e0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/puppet/provider/foreman_hostgroup/rest_v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def exists?
end

def create
Puppet.debug("Creating Foreman Hostgroup #{resource[:name]} with parent #{resource[:parent_hostgroup]}")
debug("Creating Foreman Hostgroup #{resource[:name]} with parent #{resource[:parent_hostgroup]}")

if resource[:parent_hostgroup] && parent_hostgroup_id.nil?
raise Puppet::Error,
Expand Down Expand Up @@ -44,7 +44,7 @@ def create
end

def destroy
Puppet.debug("Destroying Foreman Hostgroup #{resource[:name]} with parent #{resource[:parent_hostgroup]}")
debug("Destroying Foreman Hostgroup #{resource[:name]} with parent #{resource[:parent_hostgroup]}")
path = "api/v2/hostgroups/#{id}"
r = request(:delete, path)

Expand All @@ -59,7 +59,7 @@ def destroy
def flush
return if @property_flush.empty?

Puppet.debug "Calling API to update properties for #{resource[:name]}"
debug "Calling API to update properties for #{resource[:name]}"

path = "api/v2/hostgroups/#{id}"
r = request(:put, path, {}, { hostgroup: @property_flush }.to_json)
Expand Down Expand Up @@ -107,7 +107,7 @@ def hostgroup
else
search_name
end
Puppet.debug("Searching for hostgroup with name #{search_name} and title #{search_title}")
debug("Searching for hostgroup with name #{search_name} and title #{search_title}")
r = request(:get, path, search: %(title="#{search_title}" and name="#{search_name}"))

raise Puppet::Error, "Error making GET request to Foreman at #{request_uri(path)}: #{error_message(r)}" unless success?(r)
Expand Down Expand Up @@ -141,7 +141,7 @@ def parent_hostgroup
path = 'api/v2/hostgroups'
search_title = resource[:parent_hostgroup]
search_name = resource[:parent_hostgroup_name] || search_title.split('/').last
Puppet.debug("Searching for parent hostgroup with name #{search_name} and title #{search_title}")
debug("Searching for parent hostgroup with name #{search_name} and title #{search_title}")
r = request(:get, path, search: %(title="#{search_title}" and name="#{search_name}"))

raise Puppet::Error, "Error making GET request to Foreman at #{request_uri(path)}: #{error_message(r)}" unless success?(r)
Expand Down

0 comments on commit 175b4e0

Please sign in to comment.