From 5e558bcbf09058d1532db05350c3949333839f16 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Sat, 6 Aug 2005 19:35:25 +0000 Subject: When executing multiline commands, escape newlines with a backslash git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1975 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- switchtower/lib/switchtower/actor.rb | 38 ++++++++++++++++++++-------------- switchtower/lib/switchtower/command.rb | 2 +- 2 files changed, 24 insertions(+), 16 deletions(-) (limited to 'switchtower/lib') diff --git a/switchtower/lib/switchtower/actor.rb b/switchtower/lib/switchtower/actor.rb index cbaf8463e1..db25ca99c2 100644 --- a/switchtower/lib/switchtower/actor.rb +++ b/switchtower/lib/switchtower/actor.rb @@ -12,6 +12,27 @@ module SwitchTower # new actor via Configuration#actor. class Actor + # An adaptor for making the Net::SSH interface look and act like that of the + # Gateway class. + class DefaultConnectionFactory #:nodoc: + def initialize(config) + @config= config + end + + def connect_to(server) + Net::SSH.start(server, :username => @config.user, + :password => @config.password) + end + end + + class < @config.user, - :password => @config.password) - end - end - # Represents the definition of a single task. class Task #:nodoc: attr_reader :name, :options @@ -88,7 +96,7 @@ module SwitchTower @tasks = {} @task_call_frames = [] @sessions = {} - @factory = DefaultConnectionFactory.new(configuration) + @factory = self.class.connection_factory.new(configuration) end # Define a new task for this actor. The block will be invoked when this @@ -134,7 +142,7 @@ module SwitchTower establish_connections(servers) # execute the command on each server in parallel - command = Command.new(servers, cmd, block, options, self) + command = self.class.command_factory.new(servers, cmd, block, options, self) command.process! # raises an exception if command fails on any server end end diff --git a/switchtower/lib/switchtower/command.rb b/switchtower/lib/switchtower/command.rb index 910c97cb45..807958fd76 100644 --- a/switchtower/lib/switchtower/command.rb +++ b/switchtower/lib/switchtower/command.rb @@ -7,7 +7,7 @@ module SwitchTower def initialize(servers, command, callback, options, actor) #:nodoc: @servers = servers - @command = command + @command = command.gsub(/\r?\n/, "\\\n") @callback = callback @options = options @actor = actor -- cgit v1.2.3