Class: SnapEbs

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

Defined Under Namespace

Modules: Options, Snapshotter Classes: Plugin

Constant Summary collapse

VERSION =
'0.0.22'
@@logger =
nil

Constants included from Snapshotter

Snapshotter::AWS_INSTANCE_ID_URL

Instance Attribute Summary

Attributes included from Snapshotter

#compute

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Snapshotter

#take_snapshots

Methods included from Options

#option_parser

Class Method Details

.logger(logfile) ⇒ Object



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

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

.logger=(logger_) ⇒ Object



26
27
28
# File 'lib/snap_ebs.rb', line 26

def self.logger= logger_
  @@logger = logger_
end

Instance Method Details

#executeObject

Entry point for the snap-ebs binary



66
67
68
69
70
# File 'lib/snap_ebs.rb', line 66

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

#loggerObject

Get the global logger instance ‘logger.debug ’reticulating splines’‘



74
75
76
77
# File 'lib/snap_ebs.rb', line 74

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

#optionsObject

Get the root options object, and instance of OpenStruct



60
61
62
# File 'lib/snap_ebs/options.rb', line 60

def options
  @options ||= OpenStruct.new
end

#pluginsObject



30
31
32
# File 'lib/snap_ebs.rb', line 30

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

#registered_pluginsObject



34
35
36
# File 'lib/snap_ebs.rb', line 34

def registered_plugins
  SnapEbs::Plugin.registered_plugins
end

#runObject

Executes plugin before hooks, takes the snapshot, then runs the after hooks. Plugin hooks are called within rescue blocks to isolate errors from affecting other plugins or the snapshot plugins. Note that non- standard exceptions (i.e. out of memory or keyboard interrupt) will still cause a execution to abort.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/snap_ebs.rb', line 43

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