Setup the default name for the VM
This commit is contained in:
parent
f2666a9b74
commit
ea7caebe02
|
@ -3,4 +3,3 @@ This is a TODO file for only this branch (config-overhaul)
|
|||
* Only allow one kind of vagrantfile to be loaded (i.e. if both
|
||||
Vagrantfile and vagrantfile exist, throw an error)
|
||||
* Nicer error if can't setup home directory
|
||||
* Default name to folder name + timestamp
|
|
@ -21,12 +21,6 @@ Vagrant::Config.run do |config|
|
|||
config.vm.boot_mode = "vrdp"
|
||||
config.vm.system = :linux
|
||||
|
||||
config.vm.customize do |vm|
|
||||
# Make VM name the name of the containing folder by default
|
||||
# TODO
|
||||
# vm.name = File.basename(config.env.cwd) + "_#{Time.now.to_i}"
|
||||
end
|
||||
|
||||
# Share the root folder. This can then be overridden by
|
||||
# other Vagrantfiles, if they wish.
|
||||
config.vm.share_folder("v-root", "/vagrant", ".")
|
||||
|
|
|
@ -34,7 +34,8 @@ 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 :Customize, 'vagrant/action/vm/customize'
|
||||
autoload :DefaultName, 'vagrant/action/vm/default_name'
|
||||
autoload :Destroy, 'vagrant/action/vm/destroy'
|
||||
autoload :DestroyUnusedNetworkInterfaces, 'vagrant/action/vm/destroy_unused_network_interfaces'
|
||||
autoload :DiscardState, 'vagrant/action/vm/discard_state'
|
||||
|
|
|
@ -83,6 +83,7 @@ module Vagrant
|
|||
use VM::Import
|
||||
use VM::MatchMACAddress
|
||||
use VM::CheckGuestAdditions
|
||||
use VM::DefaultName
|
||||
use registry.get(:start)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
module Vagrant
|
||||
module Action
|
||||
module VM
|
||||
# This action sets the default name of a virtual machine. The default
|
||||
# name is the CWD of the environment plus a timestamp.
|
||||
class DefaultName
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
# Create the proc to setup the default name
|
||||
proc = lambda do |vm|
|
||||
vm.name = File.basename(env[:vm].env.cwd) + "_#{Time.now.to_i}"
|
||||
end
|
||||
|
||||
env["vm.modify"].call(proc)
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue