<commit_before>require "log4r"

module Vagrant
  module Action
    module VM
      # This middleware enforces some sane defaults on the virtualbox
      # VM which help with performance, stability, and in some cases
      # behavior.
      class SaneDefaults
        def initialize(app, env)
          @logger = Log4r::Logger.new("vagrant::action::vm::sanedefaults")
          @app = app
        end

        def call(env)
          # Set the env on an instance variable so we can access it in
          # helpers.
          @env = env

          # Enable the host IO cache on the sata controller. Note that
          # if this fails then its not a big deal, so we don't raise any
          # errors. The Host IO cache vastly improves disk IO performance
          # for VMs.
          command = [
            "storagectl", env[:vm].uuid,
            "--name", "SATA Controller",
            "--hostiocache", "on"
          ]
          attempt_and_log(command, "Enabling the Host I/O cache on the SATA controller...")

          # Enable the DNS proxy while in NAT mode.  This shields the guest
          # VM from external DNS changs on the host machine.
          command = [
            "modifyvm", env[:vm].uuid,
            "--natdnsproxy1", "on"
          ]
          attempt_and_log(command, "Enable the NAT DNS proxy on adapter 1...")

          @app.call(env)
        end

        protected
<commit_msg>Detect and disable DNS settings that break on Ubuntu 12.04.<commit_after>require "log4r"

module Vagrant
  module Action
    module VM
      # This middleware enforces some sane defaults on the virtualbox
      # VM which help with performance, stability, and in some cases
      # behavior.
      class SaneDefaults
        def initialize(app, env)
          @logger = Log4r::Logger.new("vagrant::action::vm::sanedefaults")
          @app = app
        end

        def call(env)
          # Set the env on an instance variable so we can access it in
          # helpers.
          @env = env

          # Enable the host IO cache on the sata controller. Note that
          # if this fails then its not a big deal, so we don't raise any
          # errors. The Host IO cache vastly improves disk IO performance
          # for VMs.
          command = [
            "storagectl", env[:vm].uuid,
            "--name", "SATA Controller",
            "--hostiocache", "on"
          ]
          attempt_and_log(command, "Enabling the Host I/O cache on the SATA controller...")

          enable_dns_proxy = true
          begin
            contents = File.read("/etc/resolv.conf")

            if contents =~ /^nameserver 127\.0\.0\.1$/
              # The use of both natdnsproxy and natdnshostresolver break on
              # Ubuntu 12.04 that uses resolvconf with localhost. When used
              # VirtualBox will give the client dns server 10.0.2.3, while
              # not binding to that address itself. Therefore disable this
              # feature if host uses the resolvconf server 127.0.0.1
              @logger.info("Disabling DNS proxy since resolv.conf contains 127.0.0.1")
              enable_dns_proxy = false
            end
          rescue Errno::ENOENT; end

          # Enable/disable the NAT DNS proxy as necessary
          if enable_dns_proxy
            command = [
              "modifyvm", env[:vm].uuid,
              "--natdnsproxy1", "on"
            ]
            attempt_and_log(command, "Enable the NAT DNS proxy on adapter 1...")
          else
            command = [ "modifyvm", env[:vm].uuid, "--natdnsproxy1", "off" ]
            attempt_and_log(command, "Disable the NAT DNS proxy on adapter 1...")
            command = [ "modifyvm", env[:vm].uuid, "--natdnshostresolver1", "off" ]
            attempt_and_log(command, "Disable the NAT DNS resolver on adapter 1...")
          end

          @app.call(env)
        end

        protected

{'fraction_non_alphanumeric': 0.08596356171413908, 'fraction_numerical': 0.011034128817038748, 'mean_word_length': 1.7645390070921987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, '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': '6598323', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1036, 'n_words': 391}