From ffb573a7f115dfe2172d5fe7342c437c38988093 Mon Sep 17 00:00:00 2001 From: Cam Cope Date: Wed, 1 Jan 2014 16:54:27 -0500 Subject: [PATCH] allow setting the container name in the vagrantfile --- lib/vagrant-lxc/action/create.rb | 10 +++++++--- lib/vagrant-lxc/config.rb | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-lxc/action/create.rb b/lib/vagrant-lxc/action/create.rb index 018db0d..abca848 100644 --- a/lib/vagrant-lxc/action/create.rb +++ b/lib/vagrant-lxc/action/create.rb @@ -7,9 +7,13 @@ module Vagrant end def call(env) - container_name = "#{env[:root_path].basename}_#{env[:machine].name}" - container_name.gsub!(/[^-a-z0-9_]/i, "") - container_name << "-#{Time.now.to_i}" + if env[:machine].provider_config.static_name + container_name = env[:machine].name.to_s + else + container_name = "#{env[:root_path].basename}_#{env[:machine].name}" + container_name.gsub!(/[^-a-z0-9_]/i, "") + container_name << "-#{Time.now.to_i}" + end env[:machine].provider.driver.create( container_name, diff --git a/lib/vagrant-lxc/config.rb b/lib/vagrant-lxc/config.rb index 2065bc8..59739ec 100644 --- a/lib/vagrant-lxc/config.rb +++ b/lib/vagrant-lxc/config.rb @@ -12,9 +12,13 @@ module Vagrant # on /etc/sudoers attr_accessor :sudo_wrapper + # A String that sets a static name + attr_accessor :static_name + def initialize @customizations = [] @sudo_wrapper = UNSET_VALUE + @static_name = UNSET_VALUE end # Customize the container by calling `lxc-start` with the given @@ -34,6 +38,7 @@ module Vagrant def finalize! @sudo_wrapper = nil if @sudo_wrapper == UNSET_VALUE + @static_name = nil if @static_name == UNSET_VALUE end def validate(machine)