Class: SnapEbs
- Inherits:
-
Object
- Object
- SnapEbs
- Includes:
- Options, Snapshotter
- Defined in:
- lib/snap_ebs.rb,
lib/snap_ebs/options.rb
Defined Under Namespace
Modules: Options, Snapshotter Classes: Plugin
Constant Summary collapse
- @@logger =
nil
Constants included from Snapshotter
Snapshotter::AWS_INSTANCE_ID_URL
Instance Attribute Summary
Attributes included from Snapshotter
Class Method Summary collapse
Instance Method Summary collapse
-
#execute ⇒ Object
Entry point for the
snap-ebsbinary. -
#logger ⇒ Object
Get the global logger instance ‘logger.debug ’reticulating splines’‘.
-
#options ⇒ Object
Get the root
optionsobject, and instance of OpenStruct. - #plugins ⇒ Object
- #registered_plugins ⇒ Object
-
#run ⇒ Object
Executes plugin before hooks, takes the snapshot, then runs the after hooks.
Methods included from Snapshotter
Methods included from Options
Class Method Details
.logger(logfile) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/snap_ebs.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 |
.logger=(logger_) ⇒ Object
25 26 27 |
# File 'lib/snap_ebs.rb', line 25 def self.logger= logger_ @@logger = logger_ end |
Instance Method Details
#execute ⇒ Object
Entry point for the snap-ebs binary
65 66 67 68 69 |
# File 'lib/snap_ebs.rb', line 65 def execute option_parser.parse! logger.debug "Debug logging enabled" run end |
#logger ⇒ Object
Get the global logger instance ‘logger.debug ’reticulating splines’‘
73 74 75 76 |
# File 'lib/snap_ebs.rb', line 73 def logger # HACK -- the logfile argument only gets used on the first invocation SnapEbs.logger .logfile end |
#options ⇒ Object
Get the root options object, and instance of OpenStruct
55 56 57 |
# File 'lib/snap_ebs/options.rb', line 55 def ||= OpenStruct.new end |
#plugins ⇒ Object
29 30 31 |
# File 'lib/snap_ebs.rb', line 29 def plugins @plugins ||= registered_plugins.collect { |klass| klass.new } end |
#registered_plugins ⇒ Object
33 34 35 |
# File 'lib/snap_ebs.rb', line 33 def registered_plugins SnapEbs::Plugin.registered_plugins end |
#run ⇒ Object
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.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/snap_ebs.rb', line 42 def run plugins.each do |plugin| begin plugin.before if plugin..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..enable rescue => e logger.error "Encountered error while running the #{plugin.name} plugin's after hook" logger.error e end end end |