Permalink
Browse files

Renamed routine handlers to 'routines' (b/c that's what they are) and…

… helpers to handlers. That sentence is confusing but the code is absolutely less confusing now :]
  • Loading branch information...
1 parent 0ed2c22 commit 7fea0e7363744a0e6c5d412a3423fa48afd73dd4 @delano delano committed Jun 23, 2009
View
@@ -95,16 +95,19 @@ def self.to_f; self.to_s.to_f; end
end
- def Rudy.debug?; @@debug == true; end
def Rudy.quiet?; @@quiet == true; end
- def Rudy.yes?; @@yes == true; end
- def Rudy.enable_debug; @@debug = true; end
def Rudy.enable_quiet; @@quiet = true; end
- def Rudy.enable_yes; @@yes = true; end
- def Rudy.disable_debug; @@debug = false; end
def Rudy.disable_quiet; @@quiet = false; end
+
+ def Rudy.yes?; @@yes == true; end
+ def Rudy.enable_yes; @@yes = true; end
def Rudy.disable_yes; @@yes = false; end
+ def Rudy.debug?; @@debug == true; end
+ def Rudy.enable_debug; @@debug = true; end
+ def Rudy.disable_debug; @@debug = false; end
+
+
def Rudy.sysinfo; @@sysinfo; end
def sysinfo; @@sysinfo; end
@@ -165,6 +165,9 @@ class Routines < Caesars
chill :xlocal
chill :xremote
+ forced_hash :network
+ chill :network
+
# Startup, Shutdown, Reboot routines
forced_hash :before_local
forced_hash :before_remote
View
@@ -20,6 +20,6 @@ def deepest_point(h=self, steps=0)
end
steps
end
-
+
end
View
@@ -9,19 +9,20 @@ module Rudy
# are handled by Rudy::Routines::Passthrough.
#
# An individual routine is made up of various actions. Each action is
- # associated to one of the following helpers: depends, disk, script,
- # user. See each helper for the list of actions it is responsible for.
+ # associated to one of the following handlers: depends, disk, script,
+ # user. See each handler for the list of actions it is responsible for.
module Routines
require 'rudy/routines/base'
+ require 'rudy/routines/handlers/base'
# A Hash of routine names pointing to a specific handler.
- # See Rudy::Routines.add_handler
- @@handler = {}
+ # See Rudy::Routines.add_routine
+ @@routine = {}
- # A Hash of routine keywords pointing to a specifc helper.
- # See Rudy::Routines.add_helper
- @@helper = {}
+ # A Hash of routine keywords pointing to a specifc handler.
+ # See Rudy::Routines.add_routine
+ @@handler = {}
class NoRoutine < Rudy::Error
def message; "Unknown routine '#{@obj}'"; end
@@ -50,45 +51,45 @@ def initialize(klass, actions)
def message; "#{@klass} does not support: #{@actions.join(', ')}"; end
end
- # Add a routine handler to @@handler.
+ # 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+.
- def self.add_handler(routine_name, klass)
- add_some_class @@handler, Rudy::Routines::Base, routine_name, klass
+ def self.add_routine(name, klass)
+ add_some_class @@routine, Rudy::Routines::Base, name, klass
end
- # Returns the value in the @@handler associated to the key +routine_name+
+ # Returns the value in the @@routine associated to the key +routine_name+
# if it exists, otherwise it returns Rudy::Routines::Passthrough
- def self.get_handler(routine_name)
- get_some_class(@@handler, routine_name) || Rudy::Routines::Passthrough
+ def self.get_routine(name)
+ get_some_class(@@routine, name) || Rudy::Routines::Passthrough
end
- # Add a routine helper to @@helper.
- def self.add_helper(action_name, klass)
- add_some_class @@helper, Rudy::Routines::HelperBase, action_name, klass
+ # Add a routine handler to @@handler.
+ def self.add_handler(name, klass)
+ add_some_class @@handler, Rudy::Routines::Handlers::Base, name, klass
end
- # Returns the value in the @@helper associated to the key +name+
+ # Returns the value in the @@handler associated to the key +name+
# if it exists, otherwise it returns nil
- def self.get_helper(action_name)
- get_some_class(@@helper, action_name) || nil
+ def self.get_handler(name)
+ get_some_class(@@handler, name) || nil
end
- def self.has_handler?(name); @@handler.has_key?(name); end
- def self.has_helper?(name); @@helper.has_key?(name); end
+ def self.has_routine?(name); @@routine.has_key?(name); end
+ def self.has_handler?(name); @@handler.has_key?(name); end
# Executes a routine block
def self.runner(routine, rset, lbox, argv=nil)
- routine.each_pair do |action,definition|
- helper = Rudy::Routines.get_helper action
- Rudy::Huxtable.ld " executing helper: #{action}"
+ routine.each_pair do |name,definition|
+ handler = Rudy::Routines.get_handler name
+ Rudy::Huxtable.ld " executing handler: #{name}"
Rudy::Routines.rescue {
- helper.execute(action, definition, rset, lbox, argv)
+ handler.execute(name, definition, rset, lbox, argv)
}
end
end
@@ -120,7 +121,7 @@ def self.machine_separator(name, awsid)
private
- # See Rudy::Routines.add_handler
+ # See Rudy::Routines.add_routine
def self.add_some_class(store, super_klass, name, klass)
if store.has_key? name
Rudy::Huxtable.li "Redefining class for #{name}"
@@ -131,7 +132,7 @@ def self.add_some_class(store, super_klass, name, klass)
store[name] = klass
end
- # See Rudy::Routines.get_handler
+ # See Rudy::Routines.get_routine
def self.get_some_class(store, routine_name)
routine_name &&= routine_name.to_sym
store[routine_name]
@@ -141,5 +142,5 @@ def self.get_some_class(store, routine_name)
end
Rudy::Utils.require_glob(RUDY_LIB, 'rudy', 'routines', '*.rb')
-Rudy::Utils.require_glob(RUDY_LIB, 'rudy', 'routines', 'helpers', '*.rb')
+Rudy::Utils.require_glob(RUDY_LIB, 'rudy', 'routines', 'handlers', '*.rb')
@@ -46,14 +46,15 @@ def initialize(name=nil, option={}, argv=[], *args)
# e.g. startup, sysupdate, installdeps
@routine = fetch_routine_config @name
+ ld "Routine: #{@routine.inspect}"
+
if @routine
- # This gets and removes the dependencies from the routines hash.
- # We grab the after ones now too, so they can also be removed.
+ # Removes the dependencies from the routines hash.
+ # We run these separately from the other actions.
@before, @after = @routine.delete(:before), @routine.delete(:after)
end
- ld "Routine: #{@routine.inspect}"
-
+ # Share one Rye::Box instance for localhost across all routines
@@lbox = create_rye_box @@global.localhost unless defined?(@@lbox)
disable_run if @@global.testrun
@@ -0,0 +1,48 @@
+
+
+module Rudy; module Routines; module Handlers;
+ module Base
+ include Rudy::Huxtable
+
+ def trap_rbox_errors(ret=nil, &command)
+ begin
+ ret = command.call if command
+ return unless ret.is_a?(Rye::Rap)
+ puts ' ' << ret.stdout.join("#{$/} ") if !ret.stdout.empty?
+ print_response(ret)
+ rescue IOError => ex
+ STDERR.puts " Connection Error (#{ex.message})".color(:red)
+ choice = Annoy.get_user_input('(S)kip (A)bort: ') || ''
+ if choice.match(/\AS/i)
+ return
+ #elsif choice.match(/\AR/i)
+ # retry
+ else
+ exit 12
+ end
+ end
+
+ ret
+ end
+
+ def keep_going?
+ Annoy.pose_question(" Keep going?\a ", /yes|y|ya|sure|you bet!/i, STDERR)
+ end
+
+
+ private
+ def print_response(rap)
+ colour = rap.exit_code != 0 ? :red : :normal
+ [:stderr].each do |sumpin|
+ next if rap.send(sumpin).empty?
+ STDERR.puts
+ STDERR.puts((" #{sumpin.to_s.upcase} " << '-'*38).color(colour).bright)
+ STDERR.puts " " << rap.send(sumpin).join("#{$/} ").color(colour)
+ end
+ STDERR.puts " Exit code: #{rap.exit_code}".color(colour) if rap.exit_code != 0
+ end
+
+ end
+
+end; end; end
+
@@ -1,13 +1,13 @@
-module Rudy; module Routines;
- module DependsHelper
- include Rudy::Routines::HelperBase # TODO: use trap_rbox_errors
+module Rudy; module Routines; module Handlers;
+ module Depends
+ include Rudy::Routines::Handlers::Base
extend self
- ## NOTE: Dependencies don't use Rudy::Routines.add_helper but we
+ ## NOTE: Dependencies don't use Rudy::Routines.add_handler but we
## define them ehere anyway so raise_early_exceptions passes.
- Rudy::Routines.add_helper :before, self
- Rudy::Routines.add_helper :after, self
+ Rudy::Routines.add_handler :before, self
+ Rudy::Routines.add_handler :after, self
def raise_early_exceptions(type, depends, rset, lbox, argv=nil)
unless depends.kind_of? Array
@@ -44,4 +44,4 @@ def execute_all(depends)
end
-end; end
+end; end; end
@@ -1,11 +1,10 @@
-
-module Rudy; module Routines;
- module DiskHelper
- include Rudy::Routines::HelperBase # TODO: use trap_rbox_errors
+module Rudy; module Routines; module Handlers;
+ module Disks
+ include Rudy::Routines::Handlers::Base
extend self
- Rudy::Routines.add_helper :disks, self
+ Rudy::Routines.add_handler :disks, self
def raise_early_exceptions(type, batch, rset, lbox, argv=nil)
@@ -396,4 +395,4 @@ def destroy(disks)
end
end
-end;end
+end; end; end
@@ -1,10 +1,10 @@
-module Rudy; module Routines;
- module HostHelper
- include Rudy::Routines::HelperBase # TODO: use trap_rbox_errors
+module Rudy; module Routines; module Handlers;
+ module Host
+ include Rudy::Routines::Handlers::Base
extend self
- ## NOTE: This helper doesn't use Rudy::Routines.add_helper
+ ## NOTE: This handler doesn't use Rudy::Routines.add_handler
def is_running?(rset)
raise NoMachines if rset.boxes.empty?
@@ -65,4 +65,4 @@ def set_hostname(rset)
end
end
-end; end
+end; end; end
@@ -0,0 +1,11 @@
+
+module Rudy; module Routines; module Handlers;
+ module Disks
+ include Rudy::Routines::Handlers::Base
+ extend self
+
+ Rudy::Routines.add_handler :machines, self
+
+
+ end
+end; end; end
@@ -1,18 +1,15 @@
-require 'tempfile'
-module Rudy; module Routines;
- #--
- # TODO: Rename to ShellHelper
- #++
- module ScriptHelper
- include Rudy::Routines::HelperBase
+
+module Rudy; module Routines; module Handlers;
+ module Script
+ include Rudy::Routines::Handlers::Base
extend self
- Rudy::Routines.add_helper :local, self
- Rudy::Routines.add_helper :remote, self
+ Rudy::Routines.add_handler :local, self
+ Rudy::Routines.add_handler :remote, self
- Rudy::Routines.add_helper :xlocal, self
- Rudy::Routines.add_helper :xremote, self
+ Rudy::Routines.add_handler :xlocal, self
+ Rudy::Routines.add_handler :xremote, self
def raise_early_exceptions(type, batch, rset, lbox, argv=nil)
@@ -85,4 +82,4 @@ def execute_command(batch, robj, argv=nil)
end
end
-end;end
+end;end;end
@@ -1,11 +1,11 @@
-module Rudy; module Routines;
- module UserHelper
- include Rudy::Routines::HelperBase # TODO: use trap_rbox_errors
+module Rudy; module Routines; module Handlers;
+ module User
+ include Rudy::Routines::Handlers::Base
extend self
- Rudy::Routines.add_helper :adduser, self
- Rudy::Routines.add_helper :authorize, self
+ Rudy::Routines.add_handler :adduser, self
+ Rudy::Routines.add_handler :authorize, self
def raise_early_exceptions(type, user, rset, lbox, argv=nil)
@@ -38,4 +38,4 @@ def authorize(user, robj)
end
-end; end
+end; end; end
Oops, something went wrong.

0 comments on commit 7fea0e7

Please sign in to comment.