provider: Show an user friendly message when trying to use the plugin on non-Linux environments

This commit is contained in:
Fabio Rehm 2015-01-08 02:17:29 -02:00
parent 2a667b88b6
commit 8b37056294
4 changed files with 18 additions and 0 deletions

View file

@ -8,6 +8,8 @@ IMPROVEMENTS:
- The provider will now have a higher priority over the VirtualBox provider - The provider will now have a higher priority over the VirtualBox provider
in case VirtualBox is installed alongside lxc dependecies. 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) ## [1.0.1](https://github.com/fgrehm/vagrant-lxc/compare/v1.0.0...v1.0.1) (Oct 15, 2014)

View file

@ -18,6 +18,10 @@ module Vagrant
class NamespacesNotSupported < Vagrant::Errors::VagrantError class NamespacesNotSupported < Vagrant::Errors::VagrantError
end end
class LxcLinuxRequired < Vagrant::Errors::VagrantError
error_key(:lxc_linux_required)
end
class LxcNotInstalled < Vagrant::Errors::VagrantError class LxcNotInstalled < Vagrant::Errors::VagrantError
error_key(:lxc_not_installed) error_key(:lxc_not_installed)
end end

View file

@ -9,6 +9,14 @@ module Vagrant
class Provider < Vagrant.plugin("2", :provider) class Provider < Vagrant.plugin("2", :provider)
attr_reader :driver attr_reader :driver
def self.usable?(raise_error=false)
if !Vagrant::Util::Platform.linux?
raise Errors::LxcLinuxRequired
end
true
end
def initialize(machine) def initialize(machine)
@logger = Log4r::Logger.new("vagrant::provider::lxc") @logger = Log4r::Logger.new("vagrant::provider::lxc")
@machine = machine @machine = machine

View file

@ -56,6 +56,10 @@ en:
Looked up under: %{paths} Looked up under: %{paths}
lxc_linux_required: |-
The LXC provider only works on Linux. Please try to use
another provider.
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.