class Blender::Driver::Scp

Attributes

user[R]

Public Class Methods

new(config = {}) click to toggle source
Calls superclass method Blender::Driver::Base::new
# File lib/blender/drivers/scp.rb, line 28
def initialize(config = {})
  cfg = config.dup
  @user = cfg.delete(:user) || ENV['USER']
  super(cfg)
end

Public Instance Methods

execute(tasks, hosts) click to toggle source
# 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.metadata[:ignore_failure]
        raise ExecutionFailed, cmd.stderr
      end
    end
    session.loop
  end
end
run_command(command, session) click to toggle source
# 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.options)
      ExecOutput.new(0, '', '')
    when :download
      session.scp.download!(command.source, command.target, command.options)
      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.message + e.backtrace.join("\n"))
  end
end

Private Instance Methods

create_session(host) click to toggle source
# File lib/blender/drivers/scp.rb, line 68
def create_session(host)
  Log.debug("Invoking ssh: #{user}@#{host}")
  Net::SSH.start(host, user, config)
end