hotdog 0.4.1 → 0.5.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 +4 -0
- data/lib/hotdog/application.rb +21 -15
- data/lib/hotdog/commands/down.rb +10 -8
- data/lib/hotdog/commands/hosts.rb +0 -1
- data/lib/hotdog/commands/pssh.rb +27 -24
- data/lib/hotdog/commands/search.rb +640 -262
- data/lib/hotdog/commands/ssh.rb +30 -20
- data/lib/hotdog/commands/tags.rb +0 -1
- data/lib/hotdog/commands/up.rb +0 -1
- data/lib/hotdog/commands.rb +66 -22
- data/lib/hotdog/version.rb +1 -1
- data/spec/parser/parser_spec.rb +3 -3
- data/spec/parser/tag_expression_spec.rb +10 -8
- data/spec/parser/tag_glob_expression_spec.rb +10 -8
- data/spec/parser/tag_regexp_expression_spec.rb +10 -8
- 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: 4c464a62cf28997e088dd57a9e0ede3f2983f274
|
4
|
+
data.tar.gz: 85ad0d5644e20a84eaa99fee56c86ad8ead5de21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1ae715a85cc4ad9531cbbb23a965df3c0dede59a5c2fdaf4b09fd3bf24b4e4eb2f98863357924d88feff3729c4f89bf54c484311c9a2c7152ddb59e85db2101
|
7
|
+
data.tar.gz: d79aa608eecf509fc7838f2ab3682eeea5f7009bea8479f334a7194f875b9b8b05572f16dbbdaa1788f818c3f04ba002e64a12ec931bfc856c631f34ec9f37e3
|
data/README.md
CHANGED
@@ -105,6 +105,7 @@ expression: expression0
|
|
105
105
|
|
106
106
|
expression0: expression1 "and" expression
|
107
107
|
| expression1 "or" expression
|
108
|
+
| expression1 "xor" expression
|
108
109
|
| expression1
|
109
110
|
;
|
110
111
|
|
@@ -118,6 +119,9 @@ expression2: expression3 expression
|
|
118
119
|
|
119
120
|
expression3: expression4 "&&" expression
|
120
121
|
| expression4 "||" expression
|
122
|
+
| expression4 '&' expression
|
123
|
+
| expression4 '^' expression
|
124
|
+
| expression4 '|' expression
|
121
125
|
| expression4
|
122
126
|
;
|
123
127
|
|
data/lib/hotdog/application.rb
CHANGED
@@ -28,6 +28,7 @@ module Hotdog
|
|
28
28
|
logger.level = Logger::INFO
|
29
29
|
},
|
30
30
|
max_time: 5,
|
31
|
+
offline: false,
|
31
32
|
print0: false,
|
32
33
|
print1: true,
|
33
34
|
primary_tag: nil,
|
@@ -50,25 +51,27 @@ module Hotdog
|
|
50
51
|
end
|
51
52
|
args = @optparse.order(argv)
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
begin
|
55
|
+
command = ( args.shift || "help" )
|
56
|
+
get_command(command).new(self).tap do |cmd|
|
57
|
+
cmd.define_options(@optparse)
|
58
|
+
args = cmd.parse_options(@optparse, args)
|
59
|
+
unless options[:api_key]
|
60
|
+
raise("DATADOG_API_KEY is not set")
|
61
|
+
end
|
56
62
|
|
57
|
-
|
58
|
-
|
59
|
-
|
63
|
+
unless options[:application_key]
|
64
|
+
raise("DATADOG_APPLICATION_KEY is not set")
|
65
|
+
end
|
60
66
|
|
61
|
-
|
67
|
+
options[:formatter] = get_formatter(options[:format]).new
|
62
68
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
69
|
+
if options[:debug] or options[:verbose]
|
70
|
+
options[:logger].level = Logger::DEBUG
|
71
|
+
else
|
72
|
+
options[:logger].level = Logger::INFO
|
73
|
+
end
|
68
74
|
|
69
|
-
begin
|
70
|
-
command = ( args.shift || "help" )
|
71
|
-
get_command(command).new(self).tap do |cmd|
|
72
75
|
cmd.run(args)
|
73
76
|
end
|
74
77
|
rescue Errno::EPIPE
|
@@ -120,6 +123,9 @@ module Hotdog
|
|
120
123
|
@optparse.on("-V", "--[no-]verbose", "Enable verbose mode") do |v|
|
121
124
|
options[:verbose] = v
|
122
125
|
end
|
126
|
+
@optparse.on("--[no-]offline", "Enable offline mode") do |v|
|
127
|
+
options[:offline] = v
|
128
|
+
end
|
123
129
|
end
|
124
130
|
|
125
131
|
def const_name(name)
|
data/lib/hotdog/commands/down.rb
CHANGED
@@ -5,24 +5,26 @@ require "fileutils"
|
|
5
5
|
module Hotdog
|
6
6
|
module Commands
|
7
7
|
class Down < BaseCommand
|
8
|
-
def
|
9
|
-
downtime = 86400
|
10
|
-
start = Time.new
|
8
|
+
def define_options(optparse)
|
9
|
+
@downtime = 86400
|
10
|
+
@start = Time.new
|
11
11
|
optparse.on("--downtime DURATION") do |v|
|
12
|
-
downtime = v.to_i
|
12
|
+
@downtime = v.to_i
|
13
13
|
end
|
14
14
|
optparse.on("--start TIME") do |v|
|
15
|
-
start = Time.parse(v)
|
15
|
+
@start = Time.parse(v)
|
16
16
|
end
|
17
|
-
|
17
|
+
end
|
18
|
+
|
19
|
+
def run(args=[])
|
18
20
|
args.each do |arg|
|
19
21
|
if arg.index(":").nil?
|
20
22
|
scope = "host:#{arg}"
|
21
23
|
else
|
22
24
|
scope = arg
|
23
25
|
end
|
24
|
-
code, schedule = @dog.schedule_downtime(scope, :start => start.to_i, :end => (start
|
25
|
-
logger.debug("dog.schedule_donwtime(%s, :start => %s, :end => %s) #==> [%s, %s]" % [scope.inspect, start.to_i, (start
|
26
|
+
code, schedule = @dog.schedule_downtime(scope, :start => @start.to_i, :end => (@start+@downtime).to_i)
|
27
|
+
logger.debug("dog.schedule_donwtime(%s, :start => %s, :end => %s) #==> [%s, %s]" % [scope.inspect, @start.to_i, (@start+@downtime).to_i, code.inspect, schedule.inspect])
|
26
28
|
if code.to_i / 100 != 2
|
27
29
|
raise("dog.schedule_downtime(%s, ...) returns [%s, %s]" % [scope.inspect, code.inspect, schedule.inspect])
|
28
30
|
end
|
data/lib/hotdog/commands/pssh.rb
CHANGED
@@ -9,36 +9,39 @@ require "parallel"
|
|
9
9
|
module Hotdog
|
10
10
|
module Commands
|
11
11
|
class Pssh < Search
|
12
|
-
def
|
13
|
-
|
12
|
+
def define_options(optparse)
|
13
|
+
@ssh_options = @options.merge({
|
14
14
|
options: [],
|
15
15
|
user: nil,
|
16
16
|
port: nil,
|
17
17
|
identity_file: nil,
|
18
18
|
max_parallelism: nil,
|
19
|
-
}
|
19
|
+
})
|
20
20
|
|
21
21
|
optparse.on("-o SSH_OPTION", "Passes this string to ssh command through shell. This option may be given multiple times") do |option|
|
22
|
-
|
22
|
+
@ssh_options[:options] += [option]
|
23
23
|
end
|
24
24
|
optparse.on("-i SSH_IDENTITY_FILE", "SSH identity file path") do |path|
|
25
|
-
|
25
|
+
@ssh_options[:identity_file] = path
|
26
26
|
end
|
27
27
|
optparse.on("-p PORT", "Port of the remote host", Integer) do |port|
|
28
|
-
|
28
|
+
@ssh_options[:port] = port
|
29
29
|
end
|
30
30
|
optparse.on("-u SSH_USER", "SSH login user name") do |user|
|
31
|
-
|
31
|
+
@ssh_options[:user] = user
|
32
32
|
end
|
33
33
|
optparse.on("-P PARALLELISM", "Max parallelism", Integer) do |n|
|
34
|
-
|
34
|
+
@ssh_options[:max_parallelism] = n
|
35
35
|
end
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
+
def parse_options(optparse, args=[])
|
39
|
+
optparse.order(args)
|
40
|
+
end
|
38
41
|
|
39
|
-
|
40
|
-
|
41
|
-
expression =
|
42
|
+
def run(args=[])
|
43
|
+
use_color = STDOUT.tty?
|
44
|
+
expression = args.join(" ").strip
|
42
45
|
if expression.empty? || args.empty?
|
43
46
|
exit(1)
|
44
47
|
end
|
@@ -62,25 +65,25 @@ module Hotdog
|
|
62
65
|
|
63
66
|
# build ssh command
|
64
67
|
cmdline = ["ssh"]
|
65
|
-
|
68
|
+
@ssh_options[:options].each do |option|
|
66
69
|
cmdline << "-o" << option
|
67
70
|
end
|
68
|
-
if path =
|
71
|
+
if path = @ssh_options[:identity_file]
|
69
72
|
cmdline << "-i" << Shellwords.escape(path)
|
70
73
|
end
|
71
|
-
if port =
|
74
|
+
if port = @ssh_options[:port]
|
72
75
|
cmdline << "-p" << port.to_s
|
73
76
|
end
|
74
|
-
if
|
77
|
+
if @ssh_options[:forward_agent]
|
75
78
|
cmdline << "-A"
|
76
79
|
end
|
77
80
|
|
78
81
|
cmdline << "-o" << "BatchMode=yes"
|
79
82
|
|
80
|
-
user =
|
83
|
+
user = @ssh_options[:user]
|
81
84
|
|
82
|
-
threads =
|
83
|
-
stats = Parallel.map(addresses, in_threads: threads)
|
85
|
+
threads = @ssh_options[:max_parallelism] || addresses.size
|
86
|
+
stats = Parallel.map(addresses, in_threads: threads) { |address,name|
|
84
87
|
if use_color
|
85
88
|
header = "\e[0;36m#{name}\e[00m"
|
86
89
|
else
|
@@ -97,14 +100,14 @@ module Hotdog
|
|
97
100
|
c.concat(args)
|
98
101
|
|
99
102
|
IO.popen([*c, in: :close, err: [:child, :out]]) do |io|
|
100
|
-
io.each_line
|
103
|
+
io.each_line do |line|
|
101
104
|
STDOUT.write "#{header}: #{line}"
|
102
|
-
|
105
|
+
end
|
103
106
|
end
|
104
|
-
$?.success?
|
105
|
-
|
107
|
+
$?.success? # $? is thread-local variable
|
108
|
+
}
|
106
109
|
|
107
|
-
unless stats.all?
|
110
|
+
unless stats.all?
|
108
111
|
exit(1)
|
109
112
|
end
|
110
113
|
end
|