module Rudy::Routines

Rudy::Routines

Every Rudy routine is associated to a handler. There are four standard handler types: Startup, Shutdown, Reboot, and Passthrough. The first three are associated to routines of the same same. All other routines are handled by Rudy::Routines::Passthrough.

An individual routine is made up of various actions. Each action is associated to one of the following handlers: depends, disk, script, user. See each handler for the list of actions it is responsible for.

Public Class Methods

add_handler(name, klass) click to toggle source

Add a routine handler to @@handler.

# File lib/rudy/routines.rb, line 73
def self.add_handler(name, klass)
  add_some_class @@handler, Rudy::Routines::Handlers::Base, name, klass
end
add_routine(name, klass) click to toggle source

Add a routine handler to @@routine.

  • routine_name Literally the name of the routine that will have a special handler, like startup, shutdown, and reboot.

  • handler The class that will handle this routine. It must inherit Rudy::Routine::Base

Returns the value of handler.

# File lib/rudy/routines.rb, line 62
def self.add_routine(name, klass)
  add_some_class @@routine, Rudy::Routines::Base, name, klass
end
get_handler(name) click to toggle source

Returns the value in the @@handler associated to the key name if it exists, otherwise it returns nil

# File lib/rudy/routines.rb, line 79
def self.get_handler(name)
  get_some_class(@@handler, name) || nil
end
get_routine(name) click to toggle source

Returns the value in the @@routine associated to the key routine_name if it exists, otherwise it returns Rudy::Routines::Passthrough

# File lib/rudy/routines.rb, line 68
def self.get_routine(name)
  get_some_class(@@routine, name) || Rudy::Routines::Passthrough
end
has_handler?(name) click to toggle source
# File lib/rudy/routines.rb, line 84
def self.has_handler?(name);  @@handler.has_key?(name);  end
has_routine?(name) click to toggle source
# File lib/rudy/routines.rb, line 83
def self.has_routine?(name); @@routine.has_key?(name); end
machine_separator(name, awsid) click to toggle source
# File lib/rudy/routines.rb, line 120
def self.machine_separator(name, awsid)
  ('%s %-50s awsid: %s ' % [$/, name, awsid]).att(:reverse)
end
rescue(ret=nil, &bloc_party) click to toggle source
# File lib/rudy/routines.rb, line 97
def self.rescue(ret=nil, &bloc_party)

  begin
    ret = bloc_party.call
  rescue NameError, ArgumentError, RuntimeError, Errno::ECONNREFUSED => ex
    Rudy::Huxtable.le "#{ex.class}: #{ex.message}".color(:red)
    Rudy::Huxtable.le ex.backtrace if Rudy.debug?
    
    unless Rudy::Huxtable.global.parallel
      choice = Annoy.get_user_input('(S)kip  (A)bort: ', nil, 3600) || ''
      if choice.match(/\AS/i)
        # do nothing
      else
        exit 12
      end
     end
  rescue Interrupt
    Rudy::Huxtable.li "Aborting..."
    exit 12
  end
  ret
end
runner(routine, rset, lbox, argv=nil) click to toggle source

Executes a routine block

# File lib/rudy/routines.rb, line 87
def self.runner(routine, rset, lbox, argv=nil)
  routine.each_pair do |name,definition| 
    handler = Rudy::Routines.get_handler name
    #Rudy::Huxtable.li "  #{name}:".bright
    self.rescue {
      handler.execute(name, definition, rset, lbox, argv)
    }
  end
end

Private Class Methods

add_some_class(store, super_klass, name, klass) click to toggle source

See ::add_routine

# File lib/rudy/routines.rb, line 127
def self.add_some_class(store, super_klass, name, klass)
  if store.has_key? name
    Rudy::Huxtable.ld "Redefining class for #{name}"
  end
  unless klass.ancestors.member? super_klass
    raise "#{klass} does not inherit #{super_klass}"
  end
  store[name] = klass
end
get_some_class(store, routine_name) click to toggle source

See ::get_routine

# File lib/rudy/routines.rb, line 138
def self.get_some_class(store, routine_name)
  routine_name &&= routine_name.to_sym
  store[routine_name]
end