Class: Hotdog::Commands::Up

Inherits:
BaseCommand show all
Defined in:
lib/hotdog/commands/up.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::MASK_DATABASE, BaseCommand::MASK_QUERY, BaseCommand::PERSISTENT_DB

Instance Attribute Summary

Attributes inherited from BaseCommand

#application, #logger, #options

Instance Method Summary collapse

Methods inherited from BaseCommand

#execute, #fixed_string?, #initialize, #reload

Constructor Details

This class inherits a constructor from Hotdog::Commands::BaseCommand

Instance Method Details

#run(args = []) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hotdog/commands/up.rb', line 8

def run(args=[])
  args = optparse.parse(args)
  scopes = args.map { |arg|
    if arg.index(":").nil?
      "host:#{arg}"
    else
      arg
    end
  }
  code, all_downtimes = @dog.get_all_downtimes()
  if code.to_i / 100 != 2
    raise("dog.get_all_downtimes() returns [%s, %s]" % [code.inspect, all_downtimes.inspect])
  end

  cancel_downtimes = all_downtimes.select { |downtime|
    downtime["active"] and downtime["id"] and scopes.map { |scope| downtime.fetch("scope", []).include?(scope) }.any?
  }

  cancel_downtimes.each do |downtime|
    code, cancel = @dog.cancel_downtime(downtime["id"])
    if code.to_i / 100 != 2
      raise("dog.cancel_downtime(%s) returns [%s, %s]" % [downtime["id"].inspect, code.inspect, cancel.inspect])
    end
  end

  # Remove persistent.db to schedule update on next invocation
  if @db
    close_db(@db)
    FileUtils.rm_f(File.join(options[:confdir], PERSISTENT_DB))
  end
end