Better logging in the SaneDefaults middleware

This commit is contained in:
Mitchell Hashimoto 2012-03-23 10:00:26 -04:00
parent 3d1879e4a0
commit 3877b71983
1 changed files with 22 additions and 2 deletions

View File

@ -1,3 +1,5 @@
require "log4r"
module Vagrant module Vagrant
module Action module Action
module VM module VM
@ -6,10 +8,15 @@ module Vagrant
# behavior. # behavior.
class SaneDefaults class SaneDefaults
def initialize(app, env) def initialize(app, env)
@logger = Log4r::Logger.new("vagrant::action::vm::sanedefaults")
@app = app @app = app
end end
def call(env) 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 # 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 # 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 # errors. The Host IO cache vastly improves disk IO performance
@ -19,7 +26,7 @@ module Vagrant
"--name", "SATA Controller", "--name", "SATA Controller",
"--hostiocache", "on" "--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 # Enable the DNS proxy while in NAT mode. This shields the guest
# VM from external DNS changs on the host machine. # VM from external DNS changs on the host machine.
@ -27,10 +34,23 @@ module Vagrant
"modifyvm", env[:vm].uuid, "modifyvm", env[:vm].uuid,
"--natdnsproxy1", "on" "--natdnsproxy1", "on"
] ]
env[:vm].driver.execute_command(command) attempt_and_log(command, "Enable the NAT DNS proxy on adapter 1...")
@app.call(env) @app.call(env)
end 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 end
end end