Class: Train::Transports::SSH
- Inherits:
-
Object
- Object
- Train::Transports::SSH
- Defined in:
- lib/train/transports/ssh.rb,
lib/train/transports/ssh_connection.rb,
lib/train/transports/cisco_ios_connection.rb
Overview
A Transport which uses the SSH protocol to execute commands and transfer files.
Defined Under Namespace
Classes: CiscoIOSConnection, Connection
Class Method Summary collapse
-
.read_options_from_ssh_config(options, option_type) ⇒ Object
Returns the ssh config option like user, port from config files Params options [Hash], option_type [String] Return String.
Instance Method Summary collapse
Class Method Details
.read_options_from_ssh_config(options, option_type) ⇒ Object
Returns the ssh config option like user, port from config files Params options [Hash], option_type [String] Return String
93 94 95 96 97 |
# File 'lib/train/transports/ssh.rb', line 93 def self.(, option_type) files = [:ssh_config_file].nil? || [:ssh_config_file] == true ? Net::SSH::Config.default_files : [:ssh_config_file] = Net::SSH::Config.for([:host], files) [option_type] end |
Instance Method Details
#apply_ssh_config_file(host) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/train/transports/ssh.rb', line 99 def apply_ssh_config_file(host) files = [:ssh_config_file] == true ? Net::SSH::Config.default_files : [:ssh_config_file] host_cfg = ssh_config_file_for_host(host, files) host_cfg.each do |key, value| # setting the key_files option to the private keys set in ssh config file if key == :keys && [:key_files].nil? && !host_cfg[:keys].nil? && [:password].nil? [:key_files] = host_cfg[key] elsif [key].nil? # Precedence is given to the option set by the user manually. # And only assigning value to the option from the ssh config file when it is not set by the user # in the option. When the option has a default value for e.g. option "keepalive_interval" has the "60" as the default # value, then the default value will be used even though the value for "user" is present in the ssh # config file. That is because the precedence is to the options set manually, and currently we don't have # any way to differentiate between the value set by the user or is it the default. This has a future of improvement. [key] = host_cfg[key] end end end |
#connection(state = {}, &block) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/train/transports/ssh.rb', line 77 def connection(state = {}, &block) apply_ssh_config_file([:host]) opts = (, state || {}) (opts) conn_opts = (opts) if defined?(@connection) && reusable_connection?(conn_opts) reuse_connection(&block) else create_new_connection(conn_opts, &block) end end |