From 97f6edeed8719d252095b4451c0b6b05d5a2c2b3 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sun, 28 Jul 2013 02:54:58 -0300 Subject: [PATCH] Error out if LXC is not installed This is enough to close #11 --- CHANGELOG.md | 2 +- README.md | 8 -------- lib/vagrant-lxc/action.rb | 10 ---------- lib/vagrant-lxc/errors.rb | 4 ++++ lib/vagrant-lxc/provider.rb | 7 +++++++ locales/en.yml | 3 +++ 6 files changed, 15 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7088dc..9c82aba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ FEATURES: IMPROVEMENTS: - - Error out if `redir` is not installed but port forwarding was configured [#112](https://github.com/fgrehm/vagrant-lxc/issues/112) + - Error out if dependencies are not installed [#11](https://github.com/fgrehm/vagrant-lxc/issues/11) / [#112](https://github.com/fgrehm/vagrant-lxc/issues/112) - Support for specifying host interface/ip for binding `redir` [#76](https://github.com/fgrehm/vagrant-lxc/issues/76) - Add Vagrantfile VM name to the container name [#115](https://github.com/fgrehm/vagrant-lxc/issues/115) - Properly handle forwarded port collisions [#5](https://github.com/fgrehm/vagrant-lxc/issues/5) diff --git a/README.md b/README.md index 3944669..4236112 100644 --- a/README.md +++ b/README.md @@ -139,14 +139,6 @@ for a list of [pre built](https://github.com/fgrehm/vagrant-lxc/wiki/Base-boxes# base boxes and information on [how to build your own](https://github.com/fgrehm/vagrant-lxc/wiki/Base-boxes#building-your-own). -## Current limitations - -* [Does not tell you if dependencies are not met](https://github.com/fgrehm/vagrant-lxc/issues/11) - (will probably just throw up some random error) -* + bunch of other [core features](https://github.com/fgrehm/vagrant-lxc/issues?labels=core&milestone=&page=1&state=open) - and some known [bugs](https://github.com/fgrehm/vagrant-lxc/issues?labels=bug&page=1&state=open) - - ## More information Please refer the [wiki](https://github.com/fgrehm/vagrant-lxc/wiki) for more diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index 1b63256..da76bf5 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -25,7 +25,6 @@ module Vagrant # machine back up with the new configuration. def self.action_reload Vagrant::Action::Builder.new.tap do |b| - # b.use CheckDependencies b.use Vagrant::Action::Builtin::Call, Created do |env1, b2| if !env1[:result] b2.use Message, :not_created @@ -44,7 +43,6 @@ module Vagrant # a bootup (i.e. not saved). def self.action_boot Vagrant::Action::Builder.new.tap do |b| - # b.use ClearForwardedPorts b.use Vagrant::Action::Builtin::Provision b.use Vagrant::Action::Builtin::EnvSet, :port_collision_repair => true b.use Vagrant::Action::Builtin::HandleForwardedPortCollisions @@ -58,7 +56,6 @@ module Vagrant # This action just runs the provisioners on the machine. def self.action_provision Vagrant::Action::Builder.new.tap do |b| - # b.use CheckDependencies b.use Vagrant::Action::Builtin::ConfigValidate b.use Vagrant::Action::Builtin::Call, Created do |env1, b2| if !env1[:result] @@ -82,7 +79,6 @@ module Vagrant # A precondition of this action is that the container exists. def self.action_start Vagrant::Action::Builder.new.tap do |b| - # b.use CheckDependencies b.use Vagrant::Action::Builtin::ConfigValidate b.use Vagrant::Action::Builtin::Call, IsRunning do |env, b2| # If the VM is running, then our work here is done, exit @@ -97,7 +93,6 @@ module Vagrant # container, configuring metadata, and booting. def self.action_up Vagrant::Action::Builder.new.tap do |b| - # b.use CheckDependencies b.use Vagrant::Action::Builtin::ConfigValidate b.use Vagrant::Action::Builtin::Call, Created do |env, b2| # If the VM is NOT created yet, then do the setup steps @@ -115,7 +110,6 @@ module Vagrant # the virtual machine, gracefully or by force. def self.action_halt Vagrant::Action::Builder.new.tap do |b| - # b.use CheckDependencies b.use Vagrant::Action::Builtin::Call, Created do |env, b2| if env[:result] # TODO: Remove this on / after 0.4 @@ -138,7 +132,6 @@ module Vagrant # freeing the resources of the underlying virtual machine. def self.action_destroy Vagrant::Action::Builder.new.tap do |b| - # b.use CheckDependencies b.use Vagrant::Action::Builtin::Call, Created do |env1, b2| if !env1[:result] b2.use Message, :not_created @@ -162,7 +155,6 @@ module Vagrant # This action packages the virtual machine into a single box file. def self.action_package Vagrant::Action::Builder.new.tap do |b| - # b.use CheckDependencies b.use Vagrant::Action::Builtin::Call, Created do |env1, b2| if !env1[:result] b2.use Message, :not_created @@ -180,7 +172,6 @@ module Vagrant # This is the action that will exec into an SSH shell. def self.action_ssh Vagrant::Action::Builder.new.tap do |b| - # b.use CheckDependencies b.use CheckCreated b.use CheckRunning b.use Vagrant::Action::Builtin::SSHExec @@ -190,7 +181,6 @@ module Vagrant # This is the action that will run a single SSH command. def self.action_ssh_run Vagrant::Action::Builder.new.tap do |b| - # b.use CheckDependencies b.use CheckCreated b.use CheckRunning b.use Vagrant::Action::Builtin::SSHRun diff --git a/lib/vagrant-lxc/errors.rb b/lib/vagrant-lxc/errors.rb index 3ec0531..c920465 100644 --- a/lib/vagrant-lxc/errors.rb +++ b/lib/vagrant-lxc/errors.rb @@ -7,6 +7,10 @@ module Vagrant error_key(:lxc_execute_error) end + class LxcNotInstalled < Vagrant::Errors::VagrantError + error_key(:lxc_not_installed) + end + # Box related errors class TemplateFileMissing < Vagrant::Errors::VagrantError error_key(:lxc_template_file_missing) diff --git a/lib/vagrant-lxc/provider.rb b/lib/vagrant-lxc/provider.rb index d8ea0ac..8c48e3c 100644 --- a/lib/vagrant-lxc/provider.rb +++ b/lib/vagrant-lxc/provider.rb @@ -14,6 +14,7 @@ module Vagrant @logger = Log4r::Logger.new("vagrant::provider::lxc") @machine = machine + ensure_lxc_installed! machine_id_changed end @@ -25,6 +26,12 @@ module Vagrant end end + def ensure_lxc_installed! + unless system("which lxc-version > /dev/null") + raise Errors::LxcNotInstalled + end + end + # If the machine ID changed, then we need to rebuild our underlying # container. def machine_id_changed diff --git a/locales/en.yml b/locales/en.yml index ee5b7b6..4690205 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -45,5 +45,8 @@ en: The template file used for creating the container was not found for %{name} box. + lxc_not_installed: |- + The `lxc` package does not seem to be installed or is not accessible on the PATH. + lxc_redir_not_installed: |- `redir` is not installed or is not accessible on the PATH.