From 67523019aa2f7ebe08f33949b8825b99cdd93074 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Wed, 7 Jan 2015 23:42:07 -0200 Subject: [PATCH] :wave: to support for Vagrant < 1.5 --- CHANGELOG.md | 7 ++ lib/vagrant-backports/README.md | 12 ---- lib/vagrant-backports/action/handle_box.rb | 1 - lib/vagrant-backports/action/is_state.rb | 34 ---------- lib/vagrant-backports/action/message.rb | 20 ------ .../action/wait_for_communicator.rb | 42 ------------ lib/vagrant-backports/ui.rb | 12 ---- lib/vagrant-backports/utils.rb | 27 -------- lib/vagrant-lxc/action.rb | 27 ++------ .../backports/action/share_folders.rb | 67 ------------------- lib/vagrant-lxc/plugin.rb | 21 ++---- 11 files changed, 19 insertions(+), 251 deletions(-) delete mode 100644 lib/vagrant-backports/README.md delete mode 100644 lib/vagrant-backports/action/handle_box.rb delete mode 100644 lib/vagrant-backports/action/is_state.rb delete mode 100644 lib/vagrant-backports/action/message.rb delete mode 100644 lib/vagrant-backports/action/wait_for_communicator.rb delete mode 100644 lib/vagrant-backports/ui.rb delete mode 100644 lib/vagrant-backports/utils.rb delete mode 100644 lib/vagrant-lxc/backports/action/share_folders.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ecd852..d861fff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [1.1.0](https://github.com/fgrehm/vagrant-lxc/compare/v1.0.1...master) (unreleased) + +BACKWARDS INCOMPATIBILITIES: + + - Support for Vagrant versions prior to 1.5 have been removed. + + ## [1.0.1](https://github.com/fgrehm/vagrant-lxc/compare/v1.0.0...v1.0.1) (Oct 15, 2014) IMPROVEMENTS: diff --git a/lib/vagrant-backports/README.md b/lib/vagrant-backports/README.md deleted file mode 100644 index 0d6f2d2..0000000 --- a/lib/vagrant-backports/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# vagrant-backports - - - -A _"hypothetical"_ gem that helps Vagrant plugin developers to stay sane when -keeping up with Vagrant improvements by backporting parts of its recent versions -functionality. - -More information will be provided if there is enough interest on having this -extracted as a separate gem. diff --git a/lib/vagrant-backports/action/handle_box.rb b/lib/vagrant-backports/action/handle_box.rb deleted file mode 100644 index 56c6c91..0000000 --- a/lib/vagrant-backports/action/handle_box.rb +++ /dev/null @@ -1 +0,0 @@ -Vagrant::Action::Builtin.const_set :HandleBox, Vagrant::Action::Builtin::HandleBoxUrl diff --git a/lib/vagrant-backports/action/is_state.rb b/lib/vagrant-backports/action/is_state.rb deleted file mode 100644 index 8d956f5..0000000 --- a/lib/vagrant-backports/action/is_state.rb +++ /dev/null @@ -1,34 +0,0 @@ -module Vagrant - module Backports - module Action - # This middleware is meant to be used with Call and can check if - # a machine is in the given state ID. - class IsState - # Note: Any of the arguments can be arrays as well. - # - # @param [Symbol] target_state The target state ID that means that - # the machine was properly shut down. - # @param [Symbol] source_state The source state ID that the machine - # must be in to be shut down. - def initialize(app, env, check, **opts) - @app = app - @logger = Log4r::Logger.new("vagrant::action::builtin::is_state") - @check = check - @invert = !!opts[:invert] - end - - def call(env) - @logger.debug("Checking if machine state is '#{@check}'") - state = env[:machine].state.id - @logger.debug("-- Machine state: #{state}") - - env[:result] = @check == state - env[:result] = !env[:result] if @invert - @app.call(env) - end - end - end - end -end - -Vagrant::Action::Builtin.const_set :IsState, Vagrant::Backports::Action::IsState diff --git a/lib/vagrant-backports/action/message.rb b/lib/vagrant-backports/action/message.rb deleted file mode 100644 index 1bf7a15..0000000 --- a/lib/vagrant-backports/action/message.rb +++ /dev/null @@ -1,20 +0,0 @@ -module Vagrant - module Backports - module Action - # This middleware simply outputs a message to the UI. - class Message - def initialize(app, env, message, **opts) - @app = app - @message = message - end - - def call(env) - env[:ui].info(@message) - @app.call(env) - end - end - end - end -end - -Vagrant::Action::Builtin.const_set :Message, Vagrant::Backports::Action::Message diff --git a/lib/vagrant-backports/action/wait_for_communicator.rb b/lib/vagrant-backports/action/wait_for_communicator.rb deleted file mode 100644 index 39b349b..0000000 --- a/lib/vagrant-backports/action/wait_for_communicator.rb +++ /dev/null @@ -1,42 +0,0 @@ -# This acts like a backport of Vagrant's built in action from 1.3+ for previous version -# https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/action/builtin/wait_for_communicator.rb -module Vagrant - module Backports - module Action - class WaitForCommunicator - def initialize(app, env) - @app = app - end - - def call(env) - @env = env - - raise Vagrant::Errors::VMFailedToBoot if !wait_for_communicator - - @app.call env - end - - def wait_for_communicator - max_tries = @env[:machine].config.ssh.max_tries.to_i - max_tries.times do |i| - if @env[:machine].communicate.ready? - @env[:ui].info 'Machine booted and ready!' - return true - end - - # Return true so that the vm_failed_to_boot error doesn't - # get shown - return true if @env[:interrupted] - - sleep 1 if !@env["vagrant.test"] - end - - @env[:ui].error I18n.t("vagrant.actions.vm.boot.failed") - false - end - end - end - end -end - -Vagrant::Action::Builtin.const_set :WaitForCommunicator, Vagrant::Backports::Action::WaitForCommunicator diff --git a/lib/vagrant-backports/ui.rb b/lib/vagrant-backports/ui.rb deleted file mode 100644 index f29c5c0..0000000 --- a/lib/vagrant-backports/ui.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Vagrant - module UI - class Interface - def output(*args) - info(*args) - end - def detail(*args) - info(*args) - end - end - end -end diff --git a/lib/vagrant-backports/utils.rb b/lib/vagrant-backports/utils.rb deleted file mode 100644 index ca09514..0000000 --- a/lib/vagrant-backports/utils.rb +++ /dev/null @@ -1,27 +0,0 @@ -module Vagrant - module Backports - class << self - def vagrant_1_2_or_later? - greater_than?('1.2.0') - end - - def vagrant_1_3_or_later? - greater_than?('1.3.0') - end - - def vagrant_1_4_or_later? - greater_than?('1.4.0') - end - - def vagrant_1_5_or_later? - greater_than?('1.5.0') - end - - private - - def greater_than?(version) - Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new(version) - end - end - end -end diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index 74370a9..851adc3 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -15,16 +15,6 @@ require 'vagrant-lxc/action/remove_temporary_files' require 'vagrant-lxc/action/setup_package_files' require 'vagrant-lxc/action/warn_networks' -unless Vagrant::Backports.vagrant_1_3_or_later? - require 'vagrant-backports/action/wait_for_communicator' -end -unless Vagrant::Backports.vagrant_1_5_or_later? - require 'vagrant-backports/ui' - require 'vagrant-backports/action/handle_box' - require 'vagrant-backports/action/message' - require 'vagrant-backports/action/is_state' -end - module Vagrant module LXC module Action @@ -57,15 +47,10 @@ module Vagrant b.use Builtin::Provision b.use Builtin::EnvSet, :port_collision_repair => true b.use Builtin::HandleForwardedPortCollisions - if Vagrant::Backports.vagrant_1_4_or_later? - b.use PrepareNFSValidIds - b.use Builtin::SyncedFolderCleanup - b.use Builtin::SyncedFolders - b.use PrepareNFSSettings - else - require 'vagrant-lxc/backports/action/share_folders' - b.use ShareFolders - end + b.use PrepareNFSValidIds + b.use Builtin::SyncedFolderCleanup + b.use Builtin::SyncedFolders + b.use PrepareNFSSettings b.use Builtin::SetHostname b.use WarnNetworks b.use ForwardPorts @@ -165,9 +150,7 @@ module Vagrant b3.use Builtin::EnvSet, :force_halt => true b3.use action_halt b3.use Destroy - if Vagrant::Backports.vagrant_1_3_or_later? - b3.use Builtin::ProvisionerCleanup - end + b3.use Builtin::ProvisionerCleanup else b3.use Builtin::Message, I18n.t("vagrant_lxc.messages.will_not_destroy") end diff --git a/lib/vagrant-lxc/backports/action/share_folders.rb b/lib/vagrant-lxc/backports/action/share_folders.rb deleted file mode 100644 index 2fb582f..0000000 --- a/lib/vagrant-lxc/backports/action/share_folders.rb +++ /dev/null @@ -1,67 +0,0 @@ -module Vagrant - module LXC - module Action - class ShareFolders - def initialize(app, env) - @app = app - end - - def call(env) - @env = env - prepare_folders - add_override_configs - @app.call env - end - - # This method returns an actual list of synced folders to create and their - # proper path. - def shared_folders - {}.tap do |result| - @env[:machine].config.vm.synced_folders.each do |id, data| - # Ignore disabled shared folders - next if data[:disabled] - # This to prevent overwriting the actual shared folders data - result[id] = data.dup - end - end - end - - # Prepares the shared folders by verifying they exist and creating them - # if they don't. - def prepare_folders - shared_folders.each do |id, options| - hostpath = Pathname.new(options[:hostpath]).expand_path(@env[:root_path]) - - if !hostpath.directory? && options[:create] - # Host path doesn't exist, so let's create it. - @logger.debug("Host path doesn't exist, creating: #{hostpath}") - - begin - hostpath.mkpath - rescue Errno::EACCES - raise Vagrant::Errors::SharedFolderCreateFailed, - :path => hostpath.to_s - end - end - end - end - - def add_override_configs - @env[:ui].info I18n.t("vagrant.actions.lxc.share_folders.preparing") - - folders = [] - shared_folders.each do |id, data| - folders << { - :name => id, - :hostpath => File.expand_path(data[:hostpath], @env[:root_path]), - :guestpath => data[:guestpath] - } - @env[:ui].info(I18n.t("vagrant.actions.vm.share_folders.mounting_entry", - :guest_path => data[:guestpath])) - end - @env[:machine].provider.driver.share_folders(folders) - end - end - end - end -end diff --git a/lib/vagrant-lxc/plugin.rb b/lib/vagrant-lxc/plugin.rb index 1a8651b..31d3adf 100644 --- a/lib/vagrant-lxc/plugin.rb +++ b/lib/vagrant-lxc/plugin.rb @@ -1,5 +1,4 @@ require 'vagrant' -require 'vagrant-backports/utils' module Vagrant module LXC @@ -10,9 +9,7 @@ module Vagrant LXC-based virtual machines. EOF - extra = [] - extra << {parallel: true} if Vagrant::Backports.vagrant_1_2_or_later? - provider(:lxc, *extra) do + provider(:lxc, parallel: true) do require File.expand_path("../provider", __FILE__) I18n.load_path << File.expand_path(File.dirname(__FILE__) + '/../../locales/en.yml') @@ -31,18 +28,14 @@ module Vagrant Config end - if Vagrant::Backports.vagrant_1_4_or_later? - synced_folder(:lxc) do - require File.expand_path("../synced_folder", __FILE__) - SyncedFolder - end + synced_folder(:lxc) do + require File.expand_path("../synced_folder", __FILE__) + SyncedFolder end - if Vagrant::Backports.vagrant_1_5_or_later? - provider_capability("lxc", "public_address") do - require_relative "provider/cap/public_address" - Provider::Cap::PublicAddress - end + provider_capability("lxc", "public_address") do + require_relative "provider/cap/public_address" + Provider::Cap::PublicAddress end end end