Module: Puppet::Util::Puppetdb
- Included in:
- Node::Facts::Puppetdb, Node::Puppetdb, Resource::Catalog::Puppetdb, Resource::Puppetdb, Command
- Defined in:
- lib/puppet/util/puppetdb/char_encoding.rb,
lib/puppet/util/puppetdb/command_names.rb,
lib/puppet/util/puppetdb/blacklist.rb,
lib/puppet/util/puppetdb/config.rb,
lib/puppet/util/puppetdb.rb
Defined Under Namespace
Modules: CharEncoding, ClassMethods, CommandNames Classes: Blacklist, Command, Config
Public instance methods collapse
-
#profile(message, metric_id, &block) ⇒ Object
Profile a block of code and log the time it took to execute.
-
#submit_command(certname, payload, command_name, version) ⇒ Hash <String, String>
Submit a command to PuppetDB.
Private instance methods collapse
- .log_x_deprecation_header(response) ⇒ Object private
- #config ⇒ Object private
Class Method Summary collapse
- .config ⇒ Object
- .included(child) ⇒ Object
- .port ⇒ Object
- .puppet3compat? ⇒ Boolean
- .server ⇒ Object
-
.to_bool(value) ⇒ Object
Convert a value (usually a string) to a boolean.
-
.to_wire_time(time) ⇒ Object
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.
- .url_path(path) ⇒ Object
Class Method Details
.config ⇒ Object
28 29 30 31 |
# File 'lib/puppet/util/puppetdb.rb', line 28 def self.config @config ||= Puppet::Util::Puppetdb::Config.load @config end |
.included(child) ⇒ Object
50 51 52 |
# File 'lib/puppet/util/puppetdb.rb', line 50 def self.included(child) child.extend ClassMethods end |
.log_x_deprecation_header(response) ⇒ Object
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.
120 121 122 123 124 |
# File 'lib/puppet/util/puppetdb.rb', line 120 def log_x_deprecation_header(response) if warning = response['x-deprecation'] Puppet.deprecation_warning "Deprecation from PuppetDB: #{warning}" end end |
.port ⇒ Object
17 18 19 |
# File 'lib/puppet/util/puppetdb.rb', line 17 def self.port config.port end |
.puppet3compat? ⇒ Boolean
33 34 35 |
# File 'lib/puppet/util/puppetdb.rb', line 33 def self.puppet3compat? defined?(Puppet::Parser::AST::HashOrArrayAccess) end |
.server ⇒ Object
13 14 15 |
# File 'lib/puppet/util/puppetdb.rb', line 13 def self.server config.server end |
.to_bool(value) ⇒ Object
Convert a value (usually a string) to a boolean
64 65 66 67 68 69 70 71 |
# File 'lib/puppet/util/puppetdb.rb', line 64 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 |
.to_wire_time(time) ⇒ Object
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.
56 57 58 59 60 61 |
# File 'lib/puppet/util/puppetdb.rb', line 56 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 |
.url_path(path) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/puppet/util/puppetdb.rb', line 21 def self.url_path(path) unless path.start_with?("/") path = "/" + path end config.url_prefix + path end |
Instance Method Details
#config ⇒ Object
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.
115 116 117 |
# File 'lib/puppet/util/puppetdb.rb', line 115 def config Puppet::Util::Puppetdb.config end |
#profile(message, metric_id, &block) ⇒ Object
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.
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/puppet/util/puppetdb.rb', line 101 def profile(, metric_id, &block) = "PuppetDB: " + arity = Puppet::Util::Profiler.method(:profile).arity case arity when 1 Puppet::Util::Profiler.profile(, &block) when 2, -2 Puppet::Util::Profiler.profile(, metric_id, &block) end end |
#submit_command(certname, payload, command_name, version) ⇒ Hash <String, String>
Submit a command to PuppetDB.
82 83 84 85 86 87 88 |
# File 'lib/puppet/util/puppetdb.rb', line 82 def submit_command(certname, payload, command_name, version) profile("Submitted command '#{command_name}' version '#{version}'", [:puppetdb, :command, :submit, command_name, version]) do command = Puppet::Util::Puppetdb::Command.new(command_name, version, certname, payload) command.submit end end |