Class: PuppetDB::Model::Node
Overview
Parses Nodes from Puppetdb
All attributes returned by for the node from the puppetdb will be added as getter to the object
Class Method Summary collapse
-
.all ⇒ Object
get all nodes.
-
.all_hardware_servers ⇒ Object
get all hardware servers.
-
.by_class(classname) ⇒ Object
get nodes with a specific class.
-
.by_fact(facts, regexp: false) ⇒ Object
get nodes by matching facts.
-
.get(**arguments) ⇒ Object
Get object from Puppet DB.
Instance Method Summary collapse
-
#bios_version ⇒ Object
get the bios version.
-
#by_name(fqdn, regexp: false) ⇒ Object
get nodes by name.
-
#fact(name) ⇒ Object
get a fact associated with this node.
-
#initialize(attributes) ⇒ Node
constructor
parses the data returned by a puppetdb query of ‘node’ objects and parses it.
-
#uptime ⇒ Object
get the uptime.
Methods inherited from Base
client, client=, query, request
Constructor Details
#initialize(attributes) ⇒ Node
parses the data returned by a puppetdb query of ‘node’ objects and parses it
21 22 23 24 25 |
# File 'lib/puppetdb/model/node.rb', line 21 def initialize(attributes) @facts = {} attributes[:environment] = attributes[:catalog_environment] super(attributes) end |
Class Method Details
.all ⇒ Object
get all nodes
90 91 92 |
# File 'lib/puppetdb/model/node.rb', line 90 def self.all query('nodes {}') end |
.all_hardware_servers ⇒ Object
get all hardware servers
85 86 87 |
# File 'lib/puppetdb/model/node.rb', line 85 def self.all_hardware_servers query("nodes { inventory { facts.virtual = 'physical' and facts.dmi.chassis.type != 'Desktop' }}") end |
.by_class(classname) ⇒ Object
get nodes with a specific class
60 61 62 |
# File 'lib/puppetdb/model/node.rb', line 60 def self.by_class(classname) query("nodes { resources { type = 'Class' and title = #{classname.dump} }}") end |
.by_fact(facts, regexp: false) ⇒ Object
get nodes by matching facts
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/puppetdb/model/node.rb', line 68 def self.by_fact(facts, regexp: false) # use strict comparator by default, because this is less performance intensive comparator = regexp ? '~' : '=' filters = facts.map do |key, value| # Boolean values doesn't support regexp operator(~) and must not be escaped if [TrueClass, FalseClass].include?(value.class) "facts.#{key} = #{value}" else "facts.#{key} #{comparator} #{value.to_s.dump}" end end query("nodes { inventory { #{filters.join(' and ')} }}") end |
.get(**arguments) ⇒ Object
Get object from Puppet DB
Pass a list of key: val arguments as filters for the query.
38 39 40 |
# File 'lib/puppetdb/model/node.rb', line 38 def self.get(**arguments) super object: 'nodes', **arguments end |
Instance Method Details
#bios_version ⇒ Object
get the bios version
103 104 105 |
# File 'lib/puppetdb/model/node.rb', line 103 def bios_version fact('dmi.bios.version').value end |
#by_name(fqdn, regexp: false) ⇒ Object
get nodes by name
46 47 48 49 50 51 |
# File 'lib/puppetdb/model/node.rb', line 46 def by_name(fqdn, regexp: false) # use strict comparator by default, because this is less performance intensive comparator = regexp ? '~' : '=' query("node { certname #{comparator} #{fqdn.dump}}") end |
#fact(name) ⇒ Object
get a fact associated with this node
98 99 100 |
# File 'lib/puppetdb/model/node.rb', line 98 def fact(name) @facts[name] ||= Fact.new(certname: certname, name: name) end |
#uptime ⇒ Object
get the uptime
108 109 110 |
# File 'lib/puppetdb/model/node.rb', line 108 def uptime fact('system_uptime.uptime').value end |