Class: PuppetPSSH::PuppetDB

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-pssh.rb

Instance Method Summary collapse

Constructor Details

#initialize(host = 'puppet', port = '8080', use_ssl = false) ⇒ PuppetDB

Returns a new instance of PuppetDB.



16
17
18
19
20
# File 'lib/puppet-pssh.rb', line 16

def initialize(host = 'puppet', port = '8080', use_ssl = false)
  @host = host
  @port = port
  @use_ssl = use_ssl
end

Instance Method Details

#active_nodesObject



50
51
52
53
# File 'lib/puppet-pssh.rb', line 50

def active_nodes
  query = URI.encode '["=", ["node", "active"], true]'
  get_nodes_from_query query
end

#deactivated_nodesObject



45
46
47
48
# File 'lib/puppet-pssh.rb', line 45

def deactivated_nodes
  query = URI.encode '["=", ["node", "active"], false]'
  get_nodes_from_query query
end

#get_nodes_from_query(query) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/puppet-pssh.rb', line 26

def get_nodes_from_query(query)
  target_url = "#{url}nodes?query=#{query}"
  Log.debug "Puppet master host: #{@host}"
  Log.debug "Puppet master url: #{target_url}"

  nodes = []
  begin
    out = Excon.get target_url
    JSON.parse(out.body).each do |n| 
      nodes << n 
    end
  rescue TypeError => e
    raise Exception.new "Error retrieving node list from master host: #{@host}"
  rescue Excon::Errors::SocketError => e
    raise Exception.new "Could not connect to the puppet master host: #{@host}"
  end
  nodes
end

#urlObject



22
23
24
# File 'lib/puppet-pssh.rb', line 22

def url 
  "#{@use_ssl ? 'https' : 'http'}://#{@host}:#{@port}/"
end