Class: EasyE

Inherits:
Object
  • Object
show all
Includes:
Options, Snapshotter
Defined in:
lib/easy_e.rb,
lib/easy_e/options.rb

Defined Under Namespace

Modules: Options, Snapshotter Classes: Plugin

Constant Summary collapse

@@logger =
nil

Constants included from Snapshotter

Snapshotter::AWS_INSTANCE_ID_URL

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Snapshotter

#access_key, #attached_volumes, #compute, #credentials, #devices_to_snap, #instance_id, #instance_name, #region, #secret_key, #should_snap, #snapshot_name, #take_snapshots

Methods included from Options

#option_parser

Class Method Details

.logger(logfile) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/easy_e.rb', line 13

def self.logger logfile
  unless @@logger
    @@logger = Logger.new(logfile || STDOUT)
    @@logger.level = Logger::DEBUG
    @@logger.formatter = proc do |severity, datetime, progname, msg|
      "[#{severity}] #{datetime.strftime("%Y-%m-%d %H:%M:%S")} #{msg}\n"
    end
  end

  @@logger
end

Instance Method Details

#executeObject



55
56
57
58
59
# File 'lib/easy_e.rb', line 55

def execute
  option_parser.parse!
  logger.debug "Debug logging enabled"
  run
end

#loggerObject



61
62
63
64
# File 'lib/easy_e.rb', line 61

def logger
  # HACK -- the logfile argument only gets used on the first invocation
  EasyE.logger options.logfile
end

#optionsObject



47
48
49
# File 'lib/easy_e/options.rb', line 47

def options
  @options ||= OpenStruct.new
end

#pluginsObject



25
26
27
# File 'lib/easy_e.rb', line 25

def plugins
  @plugins ||= registered_plugins.collect { |klass| klass.new }
end

#registered_pluginsObject



29
30
31
# File 'lib/easy_e.rb', line 29

def registered_plugins
  EasyE::Plugin.registered_plugins
end

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/easy_e.rb', line 33

def run
  plugins.each do |plugin|
    begin
      plugin.before if plugin.options.enable
    rescue Exception => e
      logger.error "Encountered error while running the #{plugin.name} plugin's before hook"
      logger.error e
    end
  end

  take_snapshots

  plugins.each do |plugin|
    begin
      plugin.after if plugin.options.enable
    rescue Exception => e
      logger.error "Encountered error while running the #{plugin.name} plugin's after hook"
      logger.error e
    end
  end
end