Class: PuppetPSSH::BaseCommand

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

Direct Known Subclasses

List, Run

Instance Method Summary collapse

Instance Method Details

#get_nodes(puppetmaster, include_deactivated = false) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/puppet-pssh.rb', line 94

def get_nodes(puppetmaster, include_deactivated = false)
  query = URI.encode '["=", ["node", "active"], true]'
  url = "#{use_ssl? ? 'https' : 'http'}://#{puppetmaster}:#{puppetmaster_port}/nodes?query=#{query}"
  Log.debug "Puppet master host: #{puppetmaster}"
  Log.debug "Puppet master url: #{url}"

  nodes = []
  begin
    out = Excon.get url
    JSON.parse(out.body).each do |n| 
      next unless  n =~ /#{match}/
      nodes << n 
    end
    # IF --deactivated, include also deactivated nodes
    if deactivated?
      query = URI.encode '["=", ["node", "active"], false]'
      url = "#{use_ssl? ? 'https' : 'http'}://#{puppetmaster}:#{puppetmaster_port}/nodes?query=#{query}"
      out = Excon.get url
      JSON.parse(out.body).each do |n| 
        next unless  n =~ /#{match}/
        nodes << n 
      end
    end
  rescue TypeError => e
    raise Exception.new "Error retrieving node list from master host: #{puppetmaster}"
  rescue Excon::Errors::SocketError => e
    raise Exception.new "Could not connect to the puppet master host: #{puppetmaster}"
  end
  nodes
end

#master_urlObject



84
85
86
# File 'lib/puppet-pssh.rb', line 84

def master_url
  "#{use_ssl? ? 'https' : 'http'}://#{puppetmaster}:#{puppetmaster_port}/"
end

#node_status(node) ⇒ Object



88
89
90
91
92
# File 'lib/puppet-pssh.rb', line 88

def node_status(node)
  JSON.parse(
    Excon.get(master_url + "status/nodes/#{node}").body
  )
end