module ZTK::SSH::Core
Public Instance Methods
close()
click to toggle source
Close our session gracefully.
# File lib/ztk/ssh/core.rb, line 88 def close config.ui.logger.debug { "close" } close_ssh close_gateway true ensure @ssh = nil @gateway = nil @sftp = nil @scp = nil end
close_gateway()
click to toggle source
Attempts to close the gateway session if it is valid.
# File lib/ztk/ssh/core.rb, line 69 def close_gateway if (!@gateway.nil?) config.ui.logger.debug { "gateway object is valid" } begin config.ui.logger.debug { "attempting to shutdown" } @gateway.shutdown! config.ui.logger.debug { "shutdown" } rescue Exception => e config.ui.logger.fatal { "EXCEPTION: #{e.inspect}" } end else config.ui.logger.debug { "gateway object is NIL!" } end end
close_ssh()
click to toggle source
Attempts to close the SSH
session if it is valid.
# File lib/ztk/ssh/core.rb, line 50 def close_ssh if (!@ssh.nil? && !@ssh.closed?) config.ui.logger.debug { "SSH object is valid and not closed" } begin config.ui.logger.debug { "attempting to close" } @ssh.close config.ui.logger.debug { "closed" } rescue Exception => e config.ui.logger.fatal { "EXCEPTION: #{e.inspect}" } end else config.ui.logger.debug { "SSH object is NIL!" } end end
do_proxy?()
click to toggle source
Should we run a proxy?
# File lib/ztk/ssh/core.rb, line 45 def do_proxy? ((!config.proxy_host_name.nil? && !config.proxy_host_name.empty?) && (!config.proxy_user.nil? && !config.proxy_user.empty?)) end
gateway()
click to toggle source
Starts an SSH
gateway session. Can also be used to get the Net::SSH::Gateway object.
Primarily used internally.
# File lib/ztk/ssh/core.rb, line 39 def gateway @gateway ||= Net::SSH::Gateway.new(config.proxy_host_name, config.proxy_user, gateway_options) @gateway end
on_retry(exception)
click to toggle source
The on_retry
method we'll use with the RescueRetry
class.
# File lib/ztk/ssh/core.rb, line 104 def on_retry(exception) config.ui.logger.warn { "ZTK::SSH on_retry triggered!" } (close rescue false) end
scp()
click to toggle source
Starts an SCP session. Can also be used to get the Net::SCP object.
Primarily used internally.
# File lib/ztk/ssh/core.rb, line 30 def scp @scp ||= self.ssh.scp @scp end
sftp()
click to toggle source
Starts an SFTP session. Can also be used to get the Net::SFTP object.
Primarily used internally.
# File lib/ztk/ssh/core.rb, line 22 def sftp @sftp ||= self.ssh.sftp @sftp end
ssh()
click to toggle source
Starts an SSH
session. Can also be used to get the Net::SSH object.
Primarily used internally.
# File lib/ztk/ssh/core.rb, line 10 def ssh if do_proxy? @ssh ||= self.gateway.ssh(config.host_name, config.user, ssh_options) else @ssh ||= Net::SSH.start(config.host_name, config.user, ssh_options) end @ssh end