Class: VagrantPlugins::SshConfigManager::SshInfoExtractor
- Inherits:
-
Object
- Object
- VagrantPlugins::SshConfigManager::SshInfoExtractor
- Defined in:
- lib/vagrant_ssh_config_manager/ssh_info_extractor.rb
Instance Method Summary collapse
-
#extract_ssh_info ⇒ Object
Extract SSH information from Vagrant’s internal APIs This replicates what ‘vagrant ssh-config’ does but using internal methods.
-
#initialize(machine) ⇒ SshInfoExtractor
constructor
A new instance of SshInfoExtractor.
-
#machine_supports_ssh? ⇒ Boolean
Comprehensive check for SSH support.
-
#ssh_capable? ⇒ Boolean
Check if the machine supports SSH with comprehensive validation.
Constructor Details
#initialize(machine) ⇒ SshInfoExtractor
6 7 8 9 |
# File 'lib/vagrant_ssh_config_manager/ssh_info_extractor.rb', line 6 def initialize(machine) @machine = machine @logger = Log4r::Logger.new('vagrant::plugins::ssh_config_manager::ssh_info_extractor') end |
Instance Method Details
#extract_ssh_info ⇒ Object
Extract SSH information from Vagrant’s internal APIs This replicates what ‘vagrant ssh-config’ does but using internal methods
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vagrant_ssh_config_manager/ssh_info_extractor.rb', line 13 def extract_ssh_info ssh_info = @machine.ssh_info return nil if ssh_info.nil? # Additional validation for SSH info completeness return nil unless valid_ssh_info?(ssh_info) # Get the SSH configuration similar to what vagrant ssh-config provides config = build_ssh_config(ssh_info) @logger&.info("Extracted SSH info for machine: #{@machine.name}") config rescue Vagrant::Errors::SSHNotReady => e @logger&.debug("SSH not ready for machine #{@machine.name}: #{e.}") nil rescue Vagrant::Errors::SSHUnavailable => e @logger&.debug("SSH unavailable for machine #{@machine.name}: #{e.}") nil rescue StandardError => e @logger&.warn("Failed to extract SSH info for machine #{@machine.name}: #{e.}") nil end |
#machine_supports_ssh? ⇒ Boolean
Comprehensive check for SSH support
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/vagrant_ssh_config_manager/ssh_info_extractor.rb', line 49 def machine_supports_ssh? # Basic checks return false unless @machine return false unless @machine.communicate_ready? # Check if machine state supports SSH return false unless machine_state_supports_ssh? # Check if communicator is SSH-based return false unless ssh_communicator? # Check if provider supports SSH return false unless provider_supports_ssh? true rescue StandardError => e @logger.debug("Machine SSH support check failed: #{e.}") false end |
#ssh_capable? ⇒ Boolean
Check if the machine supports SSH with comprehensive validation
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vagrant_ssh_config_manager/ssh_info_extractor.rb', line 37 def ssh_capable? # Simplified check - if machine is running and has SSH info, assume SSH is available @machine&.state && @machine.state.id == :running && @machine.ssh_info && ssh_communicator? rescue StandardError => e @logger&.debug("SSH capability check failed: #{e.}") false end |