VirtualBox config: "name" to set the VM name [GH-1126]
This commit is contained in:
parent
d19194d95b
commit
4fa194899d
|
@ -34,6 +34,8 @@ FEATURES:
|
|||
false will not attempt to automatically manage NAT DNS proxy settings
|
||||
with VirtualBox. [GH-1313]
|
||||
- `vagrant provision` accepts the `--provision-with` flag [GH-1167]
|
||||
- Set the name of VirtualBox machines with `virtualbox.name` in the
|
||||
VirtualBox provider config. [GH-1126]
|
||||
|
||||
IMPROVEMENTS / BUG FIXES:
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ module VagrantPlugins
|
|||
autoload :ClearSharedFolders, File.expand_path("../action/clear_shared_folders", __FILE__)
|
||||
autoload :Created, File.expand_path("../action/created", __FILE__)
|
||||
autoload :Customize, File.expand_path("../action/customize", __FILE__)
|
||||
autoload :DefaultName, File.expand_path("../action/default_name", __FILE__)
|
||||
autoload :Destroy, File.expand_path("../action/destroy", __FILE__)
|
||||
autoload :DestroyConfirm, File.expand_path("../action/destroy_confirm", __FILE__)
|
||||
autoload :DestroyUnusedNetworkInterfaces, File.expand_path("../action/destroy_unused_network_interfaces", __FILE__)
|
||||
|
@ -41,6 +40,7 @@ module VagrantPlugins
|
|||
autoload :PruneNFSExports, File.expand_path("../action/prune_nfs_exports", __FILE__)
|
||||
autoload :Resume, File.expand_path("../action/resume", __FILE__)
|
||||
autoload :SaneDefaults, File.expand_path("../action/sane_defaults", __FILE__)
|
||||
autoload :SetName, File.expand_path("../action/set_name", __FILE__)
|
||||
autoload :SetupPackageFiles, File.expand_path("../action/setup_package_files", __FILE__)
|
||||
autoload :ShareFolders, File.expand_path("../action/share_folders", __FILE__)
|
||||
autoload :Suspend, File.expand_path("../action/suspend", __FILE__)
|
||||
|
@ -295,7 +295,7 @@ module VagrantPlugins
|
|||
b2.use CheckBox
|
||||
b2.use Import
|
||||
b2.use CheckGuestAdditions
|
||||
b2.use DefaultName
|
||||
b2.use SetName
|
||||
b2.use MatchMACAddress
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
require "log4r"
|
||||
|
||||
module VagrantPlugins
|
||||
module ProviderVirtualBox
|
||||
module Action
|
||||
class DefaultName
|
||||
def initialize(app, env)
|
||||
@logger = Log4r::Logger.new("vagrant::action::vm::defaultname")
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
# Figure out the name and sanitize the default
|
||||
prefix = env[:root_path].basename.to_s
|
||||
prefix.gsub!(/[^-a-z0-9_]/i, "")
|
||||
name = prefix + "_#{Time.now.to_i}"
|
||||
@logger.info("Setting the default name of the VM: #{name}")
|
||||
|
||||
env[:machine].provider.driver.set_name(name)
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,30 @@
|
|||
require "log4r"
|
||||
|
||||
module VagrantPlugins
|
||||
module ProviderVirtualBox
|
||||
module Action
|
||||
class SetName
|
||||
def initialize(app, env)
|
||||
@logger = Log4r::Logger.new("vagrant::action::vm::setname")
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
name = env[:machine].provider_config.name
|
||||
|
||||
# If no name was manually set, then use a default
|
||||
if !name
|
||||
prefix = env[:root_path].basename.to_s
|
||||
prefix.gsub!(/[^-a-z0-9_]/i, "")
|
||||
name = prefix + "_#{Time.now.to_i}"
|
||||
end
|
||||
|
||||
@logger.info("Setting the name of the VM: #{name}")
|
||||
env[:machine].provider.driver.set_name(name)
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -18,6 +18,12 @@ module VagrantPlugins
|
|||
# @return [Boolean]
|
||||
attr_accessor :gui
|
||||
|
||||
# This should be set to the name of the machine in the VirtualBox
|
||||
# GUI.
|
||||
#
|
||||
# @return [String]
|
||||
attr_accessor :name
|
||||
|
||||
# The defined network adapters.
|
||||
#
|
||||
# @return [Hash]
|
||||
|
@ -26,6 +32,7 @@ module VagrantPlugins
|
|||
def initialize
|
||||
@auto_nat_dns_proxy = UNSET_VALUE
|
||||
@customizations = []
|
||||
@name = UNSET_VALUE
|
||||
@network_adapters = {}
|
||||
@gui = UNSET_VALUE
|
||||
|
||||
|
@ -66,6 +73,9 @@ module VagrantPlugins
|
|||
|
||||
# Default is to not show a GUI
|
||||
@gui = false if @gui == UNSET_VALUE
|
||||
|
||||
# The default name is just nothing, and we default it
|
||||
@name = nil if @name == UNSET_VALUE
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue