Class: EasyManager::SSH
- Inherits:
-
Object
- Object
- EasyManager::SSH
- Defined in:
- lib/easymanager/ssh.rb
Overview
SSH Class
Instance Attribute Summary collapse
-
#ssh_key ⇒ Object
readonly
Returns the value of attribute ssh_key.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ SSH
constructor
A new instance of SSH.
Constructor Details
#initialize(options = {}) ⇒ SSH
Returns a new instance of SSH.
11 12 13 14 |
# File 'lib/easymanager/ssh.rb', line 11 def initialize( = {}) @username = [:username] || 'root' @ssh_key = [:ssh_key] || '/root/.ssh/id_rsa' end |
Instance Attribute Details
#ssh_key ⇒ Object (readonly)
Returns the value of attribute ssh_key.
9 10 11 |
# File 'lib/easymanager/ssh.rb', line 9 def ssh_key @ssh_key end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
9 10 11 |
# File 'lib/easymanager/ssh.rb', line 9 def username @username end |
Class Method Details
.cmd_exec(ssh, srv, cmds) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/easymanager/ssh.rb', line 16 def self.cmd_exec(ssh, srv, cmds) cmd_values = {} Net::SSH.start(srv['public_ip']['address'], ssh.username, keys: ssh.ssh_key) do |shell| cmds.each do |cmd| cmd_values[cmd] = shell.exec!(cmd).chomp end end cmd_values rescue Net::SSH::AuthenticationFailed nil end |
.scp(ssh, srv, files) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/easymanager/ssh.rb', line 30 def self.scp(ssh, srv, files) Net::SCP.start(srv['public_ip']['address'], ssh.username, keys: ssh.ssh_key) do |shell| files.each do |name, infos| shell.upload! name, infos[:remote], recursive: infos[:recursive] || false end end rescue Net::SSH::AuthenticationFailed nil end |