hotdog 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/hotdog.gemspec +1 -0
- data/lib/hotdog/commands/pssh.rb +105 -0
- data/lib/hotdog/version.rb +1 -1
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 380b4a02d1dd654994f3f1ea4d4a69eef6712967
|
4
|
+
data.tar.gz: 4bbb5bb1974ec6cfa48e72780fb06e999935e65a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd8ac3e16d6b817d81d8e10911e343657643acaf03ffebd9a7227e3d47a38c5d5dc8af433ffc6775cef7ae2a6867bd2f541ff29acbb8c341a8c7d74ca61ceed3
|
7
|
+
data.tar.gz: 8c011e9f95681fcc351365a3d8309ef509dc1329b6895754cbd5b8c12734e01e9b47b993c983d67e25e5bb481d6e55fc6a02d2546c35a5a44ebf54b785582de1
|
data/hotdog.gemspec
CHANGED
@@ -0,0 +1,105 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "parslet"
|
5
|
+
require "hotdog/commands/search"
|
6
|
+
require "shellwords"
|
7
|
+
require "parallel"
|
8
|
+
|
9
|
+
module Hotdog
|
10
|
+
module Commands
|
11
|
+
class Pssh < Search
|
12
|
+
def run(args=[])
|
13
|
+
ssh_option = {
|
14
|
+
options: [],
|
15
|
+
user: nil,
|
16
|
+
port: nil,
|
17
|
+
identity_file: nil,
|
18
|
+
max_parallelism: nil,
|
19
|
+
}
|
20
|
+
|
21
|
+
optparse.on("-o SSH_OPTION", "Passes this string to ssh command through shell. This option may be given multiple times") do |option|
|
22
|
+
ssh_option[:options] += [option]
|
23
|
+
end
|
24
|
+
optparse.on("-i SSH_IDENTITY_FILE", "SSH identity file path") do |path|
|
25
|
+
ssh_option[:identity_file] = path
|
26
|
+
end
|
27
|
+
optparse.on("-p PORT", "Port of the remote host", Integer) do |port|
|
28
|
+
ssh_option[:port] = port
|
29
|
+
end
|
30
|
+
optparse.on("-u SSH_USER", "SSH login user name") do |user|
|
31
|
+
ssh_option[:user] = user
|
32
|
+
end
|
33
|
+
optparse.on("-P PARALLELISM", "Max parallelism", Integer) do |n|
|
34
|
+
ssh_option[:max_parallelism] = n
|
35
|
+
end
|
36
|
+
|
37
|
+
search_args = []
|
38
|
+
optparse.order!(args) {|search_arg| search_args.push(search_arg) }
|
39
|
+
expression = search_args.join(" ").strip
|
40
|
+
if expression.empty? || args.empty?
|
41
|
+
exit(1)
|
42
|
+
end
|
43
|
+
|
44
|
+
begin
|
45
|
+
node = parse(expression)
|
46
|
+
rescue Parslet::ParseFailed => error
|
47
|
+
STDERR.puts("syntax error: " + error.cause.ascii_tree)
|
48
|
+
exit(1)
|
49
|
+
end
|
50
|
+
|
51
|
+
result = evaluate(node, self).sort
|
52
|
+
result, fields = get_hosts(result)
|
53
|
+
|
54
|
+
if result.empty?
|
55
|
+
STDERR.puts("no match found: #{search_args.join(" ")}")
|
56
|
+
exit(1)
|
57
|
+
end
|
58
|
+
|
59
|
+
addresses = result.map {|host| [host.first, host.last] }
|
60
|
+
|
61
|
+
# build ssh command
|
62
|
+
cmdline = ["ssh"]
|
63
|
+
ssh_option[:options].each do |option|
|
64
|
+
cmdline << "-o" << option
|
65
|
+
end
|
66
|
+
if path = ssh_option[:identity_file]
|
67
|
+
cmdline << "-i" << Shellwords.escape(path)
|
68
|
+
end
|
69
|
+
if port = ssh_option[:port]
|
70
|
+
cmdline << "-p" << port.to_s
|
71
|
+
end
|
72
|
+
if ssh_option[:forward_agent]
|
73
|
+
cmdline << "-A"
|
74
|
+
end
|
75
|
+
|
76
|
+
cmdline << "-o" << "BatchMode=yes"
|
77
|
+
|
78
|
+
user = ssh_option[:user]
|
79
|
+
|
80
|
+
threads = ssh_option[:max_parallelism] || addresses.size
|
81
|
+
stats = Parallel.map(addresses, in_threads: threads) do |address,name|
|
82
|
+
c = cmdline.dup
|
83
|
+
if user
|
84
|
+
c << (user + "@" + address)
|
85
|
+
else
|
86
|
+
c << address
|
87
|
+
end
|
88
|
+
|
89
|
+
c.concat(args)
|
90
|
+
|
91
|
+
IO.popen([*c, in: :close, err: [:child, :out]]) do |io|
|
92
|
+
io.each_line {|line|
|
93
|
+
STDOUT.write "#{name}: #{line}"
|
94
|
+
}
|
95
|
+
end
|
96
|
+
$?.success? # $? is thread-local variable
|
97
|
+
end
|
98
|
+
|
99
|
+
unless stats.all? {|success| success }
|
100
|
+
exit(1)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/lib/hotdog/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hotdog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yamashita Yuu
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 1.3.10
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: parallel
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.4.1
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.4.1
|
83
97
|
description: Yet another command-line tool for Datadog
|
84
98
|
email:
|
85
99
|
- peek824545201@gmail.com
|
@@ -101,6 +115,7 @@ files:
|
|
101
115
|
- lib/hotdog/commands/help.rb
|
102
116
|
- lib/hotdog/commands/hosts.rb
|
103
117
|
- lib/hotdog/commands/ls.rb
|
118
|
+
- lib/hotdog/commands/pssh.rb
|
104
119
|
- lib/hotdog/commands/search.rb
|
105
120
|
- lib/hotdog/commands/ssh.rb
|
106
121
|
- lib/hotdog/commands/tags.rb
|