Class: Flucti::Resources::SshDetails::AccountBinding

Inherits:
Struct
  • Object
show all
Defined in:
lib/flucti/resources/ssh_details.rb

Instance Method Summary collapse

Instance Method Details

#connectObject



21
22
23
24
25
26
27
# File 'lib/flucti/resources/ssh_details.rb', line 21

def connect
  check_for_presence_of_ssh do
    command = connection_command
    $stderr.puts "Connecting to VPS with: `#{command}'"
    exec(command)
  end
end

#connection_commandObject



17
18
19
# File 'lib/flucti/resources/ssh_details.rb', line 17

def connection_command
  "ssh -p #{port} #{}@#{host}"
end

#execute(command) ⇒ Object Also known as: run



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/flucti/resources/ssh_details.rb', line 33

def execute(command)
  check_for_presence_of_ssh do
    command = execute_command(command)
    $stderr.puts "Executing: #{command}"

    # For some reason, `exec' won't work, it throws the following error:
    # `Operation not supported' (Errno::E045).  `system' causes this too
    # sometimes, but so much less often that it's bearable.
    system(command)
  end
end

#execute_command(command) ⇒ Object



29
30
31
# File 'lib/flucti/resources/ssh_details.rb', line 29

def execute_command(command)
  %(#{connection_command} 'echo "#{command.gsub /"/, '\"'}" | bash -l -s')
end

#upload(*files) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/flucti/resources/ssh_details.rb', line 46

def upload(*files)
  check_for_presence_of_scp do
    command = %(scp -P #{port} #{files * ' '} #{}@#{host}:~)
    $stderr.puts "Executing: #{command}"
    system(command)
  end
end