From ea7caebe02eca80bfb3ce9b0ce5020977b18c1f1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 10 Dec 2011 13:28:03 -0800 Subject: [PATCH] Setup the default name for the VM --- BRANCH_TODO | 1 - config/default.rb | 6 ------ lib/vagrant/action.rb | 3 ++- lib/vagrant/action/builtin.rb | 1 + lib/vagrant/action/vm/default_name.rb | 24 ++++++++++++++++++++++++ 5 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 lib/vagrant/action/vm/default_name.rb diff --git a/BRANCH_TODO b/BRANCH_TODO index 8c997cf1a..b0252d4c3 100644 --- a/BRANCH_TODO +++ b/BRANCH_TODO @@ -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 \ No newline at end of file diff --git a/config/default.rb b/config/default.rb index cfb14d01c..13b8f2a32 100644 --- a/config/default.rb +++ b/config/default.rb @@ -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", ".") diff --git a/lib/vagrant/action.rb b/lib/vagrant/action.rb index 8af1b338c..8d4bb2091 100644 --- a/lib/vagrant/action.rb +++ b/lib/vagrant/action.rb @@ -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' diff --git a/lib/vagrant/action/builtin.rb b/lib/vagrant/action/builtin.rb index 1da12a7d2..769487744 100644 --- a/lib/vagrant/action/builtin.rb +++ b/lib/vagrant/action/builtin.rb @@ -83,6 +83,7 @@ module Vagrant use VM::Import use VM::MatchMACAddress use VM::CheckGuestAdditions + use VM::DefaultName use registry.get(:start) end end diff --git a/lib/vagrant/action/vm/default_name.rb b/lib/vagrant/action/vm/default_name.rb new file mode 100644 index 000000000..b430623b4 --- /dev/null +++ b/lib/vagrant/action/vm/default_name.rb @@ -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