Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Commit

Permalink
Better logging in the SaneDefaults middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Mar 23, 2012
1 parent 3d1879e commit 3877b71
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/vagrant/action/vm/sane_defaults.rb
@@ -1,3 +1,5 @@
require "log4r"

module Vagrant
module Action
module VM
Expand All @@ -6,10 +8,15 @@ module VM
# 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
Expand All @@ -19,18 +26,31 @@ def call(env)
"--name", "SATA Controller",
"--hostiocache", "on"
]
env[:vm].driver.execute_command(command)
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"
]
env[:vm].driver.execute_command(command)
attempt_and_log(command, "Enable the NAT DNS proxy on adapter 1...")

@app.call(env)
end

protected

# This is just a helper method that executes a single command, logs
# the given string to the log, and also includes the exit status in
# the log message.
#
# @param [Array] command Command to run
# @param [String] log Log message to write.
def attempt_and_log(command, log)
result = @env[:vm].driver.execute_command(command)
@logger.info("#{log} (exit status = #{result.exit_code})")
end
end
end
end
Expand Down

0 comments on commit 3877b71

Please sign in to comment.