Nicely handles missing templates path (fixes GH-139)

This commit is contained in:
Fabio Rehm 2013-09-28 02:58:38 -03:00
parent c76df6358c
commit 18bb9482d5
4 changed files with 15 additions and 3 deletions

View file

@ -9,6 +9,7 @@ BUG FIXES:
- Fix various issues related to detecting whether the container is running - Fix various issues related to detecting whether the container is running
and is "SSHable" [#142](https://github.com/fgrehm/vagrant-lxc/issues/142) and is "SSHable" [#142](https://github.com/fgrehm/vagrant-lxc/issues/142)
- Nicely handle missing templates path [#139](https://github.com/fgrehm/vagrant-lxc/issues/139)
## [0.6.0](https://github.com/fgrehm/vagrant-lxc/compare/v0.5.0...v0.6.0) (Sep 12, 2013) ## [0.6.0](https://github.com/fgrehm/vagrant-lxc/compare/v0.5.0...v0.6.0) (Sep 12, 2013)

View file

@ -156,8 +156,10 @@ module Vagrant
yield template_name yield template_name
ensure ensure
@logger.info 'Removing LXC template' @logger.info 'Removing LXC template'
if tmp_template_path
@sudo_wrapper.run('rm', tmp_template_path) @sudo_wrapper.run('rm', tmp_template_path)
end end
end
TEMPLATES_PATH_LOOKUP = %w( TEMPLATES_PATH_LOOKUP = %w(
/usr/share/lxc/templates /usr/share/lxc/templates
@ -169,8 +171,9 @@ module Vagrant
return @templates_path if @templates_path return @templates_path if @templates_path
path = TEMPLATES_PATH_LOOKUP.find { |candidate| File.directory?(candidate) } path = TEMPLATES_PATH_LOOKUP.find { |candidate| File.directory?(candidate) }
# TODO: Raise an user friendly error if !path
raise 'Unable to identify lxc templates path!' unless path raise Errors::TemplatesDirMissing.new paths: TEMPLATES_PATH_LOOKUP.inspect
end
@templates_path = Pathname(path) @templates_path = Pathname(path)
end end

View file

@ -15,6 +15,9 @@ module Vagrant
class TemplateFileMissing < Vagrant::Errors::VagrantError class TemplateFileMissing < Vagrant::Errors::VagrantError
error_key(:lxc_template_file_missing) error_key(:lxc_template_file_missing)
end end
class TemplatesDirMissing < Vagrant::Errors::VagrantError
error_key(:lxc_templates_dir_missing)
end
class RootFSTarballMissing < Vagrant::Errors::VagrantError class RootFSTarballMissing < Vagrant::Errors::VagrantError
error_key(:lxc_invalid_box_version) error_key(:lxc_invalid_box_version)
end end

View file

@ -46,6 +46,11 @@ en:
The template file used for creating the container was not found for %{name} The template file used for creating the container was not found for %{name}
box. box.
lxc_templates_dir_missing: |-
Unable to identify lxc templates path.
Looked up under: %{paths}
lxc_not_installed: |- lxc_not_installed: |-
The `lxc` package does not seem to be installed or is not accessible on the PATH. The `lxc` package does not seem to be installed or is not accessible on the PATH.