koma 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/koma.gemspec +1 -0
- data/lib/koma/cli.rb +27 -11
- data/lib/koma/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3eee13c68f078a3f02b2d19e063eff87acd4e0fb
|
4
|
+
data.tar.gz: 3f0b322b862a2059da3ee03eb62fdbb8b555b47e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3349038bfe0a67bc48dc05eb1568efd4d5c1b6b8a84fa02eb27ffda0c723f78a395a9a2ae90064c1c52acb7d6bf966dae359c17ff1a3cc9c3cef10af9d5071cc
|
7
|
+
data.tar.gz: 5115f5fbd67158edb19ab6ea258fca8447ac14f32d1714b8a179c98512ed10f977dd50271b13e3dc69c94b3fd82b752396f1bf2855d265c20c785bbf1be1cb70
|
data/README.md
CHANGED
@@ -32,6 +32,20 @@ $ koma ssh example.com
|
|
32
32
|
|
33
33
|
And get stdout like [this](stdout_sample.json).
|
34
34
|
|
35
|
+
### Multi host gathering
|
36
|
+
|
37
|
+
```sh
|
38
|
+
$ koma ssh example.com,example.jp
|
39
|
+
{
|
40
|
+
"example.com" : {
|
41
|
+
...
|
42
|
+
},
|
43
|
+
"example.jp" : {
|
44
|
+
...
|
45
|
+
}
|
46
|
+
}
|
47
|
+
```
|
48
|
+
|
35
49
|
## Host inventory keys
|
36
50
|
|
37
51
|
```sh
|
data/koma.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_runtime_dependency 'thor'
|
23
23
|
spec.add_runtime_dependency 'highline'
|
24
24
|
spec.add_runtime_dependency 'specinfra', '~> 2.48'
|
25
|
+
spec.add_runtime_dependency 'parallel'
|
25
26
|
spec.add_development_dependency 'bundler', '~> 1.9'
|
26
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
27
28
|
spec.add_development_dependency 'rspec'
|
data/lib/koma/cli.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'json'
|
3
|
+
require 'parallel'
|
3
4
|
|
4
5
|
include Specinfra::Helper::Set
|
5
6
|
|
@@ -22,16 +23,17 @@ module Koma
|
|
22
23
|
desc: 'port',
|
23
24
|
aliases: :p
|
24
25
|
def ssh(host)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
if host.include?(',')
|
27
|
+
list = host.split(',')
|
28
|
+
results = Parallel.map(list, in_thread: 4) do |h|
|
29
|
+
ssh_out(h, options)
|
30
|
+
end
|
31
|
+
arr = [list, results].transpose
|
32
|
+
puts JSON.pretty_generate(Hash[*arr.flatten])
|
33
|
+
else
|
34
|
+
result = ssh_out(host, options)
|
35
|
+
puts JSON.pretty_generate(result)
|
36
|
+
end
|
35
37
|
end
|
36
38
|
|
37
39
|
desc 'exec', 'stdout local host inventory'
|
@@ -42,7 +44,8 @@ module Koma
|
|
42
44
|
aliases: :k
|
43
45
|
def exec
|
44
46
|
set :backend, :exec
|
45
|
-
|
47
|
+
result = out(options[:key])
|
48
|
+
puts JSON.pretty_generate(result)
|
46
49
|
end
|
47
50
|
|
48
51
|
desc 'keys', 'host inventory keys'
|
@@ -58,6 +61,19 @@ module Koma
|
|
58
61
|
Specinfra::HostInventory.inventory_keys
|
59
62
|
end
|
60
63
|
|
64
|
+
def ssh_out(host, options)
|
65
|
+
user, host = host.split('@') if host.include?('@')
|
66
|
+
set :backend, :ssh
|
67
|
+
set :host, host
|
68
|
+
set :request_pty, true
|
69
|
+
ssh_options = Net::SSH::Config.for(host)
|
70
|
+
ssh_options[:user] = user if user
|
71
|
+
ssh_options[:keys] = [options[:identity_file]] if options[:identity_file]
|
72
|
+
ssh_options[:port] = options[:port] if options[:port]
|
73
|
+
set :ssh_options, ssh_options
|
74
|
+
out(options[:key])
|
75
|
+
end
|
76
|
+
|
61
77
|
def out(key = nil)
|
62
78
|
out = {}
|
63
79
|
keys = if key.nil?
|
data/lib/koma/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: koma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- k1LoW
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.48'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: parallel
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|