From 6e7ab85dadcb04a49bd4eeadf311e2fbc5bd2c8b Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sun, 2 Feb 2014 19:42:32 -0200 Subject: [PATCH] Use a safer random name for containers (closes GH-192) if the same vagrantfile is up'd in the same second in the same basedir this caused a conflict --- CHANGELOG.md | 4 ++++ lib/vagrant-lxc/action/create.rb | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67030d3..8fedc1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ FEATURES: - Support for naming containers from Vagrantfiles [#132](https://github.com/fgrehm/vagrant-lxc/issues/132) +IMPROVEMENTS: + + - Use a safer random name for containers [#152](https://github.com/fgrehm/vagrant-lxc/issues/152) + BUG FIXES: - Properly detect if lxc is installed on hosts that do not have `lxc-version` on their paths [#186](https://github.com/fgrehm/vagrant-lxc/issues/186) diff --git a/lib/vagrant-lxc/action/create.rb b/lib/vagrant-lxc/action/create.rb index dc519bb..1676e21 100644 --- a/lib/vagrant-lxc/action/create.rb +++ b/lib/vagrant-lxc/action/create.rb @@ -17,7 +17,9 @@ module Vagrant else container_name = "#{env[:root_path].basename}_#{env[:machine].name}" container_name.gsub!(/[^-a-z0-9_]/i, "") - container_name << "-#{Time.now.to_i}" + # milliseconds + random number suffix to allow for simultaneous + # `vagrant up` of the same box in different dirs + container_name << "_#{(Time.now.to_f * 1000.0).to_i}_#{rand(100000)}" end env[:machine].provider.driver.create(