hotdog 0.1.5 → 0.1.6
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/README.md +6 -0
- data/lib/hotdog/commands/search.rb +13 -9
- data/lib/hotdog/commands/ssh.rb +90 -0
- data/lib/hotdog/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5f4c5c3e2ce98b90bfd87374b07db36fc8b077f
|
4
|
+
data.tar.gz: be06e73ed9e26efe4e4613ab16f4192b3eae65c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0c733531b4b53e213528585429afd2c70ab20088e0740ae61bbca70e7a0306613fa1b6257a816980b180148ef8850e14d0ee9c6cace0b38395c05ddf84e5f5b
|
7
|
+
data.tar.gz: 1c3bdbc7e80deed263273903924bd0c03ad187b02aa87cb9c17b860ef421c7e367466379e428afdb95fc6eff9d39e3481a406c0e8bbe55d96b79ebb9935701f6
|
data/README.md
CHANGED
@@ -86,6 +86,12 @@ $ hotdog search availability-zone:us-east-1b and 'name:web-*'
|
|
86
86
|
i-03cb56ed
|
87
87
|
```
|
88
88
|
|
89
|
+
Login to the matching host using ssh.
|
90
|
+
|
91
|
+
```sh
|
92
|
+
$ hotdog ssh availability-zone:us-east-1b and 'name:web-*' -t public_ipv4 -u username
|
93
|
+
```
|
94
|
+
|
89
95
|
|
90
96
|
## Expression
|
91
97
|
|
@@ -20,6 +20,18 @@ module Hotdog
|
|
20
20
|
exit(1)
|
21
21
|
end
|
22
22
|
|
23
|
+
result = evaluate(node, self).sort
|
24
|
+
if 0 < result.length
|
25
|
+
result, fields = get_hosts_with_search_tags(result, node)
|
26
|
+
STDOUT.print(format(result, fields: fields))
|
27
|
+
logger.info("found %d host(s)." % result.length)
|
28
|
+
else
|
29
|
+
STDERR.puts("no match found: #{args.join(" ")}")
|
30
|
+
exit(1)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_hosts_with_search_tags(result, node)
|
23
35
|
drilldown = ->(n){
|
24
36
|
case
|
25
37
|
when n[:left] && n[:right] then drilldown.(n[:left]) + drilldown.(n[:right])
|
@@ -30,15 +42,7 @@ module Hotdog
|
|
30
42
|
}
|
31
43
|
identifiers = drilldown.call(node).map(&:to_s)
|
32
44
|
|
33
|
-
result
|
34
|
-
if 0 < result.length
|
35
|
-
result, fields = get_hosts(result, @options[:display_search_tags] ? identifiers : [])
|
36
|
-
STDOUT.print(format(result, fields: fields))
|
37
|
-
logger.info("found %d host(s)." % result.length)
|
38
|
-
else
|
39
|
-
STDERR.puts("no match found: #{args.join(" ")}")
|
40
|
-
exit(1)
|
41
|
-
end
|
45
|
+
get_hosts(result, @options[:display_search_tags] ? identifiers : [])
|
42
46
|
end
|
43
47
|
|
44
48
|
def parse(expression)
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "parslet"
|
5
|
+
require "hotdog/commands/search"
|
6
|
+
require "shellwords"
|
7
|
+
|
8
|
+
module Hotdog
|
9
|
+
module Commands
|
10
|
+
class Ssh < Search
|
11
|
+
def run(args=[])
|
12
|
+
ssh_option = {
|
13
|
+
index: nil,
|
14
|
+
options: [],
|
15
|
+
user: nil,
|
16
|
+
identity_file: nil,
|
17
|
+
}
|
18
|
+
|
19
|
+
optparse.on("-n", "--index INDEX", "Use this index of host if multiple servers are found", Integer) do |index|
|
20
|
+
ssh_option[:index] = index
|
21
|
+
end
|
22
|
+
optparse.on("-o SSH_OPTION", "Passes this string to ssh command through shell. This option may be given multiple times") do |option|
|
23
|
+
ssh_option[:options] += [option]
|
24
|
+
end
|
25
|
+
optparse.on("-i SSH_IDENTITY_FILE", "SSH identity file path") do |path|
|
26
|
+
ssh_option[:identity_file] = path
|
27
|
+
end
|
28
|
+
optparse.on("-u SSH_USER", "SSH login user name") do |user|
|
29
|
+
ssh_option[:user] = user
|
30
|
+
end
|
31
|
+
|
32
|
+
args = optparse.parse(args)
|
33
|
+
expression = args.join(" ").strip
|
34
|
+
if expression.empty?
|
35
|
+
exit(1)
|
36
|
+
end
|
37
|
+
|
38
|
+
begin
|
39
|
+
node = parse(expression)
|
40
|
+
rescue Parslet::ParseFailed => error
|
41
|
+
STDERR.puts("syntax error: " + error.cause.ascii_tree)
|
42
|
+
exit(1)
|
43
|
+
end
|
44
|
+
|
45
|
+
result = evaluate(node, self).sort
|
46
|
+
|
47
|
+
if result.length == 1
|
48
|
+
host = result[0]
|
49
|
+
elsif result.empty?
|
50
|
+
STDERR.puts("no match found: #{args.join(" ")}")
|
51
|
+
exit(1)
|
52
|
+
else
|
53
|
+
if ssh_option[:index] && result.length > ssh_option[:index]
|
54
|
+
host = result[ssh_option[:index]]
|
55
|
+
else
|
56
|
+
result, fields = get_hosts_with_search_tags(result, node)
|
57
|
+
|
58
|
+
# add "index" field
|
59
|
+
result = result.each_with_index.map {|host,i| [i] + host }
|
60
|
+
fields = ["index"] + fields
|
61
|
+
|
62
|
+
STDERR.print(format(result, fields: fields))
|
63
|
+
logger.info("found %d host(s)." % result.length)
|
64
|
+
exit(1)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
result, fields = get_hosts([host])
|
69
|
+
address = result.flatten.first
|
70
|
+
|
71
|
+
# build ssh command
|
72
|
+
cmdline = ["ssh"]
|
73
|
+
ssh_option[:options].each do |option|
|
74
|
+
cmdline << "-o" << option
|
75
|
+
end
|
76
|
+
if path = ssh_option[:identity_file]
|
77
|
+
cmdline << "-i" << Shellwords.escape(path)
|
78
|
+
end
|
79
|
+
if user = ssh_option[:user]
|
80
|
+
cmdline << (Shellwords.escape(user) + "@" + address)
|
81
|
+
else
|
82
|
+
cmdline << address
|
83
|
+
end
|
84
|
+
|
85
|
+
exec cmdline.join(" ")
|
86
|
+
exit(127)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/hotdog/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yamashita Yuu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03
|
11
|
+
date: 2015-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/hotdog/commands/hosts.rb
|
103
103
|
- lib/hotdog/commands/ls.rb
|
104
104
|
- lib/hotdog/commands/search.rb
|
105
|
+
- lib/hotdog/commands/ssh.rb
|
105
106
|
- lib/hotdog/commands/tags.rb
|
106
107
|
- lib/hotdog/commands/up.rb
|
107
108
|
- lib/hotdog/formatters.rb
|