Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Set :actor key on SSH channel instances. Add Actor.default_io_proc

git-svn-id: http://svn.rubyonrails.org/rails/tools/switchtower@3381 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 1320e07f8ce0bc3d8d87c6adab3d53c3ea0c3aa7 1 parent fb52145
@jamis jamis authored
View
7 CHANGELOG
@@ -1,3 +1,10 @@
+*0.11.0* *SVN*
+
+* Added Actor.default_io_proc
+
+* Set :actor key on SSH channel instances
+
+
*0.10.0* (January 2nd, 2006)
* Handle ssh password prompts like "someone's password:"
View
22 lib/switchtower/actor.rb
@@ -29,12 +29,18 @@ class <<self
attr_accessor :connection_factory
attr_accessor :command_factory
attr_accessor :transfer_factory
+ attr_accessor :default_io_proc
end
self.connection_factory = DefaultConnectionFactory
self.command_factory = Command
self.transfer_factory = Transfer
+ self.default_io_proc = Proc.new do |ch, stream, out|
+ level = out == :error ? :important : :info
+ ch[:actor].logger.send(level, out, "#{stream} :: #{ch[:host]}")
+ end
+
# The configuration instance associated with this actor.
attr_reader :configuration
@@ -105,7 +111,7 @@ def initialize(config) #:nodoc:
# Define a new task for this actor. The block will be invoked when this
# task is called.
def define_task(name, options={}, &block)
- @tasks[name] = Task.new(name, options)
+ @tasks[name] = (options[:task_class] || Task).new(name, options)
define_method(name) do
send "before_#{name}" if respond_to? "before_#{name}"
logger.trace "executing task #{name}"
@@ -129,10 +135,7 @@ def define_task(name, options={}, &block)
#
# If +pretend+ mode is active, this does nothing.
def run(cmd, options={}, &block)
- block ||= Proc.new do |ch, stream, out|
- logger.debug(out, "#{stream} :: #{ch[:host]}")
- end
-
+ block ||= default_io_proc
logger.debug "executing #{cmd.strip.inspect}"
execute_on_servers(options) do |servers|
@@ -176,9 +179,7 @@ def put(data, path, options={})
# the sudo password (if required) is the same as the password for logging
# in to the server.
def sudo(command, options={}, &block)
- block ||= Proc.new do |ch, stream, out|
- logger.debug(out, "#{stream} :: #{ch[:host]}")
- end
+ block ||= default_io_proc
# in order to prevent _each host_ from prompting when the password was
# wrong, let's track which host prompted first and only allow subsequent
@@ -320,6 +321,11 @@ def on_rollback(&block)
task_call_frames.last.rollback = block
end
+ # An instance-level reader for the class' #default_io_proc attribute.
+ def default_io_proc
+ self.class.default_io_proc
+ end
+
private
def metaclass
View
1  lib/switchtower/command.rb
@@ -56,6 +56,7 @@ def open_channels
@servers.map do |server|
@actor.sessions[server].open_channel do |channel|
channel[:host] = server
+ channel[:actor] = @actor # so callbacks can access the actor instance
channel.request_pty :want_reply => true
channel.on_success do |ch|
Please sign in to comment.
Something went wrong with that request. Please try again.