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
This commit is contained in:
Fabio Rehm 2014-02-02 19:42:32 -02:00
parent 7e00b96520
commit 6e7ab85dad
2 changed files with 7 additions and 1 deletions

View file

@ -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)

View file

@ -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(