Class: Ssh
- Inherits:
-
Object
- Object
- Ssh
- Defined in:
- lib/vmfloaty/ssh.rb
Class Method Summary collapse
Class Method Details
.ssh(verbose, host_os, token, url) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vmfloaty/ssh.rb', line 17 def self.ssh(verbose, host_os, token, url) ssh_path = which('ssh') raise 'Could not determine path to ssh' unless ssh_path os_types = {} os_types[host_os] = 1 response = Pooler.retrieve(verbose, os_types, token, url) raise "Could not get vm from vmpooler:\n #{response}" unless response['ok'] user = /win/.match?(host_os) ? 'Administrator' : 'root' hostname = "#{response[host_os]['hostname']}.#{response['domain']}" cmd = "#{ssh_path} #{user}@#{hostname}" # TODO: Should this respect more ssh settings? Can it be configured # by users ssh config and does this respect those settings? Kernel.exec(cmd) nil end |
.which(cmd) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/vmfloaty/ssh.rb', line 4 def self.which(cmd) # Gets path of executable for given command exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) end end nil end |