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) ## 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 - Logging. The entire Vagrant source has had logging sprinkled throughout
to make debugging issues easier. To enable logging, set the VAGRANT_LOG to make debugging issues easier. To enable logging, set the VAGRANT_LOG
environmental variable to the log level you wish to see. By default, 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 :ClearForwardedPorts, 'vagrant/action/vm/clear_forwarded_ports'
autoload :ClearNFSExports, 'vagrant/action/vm/clear_nfs_exports' autoload :ClearNFSExports, 'vagrant/action/vm/clear_nfs_exports'
autoload :ClearSharedFolders, 'vagrant/action/vm/clear_shared_folders' autoload :ClearSharedFolders, 'vagrant/action/vm/clear_shared_folders'
autoload :Customize, 'vagrant/action/vm/customize'
autoload :Destroy, 'vagrant/action/vm/destroy' autoload :Destroy, 'vagrant/action/vm/destroy'
autoload :DestroyUnusedNetworkInterfaces, 'vagrant/action/vm/destroy_unused_network_interfaces' autoload :DestroyUnusedNetworkInterfaces, 'vagrant/action/vm/destroy_unused_network_interfaces'
autoload :DiscardState, 'vagrant/action/vm/discard_state' autoload :DiscardState, 'vagrant/action/vm/discard_state'

View File

@ -29,6 +29,7 @@ module Vagrant
use VM::ShareFolders use VM::ShareFolders
use VM::HostName use VM::HostName
use VM::Network use VM::Network
use VM::Customize
use VM::Boot use VM::Boot
end end
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 Vagrant
module Config module Config
class VMConfig < Base class VMConfig < Base
include Util::StackedProcRunner
attr_accessor :name attr_accessor :name
attr_accessor :auto_port_range attr_accessor :auto_port_range
attr_accessor :box attr_accessor :box
@ -17,6 +15,7 @@ module Vagrant
attr_reader :shared_folders attr_reader :shared_folders
attr_reader :network_options attr_reader :network_options
attr_reader :provisioners attr_reader :provisioners
attr_reader :customizations
attr_accessor :guest attr_accessor :guest
def initialize def initialize
@ -24,6 +23,7 @@ module Vagrant
@shared_folders = {} @shared_folders = {}
@network_options = [] @network_options = []
@provisioners = [] @provisioners = []
@customizations = []
end end
def forward_port(name, guestport, hostport, options=nil) def forward_port(name, guestport, hostport, options=nil)
@ -64,8 +64,25 @@ module Vagrant
@provisioners << Provisioner.new(name, options, &block) @provisioners << Provisioner.new(name, options, &block)
end end
def customize(&block) # TODO: This argument should not be `nil` in the future.
push_proc(&block) # 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 end
def defined_vms def defined_vms

View File

@ -74,6 +74,11 @@ module Vagrant
end end
end end
# Executes a raw command.
def execute_command(command)
execute(*command)
end
# Forwards a set of ports for a VM. # Forwards a set of ports for a VM.
# #
# This will not affect any previously set forwarded ports, # 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. # This reads the folder where VirtualBox places it's VMs.
def read_machine_folder def read_machine_folder
execute("list", "systemproperties").split("\n").each do |line| 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 return $1.to_s
end end
end end

View File

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

View File

@ -31,6 +31,12 @@ en:
are printed below: are printed below:
%{messages} %{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: |- dotfile_is_directory: |-
The local file Vagrant uses to store data ".vagrant" already exists 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 and is a directory! If you are in your home directory, then please run