hotdog 0.1.2 → 0.1.3
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/lib/hotdog/application.rb +2 -1
- data/lib/hotdog/commands/down.rb +34 -0
- data/lib/hotdog/commands/up.rb +42 -0
- data/lib/hotdog/commands.rb +8 -1
- data/lib/hotdog/formatters/csv.rb +23 -0
- data/lib/hotdog/formatters/ltsv.rb +16 -0
- data/lib/hotdog/formatters/tsv.rb +19 -0
- data/lib/hotdog/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55a9182f8b6f286b99a6d76bd70db231d1e04945
|
4
|
+
data.tar.gz: e3eda56735a69185bf33faa2f1bc027b3573464c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fa9df74864b65781ddf36978fabfaed7c002e86173e9cb50b7a504addee6862d42d27b1d9b2ac397316080f9cb6e73529cc7bdea1904be69ff0222bf6b2174a
|
7
|
+
data.tar.gz: 28d70713ab309b7383f830f9d9fcf3431bf0f30c37a4ebfdc3b55592a4a0fd4dbe497712f5ed3dd0ded0da5568c4ea680484ada4e11d5aaff2ffc7361eacdcb0
|
data/lib/hotdog/application.rb
CHANGED
@@ -136,7 +136,8 @@ module Hotdog
|
|
136
136
|
load library
|
137
137
|
Hotdog::Commands.const_get(const_name(File.basename(library, ".rb")))
|
138
138
|
else
|
139
|
-
|
139
|
+
require "hotdog/commands/help"
|
140
|
+
Hotdog::Commands::Help
|
140
141
|
end
|
141
142
|
end
|
142
143
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
module Hotdog
|
6
|
+
module Commands
|
7
|
+
class Down < BaseCommand
|
8
|
+
def run(args=[])
|
9
|
+
args.each do |arg|
|
10
|
+
if arg.index(":").nil?
|
11
|
+
scope = "host:#{arg}"
|
12
|
+
else
|
13
|
+
scope = arg
|
14
|
+
end
|
15
|
+
start = Time.new
|
16
|
+
downtime = 86400 # TODO: make configurable
|
17
|
+
code, schedule = @dog.schedule_downtime(scope, :start => start.to_i, :end => (start+downtime).to_i)
|
18
|
+
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])
|
19
|
+
if code.to_i / 100 != 2
|
20
|
+
raise("dog.schedule_downtime(%s, ...) returns [%s, %s]" % [scope.inspect, code.inspect, schedule.inspect])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Remove persistent.db to schedule update on next invocation
|
25
|
+
if not @db.nil?
|
26
|
+
@db.close
|
27
|
+
FileUtils.rm_f(File.join(confdir, PERSISTENT_DB))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# vim:set ft=ruby :
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
module Hotdog
|
6
|
+
module Commands
|
7
|
+
class Up < BaseCommand
|
8
|
+
def run(args=[])
|
9
|
+
scopes = args.map { |arg|
|
10
|
+
if arg.index(":").nil?
|
11
|
+
"host:#{arg}"
|
12
|
+
else
|
13
|
+
arg
|
14
|
+
end
|
15
|
+
}
|
16
|
+
code, all_downtimes = @dog.get_all_downtimes()
|
17
|
+
if code.to_i / 100 != 2
|
18
|
+
raise("dog.get_all_downtimes() returns [%s, %s]" % [code.inspect, all_downtimes.inspect])
|
19
|
+
end
|
20
|
+
|
21
|
+
cancel_downtimes = all_downtimes.select { |downtime|
|
22
|
+
downtime["active"] and downtime["id"] and scopes.map { |scope| downtime.fetch("scope", []).include?(scope) }.any?
|
23
|
+
}
|
24
|
+
|
25
|
+
cancel_downtimes.each do |downtime|
|
26
|
+
code, cancel = @dog.cancel_downtime(downtime["id"])
|
27
|
+
if code.to_i / 100 != 2
|
28
|
+
raise("dog.cancel_downtime(%s) returns [%s, %s]" % [downtime["id"].inspect, code.inspect, cancel.inspect])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Remove persistent.db to schedule update on next invocation
|
33
|
+
if not @db.nil?
|
34
|
+
@db.close
|
35
|
+
FileUtils.rm_f(File.join(confdir, PERSISTENT_DB))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# vim:set ft=ruby :
|
data/lib/hotdog/commands.rb
CHANGED
@@ -8,6 +8,8 @@ require "sqlite3"
|
|
8
8
|
module Hotdog
|
9
9
|
module Commands
|
10
10
|
class BaseCommand
|
11
|
+
PERSISTENT_DB = "persistent.db"
|
12
|
+
|
11
13
|
def initialize(options={})
|
12
14
|
@application = options[:application]
|
13
15
|
@confdir = options[:confdir]
|
@@ -58,6 +60,11 @@ module Hotdog
|
|
58
60
|
s.index('*') or s.index('?') or s.index('[') or s.index(']')
|
59
61
|
end
|
60
62
|
|
63
|
+
def host?(host_id)
|
64
|
+
host_id = execute("SELECT id FROM hosts WHERE name = %s LIMIT 1", s)
|
65
|
+
not host_id.nil?
|
66
|
+
end
|
67
|
+
|
61
68
|
def get_hosts(hosts=[])
|
62
69
|
update_db
|
63
70
|
if 0 < tags.length
|
@@ -102,7 +109,7 @@ module Hotdog
|
|
102
109
|
def update_db(options={})
|
103
110
|
if @db.nil?
|
104
111
|
FileUtils.mkdir_p(confdir)
|
105
|
-
persistent = File.join(confdir,
|
112
|
+
persistent = File.join(confdir, PERSISTENT_DB)
|
106
113
|
|
107
114
|
if not @force and File.exist?(persistent) and Time.new < File.mtime(persistent) + expiry
|
108
115
|
begin
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "csv"
|
4
|
+
|
5
|
+
module Hotdog
|
6
|
+
module Formatters
|
7
|
+
class Csv < BaseFormatter
|
8
|
+
def format(result, options={})
|
9
|
+
result = result.dup
|
10
|
+
if options[:headers] and options[:fields]
|
11
|
+
result.unshift(options[:fields])
|
12
|
+
end
|
13
|
+
CSV.generate { |csv|
|
14
|
+
result.each do |row|
|
15
|
+
csv << row
|
16
|
+
end
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# vim:set ft=ruby :
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Hotdog
|
4
|
+
module Formatters
|
5
|
+
class Ltsv < BaseFormatter
|
6
|
+
def format(result, options={})
|
7
|
+
fields = options.fetch(:fields, [])
|
8
|
+
result.map { |row|
|
9
|
+
fields.zip(row).map { |column| column.join(":") }.join("\t")
|
10
|
+
}.join("\n") + "\n"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# vim:set ft=ruby :
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Hotdog
|
4
|
+
module Formatters
|
5
|
+
class Tsv < BaseFormatter
|
6
|
+
def format(result, options={})
|
7
|
+
result = result.dup
|
8
|
+
if options[:headers] and options[:fields]
|
9
|
+
result.unshift(options[:fields])
|
10
|
+
end
|
11
|
+
result.map { |row|
|
12
|
+
row.join("\t")
|
13
|
+
}.join("\n") + "\n"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# vim:set ft=ruby :
|
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.3
|
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-01-
|
11
|
+
date: 2015-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,14 +97,19 @@ files:
|
|
97
97
|
- hotdog.gemspec
|
98
98
|
- lib/hotdog/application.rb
|
99
99
|
- lib/hotdog/commands.rb
|
100
|
+
- lib/hotdog/commands/down.rb
|
100
101
|
- lib/hotdog/commands/help.rb
|
101
102
|
- lib/hotdog/commands/hosts.rb
|
102
103
|
- lib/hotdog/commands/ls.rb
|
103
104
|
- lib/hotdog/commands/search.rb
|
104
105
|
- lib/hotdog/commands/tags.rb
|
106
|
+
- lib/hotdog/commands/up.rb
|
105
107
|
- lib/hotdog/formatters.rb
|
108
|
+
- lib/hotdog/formatters/csv.rb
|
106
109
|
- lib/hotdog/formatters/json.rb
|
110
|
+
- lib/hotdog/formatters/ltsv.rb
|
107
111
|
- lib/hotdog/formatters/plain.rb
|
112
|
+
- lib/hotdog/formatters/tsv.rb
|
108
113
|
- lib/hotdog/formatters/yaml.rb
|
109
114
|
- lib/hotdog/version.rb
|
110
115
|
homepage: https://github.com/yyuu/hotdog
|