lib/cloud_providers/connections.rb
def ssh( commands=[], extra_ssh_ops={})
      # commands can be single commands, as well as array
      commands = [commands] unless commands.respond_to? :each

      # Get the environment hash out of
      # the extra_ssh_ops and then delete
      # the element
      ssh_error_msg="SSH is not available for this node. perhaps you need to authorize it?"
      raise PoolParty::PoolPartyError.create("SSHError", ssh_error_msg) unless ssh_available?
      env = extra_ssh_ops[:env] || {}
      extra_ssh_ops.delete :env

      # Decide to use sudo or not
      do_sudo = user!="root"

      if extra_ssh_ops.has_key? :do_sudo
        do_sudo = extra_ssh_ops[:do_sudo] 
        extra_ssh_ops.delete :do_sudo
      end

      envstring = env.collect {|k,v| "#{k}=#{v}"}.join ' && '
      envstring += " && " unless envstring.size == 0
      ssh_string = "ssh #{user}@#{host} #{ssh_options(extra_ssh_ops)}"

      if commands.empty?
        #TODO: replace this with a IO.popen call with read_nonblocking to show progress, and accept input
        Kernel.system(ssh_string)
      else
        r = nil
        commands.each do |command|

          cmd = "#{envstring}#{command}" 
          if do_sudo
            sudocmd = %Q% sudo sh -c "#{shell_escape cmd}" % 
          else
            sudocmd = cmd
          end

          r = system_run ssh_string + %Q% "#{shell_escape sudocmd}"% 
        end
        r
      end
    end
# hostname or ip to use when running remote commands
hostname or ip to use when running remote commands
hostname or ip to use when running remote commands
def ssh( commands=[], extra_ssh_ops={})
      commands = [commands] unless commands.respond_to? :each
      ssh_error_msg="SSH is not available for this node. perhaps you need to authorize it?"
      raise PoolParty::PoolPartyError.create("SSHError", ssh_error_msg) unless ssh_available?
      env = extra_ssh_ops[:env] || {}
      extra_ssh_ops.delete :env
      do_sudo = user!="root"
      if extra_ssh_ops.has_key? :do_sudo
        do_sudo = extra_ssh_ops[:do_sudo] 
        extra_ssh_ops.delete :do_sudo
      end
      envstring = env.collect {|k,v| "#{k}=#{v}"}.join ' && '
      envstring += " && " unless envstring.size == 0
      ssh_string = "ssh #{user}@#{host} #{ssh_options(extra_ssh_ops)}"
      if commands.empty?
        Kernel.system(ssh_string)
      else
        r = nil
        commands.each do |command|
          cmd = "#{envstring}#{command}" 
          if do_sudo
            sudocmd = %Q% sudo sh -c "#{shell_escape cmd}" % 
          else
            sudocmd = cmd
          end
          r = system_run ssh_string + %Q% "#{shell_escape sudocmd}"% 
        end
        r
      end
    end
def ssh ( commands = [ ] , extra_ssh_ops = { } ) commands = [ commands ] unless commands . respond_to? :each ssh_error_msg = "SSH is not available for this node. perhaps you need to authorize it?" raise PoolParty :: PoolPartyError . create ( "SSHError" , ssh_error_msg ) unless ssh_available? env = extra_ssh_ops [ :env ] || { } extra_ssh_ops . delete :env do_sudo = user != "root" if extra_ssh_ops . has_key? :do_sudo do_sudo = extra_ssh_ops [ :do_sudo ] extra_ssh_ops . delete :do_sudo end envstring = env . collect { | k , v | "#{k}=#{v}" } . join ' && ' envstring += " && " unless envstring . size == 0 ssh_string = "ssh #{user}@#{host} #{ssh_options(extra_ssh_ops)}" if commands . empty? Kernel . system ( ssh_string ) else r = nil commands . each do | command | cmd = "#{envstring}#{command}" if do_sudo sudocmd = %Q% sudo sh -c "#{shell_escape cmd}" % else sudocmd = cmd end r = system_run ssh_string + %Q% "#{shell_escape sudocmd}"% end r end end
hostname or ip to use when running remote commands
hostname or ip to use when running remote commands
# commands can be single commands, as well as array # Get the environment hash out of # the extra_ssh_ops and then delete # the element # Decide to use sudo or not #TODO: replace this with a IO.popen call with read_nonblocking to show progress, and accept input
commands
extra_ssh_ops