Class: App::SSH
- Inherits:
-
Object
- Object
- App::SSH
- Defined in:
- lib/core/ssh.rb
Constant Summary collapse
- SCRIPT_PATH =
'vm-scripts/'
Class Method Summary collapse
-
.run_script_on_remote(config_key, script_name, args = nil, run_as_root = false) ⇒ Object
SCPs a script to a remote host and runs it.
-
.run_script_on_remote_credentials(ssh_user, ssh_host, ssh_cert, script_name, args = nil, run_as_root = false) ⇒ Object
SCPs a script to remote and runs it with pre-supplied credentials.
-
.scp_to_remote(config_key, source, target) ⇒ Object
Source can be a file or directory but whatever it is, target must be the same (a file or directory).
-
.ssh_into_remote(config_key) ⇒ Object
SSH into remote host.
-
.ssh_into_remote_credentials(ssh_user, ssh_host, ssh_cert = nil) ⇒ Object
SSH into remote with pre-supplied credentials.
Class Method Details
.run_script_on_remote(config_key, script_name, args = nil, run_as_root = false) ⇒ Object
SCPs a script to a remote host and runs it.
32 33 34 35 |
# File 'lib/core/ssh.rb', line 32 def self.run_script_on_remote(config_key, script_name, args = nil, run_as_root = false) ssh_user, ssh_host, ssh_cert = get_ssh_credentials(config_key) run_script_on_remote_credentials(ssh_user, ssh_host, ssh_cert, script_name, args, run_as_root) end |
.run_script_on_remote_credentials(ssh_user, ssh_host, ssh_cert, script_name, args = nil, run_as_root = false) ⇒ Object
SCPs a script to remote and runs it with pre-supplied credentials.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/core/ssh.rb', line 39 def self.run_script_on_remote_credentials(ssh_user, ssh_host, ssh_cert, script_name, args = nil, run_as_root = false) script_path_local = "#{App::UtilsTools::get_base_path}/#{App::SSH::SCRIPT_PATH}#{script_name}" script_path_remote = "/tmp/#{script_name}" # Time.now.to_i check_script_exists(script_name) scp_script_to_vm(script_path_local, script_path_remote, ssh_user, ssh_host, ssh_cert) args = args.nil? ? [] : args command("chmod 0755 #{script_path_remote}", ssh_user, ssh_host, ssh_cert) ("#{script_path_remote} #{args.join(' ')}") display_script_content(script_path_local) command("#{script_path_remote} #{args.join(' ')}", ssh_user, ssh_host, ssh_cert, false) command("rm #{script_path_remote}", ssh_user, ssh_host, ssh_cert) end |
.scp_to_remote(config_key, source, target) ⇒ Object
Source can be a file or directory but whatever it is, target must be the same (a file or directory).
26 27 28 |
# File 'lib/core/ssh.rb', line 26 def self.scp_to_remote(config_key, source, target) end |
.ssh_into_remote(config_key) ⇒ Object
SSH into remote host.
9 10 11 12 |
# File 'lib/core/ssh.rb', line 9 def self.ssh_into_remote(config_key) ssh_user, ssh_host, ssh_cert = get_ssh_credentials(config_key) ssh_into_remote_credentials(ssh_user, ssh_host, ssh_cert) end |
.ssh_into_remote_credentials(ssh_user, ssh_host, ssh_cert = nil) ⇒ Object
SSH into remote with pre-supplied credentials.
16 17 18 19 20 21 22 |
# File 'lib/core/ssh.rb', line 16 def self.ssh_into_remote_credentials(ssh_user, ssh_host, ssh_cert = nil) if ssh_cert.nil? App::Terminal::command("ssh #{ssh_user}@#{ssh_host}", nil, false, false) else App::Terminal::command("ssh -i #{ssh_cert} #{ssh_user}@#{ssh_host}", nil, false, false) end end |