From a96efcdec9627e17c218648b84cb8c2ec6302251 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 31 Aug 2013 22:43:33 -0700 Subject: [PATCH] providers/virtualbox: only set default name on first up [GH-1817] --- CHANGELOG.md | 2 ++ plugins/providers/virtualbox/action/set_name.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index de24010a6..b3b9ea731 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,8 @@ BUG FIXES: with Puppet. [GH-2015] - providers/virtualbox: Use `getent` to get the group ID instead of `id` in case the name doesn't have a user. [GH-1801] + - providers/virtualbox: Will only set the default name of the VM on + initial `up`. [GH-1817] ## 1.2.7 (July 28, 2013) diff --git a/plugins/providers/virtualbox/action/set_name.rb b/plugins/providers/virtualbox/action/set_name.rb index 9db19108a..906e52942 100644 --- a/plugins/providers/virtualbox/action/set_name.rb +++ b/plugins/providers/virtualbox/action/set_name.rb @@ -12,6 +12,13 @@ module VagrantPlugins def call(env) name = env[:machine].provider_config.name + # If we already set the name before, then don't do anything + sentinel = env[:machine].data_dir.join("action_set_name") + if !name && sentinel.file? + @logger.info("Default name was already set before, not doing it again.") + return @app.call(env) + end + # If no name was manually set, then use a default if !name prefix = "#{env[:root_path].basename.to_s}_#{env[:machine].name}" @@ -32,6 +39,11 @@ module VagrantPlugins env[:machine].provider.driver.set_name(name) end + # Create the sentinel + sentinel.open("w") do |f| + f.write(Time.now.to_i.to_s) + end + @app.call(env) end end