lib/ztk/ssh.rb in ztk-0.0.7 vs lib/ztk/ssh.rb in ztk-0.0.8

- old
+ new

@@ -1,8 +1,8 @@ ################################################################################ # -# Author: Zachary Patten <zachary@jovelabs.com> +# Author: Zachary Patten <zachary@jovelabs.net> # Copyright: Copyright (c) Jove Labs # License: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,56 +25,66 @@ module ZTK # ZTK::SSH error class # - # @author Zachary Patten <zachary@jovelabs.com> + # @author Zachary Patten <zachary@jovelabs.net> class SSHError < Error; end + # SSH Multi-function Class + # # We can get a new instance of SSH like so: + # # ssh = ZTK::SSH.new # # If we wanted to redirect STDOUT and STDERR to a StringIO we can do this: + # # std_combo = StringIO.new # ssh = ZTK::SSH.new(:stdout => std_combo, :stderr => std_combo) # # If you want to specify SSH options you can: + # # keys = File.expand_path(File.join(ENV['HOME'], '.ssh', 'id_rsa')) # ssh = ZTK::SSH.new(:host_name => '127.0.0.1', :user => ENV['USER'], :keys => keys) # # = Configuration Examples: # # To proxy through another host, for example SSH to 192.168.1.1 through 192.168.0.1: + # # ssh.config do |config| # config.user = ENV['USER'] # config.host_name = '192.168.1.1' # config.proxy_user = ENV['USER'] # config.proxy_host_name = '192.168.0.1' # end # # Specify an identity file: + # # ssh.config do |config| # config.keys = File.expand_path(File.join(ENV['HOME'], '.ssh', 'id_rsa')) # config.proxy_keys = File.expand_path(File.join(ENV['HOME'], '.ssh', 'id_rsa')) # end # # Specify a timeout: + # # ssh.config do |config| # config.timeout = 30 # end # # Specify a password: + # # ssh.config do |config| # config.password = 'p@$$w0rd' # end # # Check host keys, the default is false (off): + # # ssh.config do |config| # config.host_key_verify = true # end # - # @author Zachary Patten <zachary@jovelabs.com> + # @author Zachary Patten <zachary@jovelabs.net> class SSH < ZTK::Base # @param [Hash] config Configuration options hash. # @option config [String] :host_name Server hostname to connect to. # @option config [String] :user Username to use for authentication. @@ -129,16 +139,16 @@ # @return [OpenStruct#output] The output of the command, both STDOUT and # STDERR. # @return [OpenStruct#exit] The exit status (i.e. $?). # # @example Execute a command: - # $logger = ZTK::Logger.new(STDOUT) + # # ssh = ZTK::SSH.new # ssh.config do |config| # config.user = ENV["USER"] # config.host_name = "127.0.0.1" # end - # puts ssh.exec("hostname -f").output + # puts ssh.exec("hostname -f").inspect def exec(command, options={}) log(:debug) { "exec(#{command.inspect}, #{options.inspect})" } log(:debug) { "config(#{@config.inspect})" } @ssh ||= Net::SSH.start(@config.host_name, @config.user, ssh_options)