From e4c74dadd2fb84bf0700047965c53b41b9ffa8ce Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Wed, 10 Apr 2013 01:09:38 -0300 Subject: [PATCH] Support lxc templates under /usr/lib/lxc/templates Ubuntu Precise with lxc 0.7.5 keeps things on that folder --- lib/vagrant-lxc/driver.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb index 0d41f25..e243abf 100644 --- a/lib/vagrant-lxc/driver.rb +++ b/lib/vagrant-lxc/driver.rb @@ -128,8 +128,6 @@ module Vagrant protected - LXC_TEMPLATES_PATH = Pathname.new("/usr/share/lxc/templates") - # Root folder where container configs are stored CONTAINERS_PATH = '/var/lib/lxc' @@ -139,7 +137,7 @@ module Vagrant def import_template(path) template_name = "vagrant-tmp-#{@container_name}" - tmp_template_path = LXC_TEMPLATES_PATH.join("lxc-#{template_name}").to_s + tmp_template_path = templates_path.join("lxc-#{template_name}").to_s @logger.debug 'Copying LXC template into place' system(%Q[sudo su root -c "cp #{path} #{tmp_template_path}"]) @@ -148,6 +146,20 @@ module Vagrant ensure system(%Q[sudo su root -c "rm #{tmp_template_path}"]) end + + TEMPLATES_PATH_LOOKUP = %w( + /usr/share/lxc/templates + /usr/lib/lxc/templates + ) + def templates_path + return @templates_path if @templates_path + + path = TEMPLATES_PATH_LOOKUP.find { |candidate| File.directory?(candidate) } + # TODO: Raise an user friendly error + raise 'Unable to identify lxc templates path!' unless path + + @templates_path = Pathname(path) + end end end end