Class: Vos::Drivers::Ssh
- Includes:
- SshVfsStorage
- Defined in:
- lib/vos/drivers/ssh.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ config: true }
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
- #bash(command) ⇒ Object
- #close ⇒ Object
-
#exec(command) ⇒ Object
Shell.
- #host ⇒ Object
-
#initialize(options = {}) ⇒ Ssh
constructor
A new instance of Ssh.
-
#open(&block) ⇒ Object
(also: #open_fs)
Establishing SSH channel.
-
#to_s ⇒ Object
Miscellaneous.
Methods included from SshVfsStorage
#attributes, #create_dir, #delete_dir, #delete_file, #each_entry, #local?, #read_file, #set_attributes, #tmp, #write_file
Constructor Details
#initialize(options = {}) ⇒ Ssh
Returns a new instance of Ssh.
11 12 13 14 15 16 17 18 19 |
# File 'lib/vos/drivers/ssh.rb', line 11 def initialize = {} super raise ":host not provided!" unless [:host] @options = DEFAULT_OPTIONS.merge # config_options = Net::SSH.configuration_for(options[:host]) # options = DEFAULT_OPTIONS.merge(config_options).merge options # raise ":user not provided (provide explicitly or in .ssh/config)!" unless options[:user] end |
Instance Method Details
#bash(command) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/vos/drivers/ssh.rb', line 77 def bash command # somehow net-ssh doesn't executes ~/.profile, so we need to execute it manually # command = ". ~/.profile && #{command}" stdout_and_stderr, stderr, code, signal = hacked_exec! ssh, command, true return code, stdout_and_stderr end |
#close ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/vos/drivers/ssh.rb', line 49 def close if @ssh @ssh.close # @sftp.close not needed @ssh, @sftp = nil end end |
#exec(command) ⇒ Object
Shell
68 69 70 71 72 73 74 75 |
# File 'lib/vos/drivers/ssh.rb', line 68 def exec command # somehow net-ssh doesn't executes ~/.profile, so we need to execute it manually # command = ". ~/.profile && #{command}" stdout, stderr, code, signal = hacked_exec! ssh, command return code, stdout, stderr end |
#host ⇒ Object
90 |
# File 'lib/vos/drivers/ssh.rb', line 90 def host; [:host] end |
#open(&block) ⇒ Object Also known as: open_fs
Establishing SSH channel
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vos/drivers/ssh.rb', line 25 def open &block if block if @ssh block.call self else begin open block.call self ensure close end end else unless @ssh opt = self..clone host = opt.delete :host #] || raise('host not provided!') # user = options.delete(:user) || raise('user not provied!') @ssh = Net::SSH.start(host, nil, opt) @sftp = @ssh.sftp.connect end end end |
#to_s ⇒ Object
Miscellaneous
89 |
# File 'lib/vos/drivers/ssh.rb', line 89 def to_s; [:host] end |