Class: Blender::Driver::Scp
Direct Known Subclasses
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Attributes inherited from Base
#config, #events, #stderr, #stdout
Instance Method Summary collapse
- #execute(tasks, hosts) ⇒ Object
-
#initialize(config = {}) ⇒ Scp
constructor
A new instance of Scp.
- #run_command(command, session) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Scp
Returns a new instance of Scp.
28 29 30 31 32 |
# File 'lib/blender/drivers/scp.rb', line 28 def initialize(config = {}) cfg = config.dup @user = cfg.delete(:user) || ENV['USER'] super(cfg) end |
Instance Attribute Details
#user ⇒ Object (readonly)
Returns the value of attribute user.
26 27 28 |
# File 'lib/blender/drivers/scp.rb', line 26 def user @user end |
Instance Method Details
#execute(tasks, hosts) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/blender/drivers/scp.rb', line 34 def execute(tasks, hosts) Log.debug("SCP execution tasks [#{Array(tasks).size}]") Log.debug("SCP on hosts [#{hosts.join(",")}]") Array(hosts).each do |host| session = create_session(host) Array(tasks).each do |task| cmd = run_command(task.command, session) if cmd.exitstatus != 0 and !task.[:ignore_failure] raise ExecutionFailed, cmd.stderr end end session.loop end end |
#run_command(command, session) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/blender/drivers/scp.rb', line 49 def run_command(command, session) begin case command.direction when :upload session.scp.upload!(command.source, command.target, command.) ExecOutput.new(0, '', '') when :download session.scp.download!(command.source, command.target, command.) ExecOutput.new(0, '', '') else ExecOutput.new(-1, '' , "Invalid direction. Can be either :upload or :download. Found:'#{command.direction}'") end rescue StandardError => e ExecOutput.new(-1, stdout, e. + e.backtrace.join("\n")) end end |