class Producer::Core::Remote
Attributes
hostname[R]
session[W]
Public Class Methods
new(hostname)
click to toggle source
# File lib/producer/core/remote.rb, line 7 def initialize hostname @hostname = hostname end
Public Instance Methods
cleanup()
click to toggle source
# File lib/producer/core/remote.rb, line 54 def cleanup session.close if @session end
config()
click to toggle source
# File lib/producer/core/remote.rb, line 18 def config @config ||= Net::SSH::Config.for(@hostname) end
environment()
click to toggle source
# File lib/producer/core/remote.rb, line 50 def environment Environment.string_to_hash(execute 'env') end
execute(command, output = '', error_output = '')
click to toggle source
# File lib/producer/core/remote.rb, line 30 def execute command, output = '', error_output = '' session.open_channel do |channel| channel.exec command do |ch, _success| ch.on_data do |_c, data| output << data end ch.on_extended_data do |_c, _type, data| error_output << data end ch.on_request 'exit-status' do |_c, data| exit_status = data.read_long fail RemoteCommandExecutionError, command if exit_status != 0 end end end.wait output end
fs()
click to toggle source
# File lib/producer/core/remote.rb, line 26 def fs @fs ||= Remote::FS.new(session.sftp.connect) end
session()
click to toggle source
# File lib/producer/core/remote.rb, line 11 def session @session ||= begin check_hostname! Net::SSH.start(@hostname, user_name) end end
user_name()
click to toggle source
# File lib/producer/core/remote.rb, line 22 def user_name config[:user] || Etc.getlogin end
Private Instance Methods
check_hostname!()
click to toggle source
# File lib/producer/core/remote.rb, line 60 def check_hostname! return if @hostname fail RemoteInvalidError, "remote target is invalid: `#{@hostname.inspect}'" end