<commit_before>require "log4r"

module VagrantPlugins
  module XenServer
    module Action
      # This action reads the SSH info for the machine and puts it into the
      # `:machine_ssh_info` key in the environment.
      class ReadSSHInfo
        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant_xenserver::action::read_ssh_info")
        end

        def call(env)
          if env[:machine].provider_config.use_himn
            env[:machine_ssh_info] = read_ssh_info_himn(env)
          else
            env[:machine_ssh_info] = read_ssh_info(env)
          end

          @app.call(env)
        end

        def read_ssh_info_himn(env)
          machine = env[:machine]
          return nil if machine.id.nil?

          # Find the machine
          networks = env[:xc].network.get_all_records

          begin
            vifs = env[:xc].VM.get_VIFs(machine.id)
          rescue
            @logger.info("Machine couldn't be found, assuming it got destroyed.")
            machine.id = nil
            return nil
          end

          himn = networks.find { |ref,net| net['other_config']['is_host_internal_management_network'] }
          (himn_ref,himn_rec) = himn

          assigned_ips = himn_rec['assigned_ips']
          (vif,ip) = assigned_ips.find { |vif,ip| vifs.include? vif }

          ssh_info = {
            :host          => ip,
            :port          => machine.config.ssh.guest_port,
            :username      => machine.config.ssh.username,
            :forward_agent => machine.config.ssh.forward_agent,
            :forward_x11   => machine.config.ssh.forward_x11,
          }

          ssh_info[:proxy_command] = "ssh '#{machine.provider_config.xs_host}' -l '#{machine.provider_config.xs_username}' nc %h %p"

          if not ssh_info[:username]
            ssh_info[:username] = machine.config.ssh.default.username
          end

          return ssh_info
        end<commit_msg>Do not require netcat to be installed on target host<commit_after>require "log4r"

module VagrantPlugins
  module XenServer
    module Action
      # This action reads the SSH info for the machine and puts it into the
      # `:machine_ssh_info` key in the environment.
      class ReadSSHInfo
        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant_xenserver::action::read_ssh_info")
        end

        def call(env)
          if env[:machine].provider_config.use_himn
            env[:machine_ssh_info] = read_ssh_info_himn(env)
          else
            env[:machine_ssh_info] = read_ssh_info(env)
          end

          @app.call(env)
        end

        def read_ssh_info_himn(env)
          machine = env[:machine]
          return nil if machine.id.nil?

          # Find the machine
          networks = env[:xc].network.get_all_records

          begin
            vifs = env[:xc].VM.get_VIFs(machine.id)
          rescue
            @logger.info("Machine couldn't be found, assuming it got destroyed.")
            machine.id = nil
            return nil
          end

          himn = networks.find { |ref,net| net['other_config']['is_host_internal_management_network'] }
          (himn_ref,himn_rec) = himn

          assigned_ips = himn_rec['assigned_ips']
          (vif,ip) = assigned_ips.find { |vif,ip| vifs.include? vif }

          ssh_info = {
            :host          => ip,
            :port          => machine.config.ssh.guest_port,
            :username      => machine.config.ssh.username,
            :forward_agent => machine.config.ssh.forward_agent,
            :forward_x11   => machine.config.ssh.forward_x11,
          }

          ssh_info[:proxy_command] = "ssh '#{machine.provider_config.xs_host}' -l '#{machine.provider_config.xs_username}' -W %h:%p"

          if not ssh_info[:username]
            ssh_info[:username] = machine.config.ssh.default.username
          end

          return ssh_info
        end
{'fraction_non_alphanumeric': 0.09765919959728166, 'fraction_numerical': 0.003020387616410773, 'mean_word_length': 1.9306784660766962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3008534', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1170, 'n_words': 247}