Module: CORL::Mixin::Machine::SSH
- Included in:
- CORL::Machine::Fog, CORL::Machine::Vagrant
- Defined in:
- lib/core/mixin/machine/ssh.rb
Instance Method Summary collapse
-
#close_ssh_session ⇒ Object
—.
-
#init_ssh_session(reset = false, tries = 5, sleep_secs = 5) ⇒ Object
—————————————————————————– SSH Operations.
-
#ssh_download(remote_path, local_path, options = {}, &code) ⇒ Object
—.
-
#ssh_exec(commands, options = {}, &code) ⇒ Object
—.
-
#ssh_terminal(user, options = {}) ⇒ Object
—.
-
#ssh_upload(local_path, remote_path, options = {}, &code) ⇒ Object
—.
-
#ssh_wait_for_ready ⇒ Object
—————————————————————————– Utilities.
Instance Method Details
#close_ssh_session ⇒ Object
99 100 101 |
# File 'lib/core/mixin/machine/ssh.rb', line 99 def close_ssh_session Util::SSH.close_session(node.public_ip, node.user) end |
#init_ssh_session(reset = false, tries = 5, sleep_secs = 5) ⇒ Object
SSH Operations
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/core/mixin/machine/ssh.rb', line 9 def init_ssh_session(reset = false, tries = 5, sleep_secs = 5) ssh_wait_for_ready success = true begin Util::SSH.session(node.public_ip, node.user, node.ssh_port, node.private_key, reset) rescue Net::SSH::HostKeyMismatch => error error.remember_host! sleep 0.2 reset = true retry rescue Errno::ECONNREFUSED, Net::SSH::ConnectionTimeout, Net::SSH::Disconnect => error if tries > 1 sleep(sleep_secs) tries -= 1 reset = true retry else success = false end rescue => error ui.warn(error) success = false end success end |
#ssh_download(remote_path, local_path, options = {}, &code) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/core/mixin/machine/ssh.rb', line 43 def ssh_download(remote_path, local_path, = {}, &code) config = Config.ensure() success = false begin if init_ssh_session Util::SSH.download(node.public_ip, node.user, remote_path, local_path, config.export) do |name, received, total| code.call(name, received, total) if code end success = true end rescue => error ui.error(error.) end success end |
#ssh_exec(commands, options = {}, &code) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/core/mixin/machine/ssh.rb', line 83 def ssh_exec(commands, = {}, &code) config = Config.ensure() results = nil if commands if init_ssh_session results = Util::SSH.exec(node.public_ip, node.user, commands) do |type, command, data| code.call(type, command, data) if code end end end results end |
#ssh_terminal(user, options = {}) ⇒ Object
105 106 107 |
# File 'lib/core/mixin/machine/ssh.rb', line 105 def ssh_terminal(user, = {}) Util::SSH.terminal(node.public_ip, user, Config.ensure().export) end |
#ssh_upload(local_path, remote_path, options = {}, &code) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/core/mixin/machine/ssh.rb', line 63 def ssh_upload(local_path, remote_path, = {}, &code) config = Config.ensure() success = false begin if init_ssh_session Util::SSH.upload(node.public_ip, node.user, local_path, remote_path, config.export) do |name, sent, total| code.call(name, sent, total) if code end success = true end rescue => error ui.error(error.) end success end |
#ssh_wait_for_ready ⇒ Object
Utilities
112 113 114 |
# File 'lib/core/mixin/machine/ssh.rb', line 112 def ssh_wait_for_ready # Override in class if needed (see Fog Machine provider) end |