Added default user & error handling

This commit is contained in:
Tristan Ancelet 2024-06-28 20:13:45 -05:00
parent 73797ce2d7
commit 994f8a906b

View File

@ -5,7 +5,7 @@ module RubyQA
:hostname => "", :hostname => "",
:ip => "", :ip => "",
:port => 22, :port => 22,
:user => "", :user => ENV["USER"],
:password => "", :password => "",
:site => "", :site => "",
:cluster => false, :cluster => false,
@ -28,9 +28,18 @@ module RubyQA
end end
def init_client def init_client
begin
if @data[:password]
@client = Net::SSH.start(@data[:ip], @data[:user], password: @data[:password])
else
@client = Net::SSH.start(@data[:ip], @data[:user]) @client = Net::SSH.start(@data[:ip], @data[:user])
end end
rescue SocketError
raise "Failed to make ssh client for #{@data[:hostname]}"
end
end
def exec (command) def exec (command)
@client.exec!(command) @client.exec!(command)
end end