Class: VagrantTestSubject::SSH
- Inherits:
-
Object
- Object
- VagrantTestSubject::SSH
- Defined in:
- lib/vagrant-test-subject/ssh.rb
Overview
Encapsulates an SSH channel into a VM
Instance Method Summary collapse
-
#initialize(vm_name = 'default') ⇒ SSH
constructor
A new instance of SSH.
- #method_missing(*args, &block) ⇒ Object
Constructor Details
#initialize(vm_name = 'default') ⇒ SSH
Returns a new instance of SSH.
5 6 7 8 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 |
# File 'lib/vagrant-test-subject/ssh.rb', line 5 def initialize(vm_name = 'default') # Grab ssh config config = `vagrant ssh-config` # Write most of it to a file, grabbing the username and host config_file = Tempfile.new("vagrant-ssh-conf") host, username = nil, nil config.split(/\n/).each do |line| case line when /^\s+User\s+(\w+)/ username = $1 when /^\s+HostName\s+(\S+)/ host = $1 when /^\s*Host\s+#{vm_name}/ # Ignore else config_file << line + "\n" end end config_file.flush # make a Net::SSH Session # and delegate everything to it @session = Net::SSH.start(host, username, :config => config_file.path) config_file.close end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
35 36 37 38 |
# File 'lib/vagrant-test-subject/ssh.rb', line 35 def method_missing(*args, &block) method_name = args.shift @session.send method_name, *args, &block end |