module Puppet::Util::Puppetdb
Public Class Methods
# File lib/puppet/util/puppetdb.rb, line 22 def self.config @config ||= Puppet::Util::Puppetdb::Config.load @config end
# File lib/puppet/util/puppetdb.rb, line 40 def self.included(child) child.extend ClassMethods end
@api private
# File lib/puppet/util/puppetdb.rb, line 101 def log_x_deprecation_header(response) if warning = response['x-deprecation'] Puppet.deprecation_warning "Deprecation from PuppetDB: #{warning}" end end
# File lib/puppet/util/puppetdb.rb, line 18 def self.port config.port end
# File lib/puppet/util/puppetdb.rb, line 14 def self.server config.server end
Convert a value (usually a string) to a boolean
# File lib/puppet/util/puppetdb.rb, line 54 def self.to_bool(value) case value when true, "true"; return true when false, "false"; return false else raise ArgumentError.new("invalid value for Boolean: \"#{val}\"") end end
Given an instance of ruby's Time class, this method converts it to a String that conforms to PuppetDB's wire format for representing a date/time.
# File lib/puppet/util/puppetdb.rb, line 46 def self.to_wire_time(time) # The current implementation simply calls iso8601, but having this method # allows us to change that in the future if needed w/o being forced to # update all of the date objects elsewhere in the code. time.iso8601(9) end
Public Instance Methods
@api private
# File lib/puppet/util/puppetdb.rb, line 96 def config Puppet::Util::Puppetdb.config end
Profile a block of code and log the time it took to execute.
This outputs logs entries to the Puppet
masters logging destination providing the time it took, a message describing the profiled code and a leaf location marking where the profile method was called in the profiled hierachy.
@param message [String] A description of the profiled event @param block [Block] The segment of code to profile @api public
# File lib/puppet/util/puppetdb.rb, line 88 def profile(message, &block) message = "PuppetDB: " + message Puppet::Util::Profiler.profile(message, &block) end
Submit a command to PuppetDB
.
@param certname [String] hostname name of puppetdb instance @param payload [String] payload @param command_name [String] name of command @param version [Number] version number of command
# File lib/puppet/util/puppetdb.rb, line 71 def submit_command(certname, payload, command_name, version) profile "Submitted command '#{command_name}' version '#{version}'" do command = Puppet::Util::Puppetdb::Command.new(command_name, version, certname, payload) command.submit end end
Private Instance Methods
@api private
# File lib/puppet/util/puppetdb.rb, line 101 def log_x_deprecation_header(response) if warning = response['x-deprecation'] Puppet.deprecation_warning "Deprecation from PuppetDB: #{warning}" end end