diff --git a/CHANGELOG.md b/CHANGELOG.md index c2867c2..ee02cf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ IMPROVEMENTS: - The provider will now have a higher priority over the VirtualBox provider in case VirtualBox is installed alongside lxc dependecies. + - Show an user friendly message when trying to use the plugin on non-Linux + environments. ## [1.0.1](https://github.com/fgrehm/vagrant-lxc/compare/v1.0.0...v1.0.1) (Oct 15, 2014) diff --git a/lib/vagrant-lxc/errors.rb b/lib/vagrant-lxc/errors.rb index 4446b70..e2254ff 100644 --- a/lib/vagrant-lxc/errors.rb +++ b/lib/vagrant-lxc/errors.rb @@ -18,6 +18,10 @@ module Vagrant class NamespacesNotSupported < Vagrant::Errors::VagrantError end + class LxcLinuxRequired < Vagrant::Errors::VagrantError + error_key(:lxc_linux_required) + end + class LxcNotInstalled < Vagrant::Errors::VagrantError error_key(:lxc_not_installed) end diff --git a/lib/vagrant-lxc/provider.rb b/lib/vagrant-lxc/provider.rb index fbae5b2..dead6ab 100644 --- a/lib/vagrant-lxc/provider.rb +++ b/lib/vagrant-lxc/provider.rb @@ -9,6 +9,14 @@ module Vagrant class Provider < Vagrant.plugin("2", :provider) attr_reader :driver + def self.usable?(raise_error=false) + if !Vagrant::Util::Platform.linux? + raise Errors::LxcLinuxRequired + end + + true + end + def initialize(machine) @logger = Log4r::Logger.new("vagrant::provider::lxc") @machine = machine diff --git a/locales/en.yml b/locales/en.yml index 51f8d8c..32f635f 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -56,6 +56,10 @@ en: Looked up under: %{paths} + lxc_linux_required: |- + The LXC provider only works on Linux. Please try to use + another provider. + lxc_not_installed: |- The `lxc` package does not seem to be installed or is not accessible on the PATH.