👋 to support for Vagrant < 1.5
This commit is contained in:
parent
622366bd64
commit
67523019aa
11 changed files with 19 additions and 251 deletions
|
@ -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:
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
# vagrant-backports
|
||||
|
||||
<!--
|
||||
[![Build Status](https://travis-ci.org/fgrehm/vagrant-backports.png?branch=master)](https://travis-ci.org/fgrehm/vagrant-backports) [![Gem Version](https://badge.fury.io/rb/vagrant-backports.png)](http://badge.fury.io/rb/vagrant-backports) [![Code Climate](https://codeclimate.com/github/fgrehm/vagrant-backports.png)](https://codeclimate.com/github/fgrehm/vagrant-backports) [![Coverage Status](https://coveralls.io/repos/fgrehm/vagrant-backports/badge.png?branch=master)](https://coveralls.io/r/fgrehm/vagrant-backports) [![Gittip](http://img.shields.io/gittip/fgrehm.svg)](https://www.gittip.com/fgrehm/)
|
||||
-->
|
||||
|
||||
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.
|
|
@ -1 +0,0 @@
|
|||
Vagrant::Action::Builtin.const_set :HandleBox, Vagrant::Action::Builtin::HandleBoxUrl
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue