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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc96b843200f93f4a812c164c690eead02717239
4
- data.tar.gz: ee5bd2f02afa28d4b180d8c1392a01d33fc6e9eb
3
+ metadata.gz: 55a9182f8b6f286b99a6d76bd70db231d1e04945
4
+ data.tar.gz: e3eda56735a69185bf33faa2f1bc027b3573464c
5
5
  SHA512:
6
- metadata.gz: 3a1a31cac900cbf90f39136308851a1545bd38ff736322dd58b48dd9744c7b495c8980743dfd8fb6c9948b28bcbde57205be3ce07d68b56603a0c8a2ffd307b9
7
- data.tar.gz: cde383321ce521ffce0a7c6053160de969fab6756d243bf22256502bcf89db142409009a8f8d70c44dcff64283fb4c8643bd7d1b4e16c177a05ef15d4be3af4c
6
+ metadata.gz: 2fa9df74864b65781ddf36978fabfaed7c002e86173e9cb50b7a504addee6862d42d27b1d9b2ac397316080f9cb6e73529cc7bdea1904be69ff0222bf6b2174a
7
+ data.tar.gz: 28d70713ab309b7383f830f9d9fcf3431bf0f30c37a4ebfdc3b55592a4a0fd4dbe497712f5ed3dd0ded0da5568c4ea680484ada4e11d5aaff2ffc7361eacdcb0
@@ -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
- raise(NameError.new("unknown command: #{name}"))
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 :
@@ -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, "persistent.db")
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 :
@@ -1,3 +1,3 @@
1
1
  module Hotdog
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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-16 00:00:00.000000000 Z
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