Customizations are back in!

This commit is contained in:
Mitchell Hashimoto 2011-12-21 16:25:58 -08:00
parent 306945dd26
commit e1d0ce19ce
8 changed files with 74 additions and 5 deletions

View File

@ -1,5 +1,9 @@
## 0.9.0 (unreleased)
- `config.vm.customize` now takes a command to send to `VBoxManage`, so any
arbitrary command can be sent. The older style of passing a block no longer
works and Vagrant will give a proper error message if it notices this old-style
being used.
- Logging. The entire Vagrant source has had logging sprinkled throughout
to make debugging issues easier. To enable logging, set the VAGRANT_LOG
environmental variable to the log level you wish to see. By default,

View File

@ -33,6 +33,7 @@ module Vagrant
autoload :ClearForwardedPorts, 'vagrant/action/vm/clear_forwarded_ports'
autoload :ClearNFSExports, 'vagrant/action/vm/clear_nfs_exports'
autoload :ClearSharedFolders, 'vagrant/action/vm/clear_shared_folders'
autoload :Customize, 'vagrant/action/vm/customize'
autoload :Destroy, 'vagrant/action/vm/destroy'
autoload :DestroyUnusedNetworkInterfaces, 'vagrant/action/vm/destroy_unused_network_interfaces'
autoload :DiscardState, 'vagrant/action/vm/discard_state'

View File

@ -29,6 +29,7 @@ module Vagrant
use VM::ShareFolders
use VM::HostName
use VM::Network
use VM::Customize
use VM::Boot
end
end

View File

@ -0,0 +1,30 @@
module Vagrant
module Action
module VM
class Customize
def initialize(app, env)
@app = app
end
def call(env)
customizations = env[:vm].config.vm.customizations
if !customizations.empty?
env[:ui].info I18n.t("vagrant.actions.vm.customize.running")
# Execute each customization command.
customizations.each do |command|
processed_command = command.collect do |arg|
arg = env[:vm].uuid if arg == :id
arg
end
env[:vm].driver.execute_command(processed_command)
end
end
@app.call(env)
end
end
end
end
end

View File

@ -4,8 +4,6 @@ require 'vagrant/config/vm/provisioner'
module Vagrant
module Config
class VMConfig < Base
include Util::StackedProcRunner
attr_accessor :name
attr_accessor :auto_port_range
attr_accessor :box
@ -17,6 +15,7 @@ module Vagrant
attr_reader :shared_folders
attr_reader :network_options
attr_reader :provisioners
attr_reader :customizations
attr_accessor :guest
def initialize
@ -24,6 +23,7 @@ module Vagrant
@shared_folders = {}
@network_options = []
@provisioners = []
@customizations = []
end
def forward_port(name, guestport, hostport, options=nil)
@ -64,8 +64,25 @@ module Vagrant
@provisioners << Provisioner.new(name, options, &block)
end
def customize(&block)
push_proc(&block)
# TODO: This argument should not be `nil` in the future.
# It is only defaulted to nil so that the deprecation error
# can be properly shown.
def customize(command=nil)
if block_given?
raise Errors::DeprecationError, :message => <<-MESSAGE
`config.vm.customize` now takes an array of arguments to send to
`VBoxManage` instead of having a block which gets a virtual machine
object. Example of the new usage:
config.vm.customize ["modifyvm", :id, "--memory", "1024"]
The above will run `VBoxManage modifyvm 1234 --memory 1024` where
"1234" is the ID of your current virtual machine. Anything you could
do before is certainly still possible with `VBoxManage` as well.
MESSAGE
end
@customizations << command if command
end
def defined_vms

View File

@ -74,6 +74,11 @@ module Vagrant
end
end
# Executes a raw command.
def execute_command(command)
execute(*command)
end
# Forwards a set of ports for a VM.
#
# This will not affect any previously set forwarded ports,
@ -171,7 +176,7 @@ module Vagrant
# This reads the folder where VirtualBox places it's VMs.
def read_machine_folder
execute("list", "systemproperties").split("\n").each do |line|
if line =~ /^Default machine folder:\s+(.+?)$/
if line =~ /^Default machine folder:\s+(.+?)$/i
return $1.to_s
end
end

View File

@ -138,6 +138,11 @@ module Vagrant
error_key(:config_validation)
end
class DeprecationError < VagrantError
status_code(60)
error_key(:deprecation)
end
class DotfileIsDirectory < VagrantError
status_code(46)
error_key(:dotfile_is_directory)

View File

@ -31,6 +31,12 @@ en:
are printed below:
%{messages}
deprecation: |-
You are using a feature that has been removed in this version. Explanation:
%{message}
Note that this error message will not appear in the next version of Vagrant.
dotfile_is_directory: |-
The local file Vagrant uses to store data ".vagrant" already exists
and is a directory! If you are in your home directory, then please run