puppet-pssh 0.3 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/puppet-pssh.rb +32 -10
- metadata +2 -2
data/lib/puppet-pssh.rb
CHANGED
@@ -4,11 +4,12 @@ require 'excon'
|
|
4
4
|
require 'json'
|
5
5
|
require 'logger'
|
6
6
|
require 'colored'
|
7
|
+
require 'uri'
|
7
8
|
require 'pp'
|
8
9
|
|
9
10
|
module PuppetPSSH
|
10
11
|
|
11
|
-
VERSION = "0.3"
|
12
|
+
VERSION = "0.3.1"
|
12
13
|
|
13
14
|
if !defined? Log or Log.nil?
|
14
15
|
Log = Logger.new($stdout)
|
@@ -27,7 +28,8 @@ module PuppetPSSH
|
|
27
28
|
|
28
29
|
|
29
30
|
class BaseCommand < Clamp::Command
|
30
|
-
|
31
|
+
|
32
|
+
option "--deactivated", :flag, "Include also deactivated nodes"
|
31
33
|
option ["-m", "--match"], "REGEX", "Only the nodes matching the regex", :default => '.*'
|
32
34
|
option ["-p", "--puppetmaster"], "PUPPETMASTER", "Puppet master host", :default => 'puppet'
|
33
35
|
option ["-P", "--puppetmaster-port"], "PUPPETMASTER_PORT", "Puppet master port", :default => '8080'
|
@@ -40,8 +42,15 @@ module PuppetPSSH
|
|
40
42
|
"#{use_ssl? ? 'https' : 'http'}://#{puppetmaster}:#{puppetmaster_port}/"
|
41
43
|
end
|
42
44
|
|
43
|
-
def
|
44
|
-
|
45
|
+
def node_status(node)
|
46
|
+
JSON.parse(
|
47
|
+
Excon.get(master_url + "status/nodes/#{node}").body
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_nodes(puppetmaster, include_deactivated = false)
|
52
|
+
query = URI.encode '["=", ["node", "active"], true]'
|
53
|
+
url = "#{use_ssl? ? 'https' : 'http'}://#{puppetmaster}:#{puppetmaster_port}/nodes?query=#{query}"
|
45
54
|
Log.debug "Puppet master host: #{puppetmaster}"
|
46
55
|
Log.debug "Puppet master url: #{url}"
|
47
56
|
|
@@ -52,6 +61,16 @@ module PuppetPSSH
|
|
52
61
|
next unless n =~ /#{match}/
|
53
62
|
nodes << n
|
54
63
|
end
|
64
|
+
# IF --deactivated, include also deactivated nodes
|
65
|
+
if deactivated?
|
66
|
+
query = URI.encode '["=", ["node", "active"], false]'
|
67
|
+
url = "#{use_ssl? ? 'https' : 'http'}://#{puppetmaster}:#{puppetmaster_port}/nodes?query=#{query}"
|
68
|
+
out = Excon.get url
|
69
|
+
JSON.parse(out.body).each do |n|
|
70
|
+
next unless n =~ /#{match}/
|
71
|
+
nodes << n
|
72
|
+
end
|
73
|
+
end
|
55
74
|
rescue TypeError => e
|
56
75
|
raise Exception.new "Error retrieving node list from master host: #{puppetmaster}"
|
57
76
|
rescue Excon::Errors::SocketError => e
|
@@ -94,12 +113,14 @@ module PuppetPSSH
|
|
94
113
|
end
|
95
114
|
elsif status?
|
96
115
|
puts n
|
97
|
-
status =
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
116
|
+
status = node_status(n)
|
117
|
+
puts " #{'name:'.ljust(20).yellow} #{n}"
|
118
|
+
if status['deactivated']
|
119
|
+
puts " #{'deactivated:'.ljust(20).yellow} " +
|
120
|
+
"yes (#{status['deactivated']})"
|
121
|
+
else
|
122
|
+
puts " #{'deactivated:'.ljust(20).yellow} no"
|
123
|
+
end
|
103
124
|
puts " #{'catalog_timestamp:'.ljust(20).yellow} " +
|
104
125
|
"#{status['catalog_timestamp']}"
|
105
126
|
puts " #{'facts_timestamp:'.ljust(20).yellow} " +
|
@@ -110,6 +131,7 @@ module PuppetPSSH
|
|
110
131
|
end
|
111
132
|
rescue Exception => e
|
112
133
|
Log.error e.message
|
134
|
+
Log.debug e.backtrace
|
113
135
|
exit 1
|
114
136
|
end
|
115
137
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-pssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colored
|