lib/testlab/node/ssh.rb in testlab-1.21.1 vs lib/testlab/node/ssh.rb in testlab-1.22.0
- old
+ new
@@ -1,11 +1,13 @@
class TestLab
class Node
module SSH
- # SSH to the Node
+ # Node SSH Connection
+ #
+ # @return [ZTK::SSH] Returns a new or cached ZTK::SSH object for the node.
def ssh(options={})
if (!defined?(@ssh) || @ssh.nil?)
@ssh ||= ZTK::SSH.new({:ui => @ui, :timeout => 3600, :silence => true}.merge(options))
@ssh.config do |c|
c.host_name = @provider.ip
@@ -15,11 +17,14 @@
end
end
@ssh
end
- # SSH to a container running on the Node
+ # Container SSH Connection
+ #
+ # @return [ZTK::SSH] Returns a new or cached ZTK::SSH object for the
+ # container.
def container_ssh(container, options={})
name = container.id
@container_ssh ||= Hash.new
if @container_ssh[name].nil?
@container_ssh[name] ||= ZTK::SSH.new({:ui => @ui, :timeout => 3600, :silence => true}.merge(options))
@@ -35,9 +40,24 @@
c.password = (options[:passwd] || container.primary_user.password)
c.keys = (options[:keys] || [container.primary_user.identity, @provider.identity].flatten.compact)
end
end
@container_ssh[name]
+ end
+
+ # Shutdown all SSH connections
+ #
+ # @return [Boolean] True if successful.
+ def ssh_shutdown!
+ @ssh.nil? or @ssh.close
+ @ssh = nil
+
+ @container_ssh.nil? or @container_ssh.each do |name, ssh|
+ ssh.nil? or ssh.close
+ end
+ @container_ssh = nil
+
+ true
end
end
end