Module: Spectre::SSH
- Defined in:
- lib/spectre/ssh.rb
Defined Under Namespace
Classes: SSHConnection, SSHError
Constant Summary collapse
- @@cfg =
{}
Class Method Summary collapse
Class Method Details
.ssh(name, options = {}, &block) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/spectre/ssh.rb', line 138 def ssh name, = {}, &block cfg = @@cfg[name] || {} host = cfg['host'] || name username = [:username] || cfg['username'] password = [:password] || cfg['password'] opts = {} opts[:password] = password opts[:port] = [:port] || cfg['port'] || 22 ssh_key = [:key] || cfg['key'] opts[:keys] = [ssh_key] unless ssh_key.nil? opts[:passphrase] = [:passphrase] || cfg['passphrase'] opts[:auth_methods] = [] opts[:auth_methods].push 'publickey' unless opts[:keys].nil? or opts[:keys].empty? opts[:auth_methods].push 'password' unless opts[:password].nil? proxy_host = [:proxy_host] || cfg['proxy_host'] proxy_port = [:proxy_port] || cfg['proxy_port'] opts[:proxy] = Net::SSH::Proxy::HTTP.new(proxy_host, proxy_port) unless proxy_host.nil? if @@debug opts[:logger] = @@logger.logger opts[:verbose] = Logger::DEBUG end ssh_con = SSHConnection.new(host, username, opts, @@logger) begin ssh_con.instance_eval &block ensure ssh_con.close end end |