Skip to content

Commit

Permalink
Issue #69 Handling of vagrant-registration action hooks depending on …
Browse files Browse the repository at this point in the history
…used provider

For VirtualBox we hook after VagrantPlugins::ProviderVirtualBox::Action::WaitForCommunicator and
for libvirt we use WaitTillUp
  • Loading branch information
hferentschik committed Mar 23, 2016
1 parent eeb9d8c commit 99c47eb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
8 changes: 2 additions & 6 deletions lib/vagrant-registration/action/register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ def initialize(app, _)
end

def call(env)
# Vbguest plugin (if present) is called next. Therefore registration
# needs to be done first. This does not work with the default
# 'action_register' hook.
@app.call(env) unless Plugin.vbguest_plugin?

# Configuration from Vagrantfile
config = env[:machine].config.registration
machine = env[:machine]
Expand All @@ -42,7 +37,8 @@ def call(env)

@logger.debug('Registration is skipped due to the configuration') if config.skip

@app.call(env) if Plugin.vbguest_plugin?
# Call next middleware in chain
@app.call(env)
end

private
Expand Down
42 changes: 26 additions & 16 deletions lib/vagrant-registration/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,28 @@ module Registration
class Plugin < Vagrant.plugin('2')
class << self

# Vbguest plugin updates GuestAdditions for VirtualBox before
# '::Vagrant::Action::Builtin::SyncedFolders' and therefore needs
# to be registered. Prepending Vbguest hook ensures that, but this
# is done only with Vbguest plugin and VirtualBox provider. In other
# cases the behavior is unchanged.
# vagrant-vbguest plugin updates GuestAdditions for VirtualBox
# and therefore needs to be run after the box got registered.
# See https://github.com/projectatomic/adb-vagrant-registration/issues/69
#
# vagrant-vbguest hooks before VagrantPlugins::ProviderVirtualBox::Action::CheckGuestAdditions
# (see https://github.com/mitchellh/vagrant/blob/master/plugins/providers/virtualbox/action.rb#L81)
# For registration to occur in time, it has to happen before that. Using WaitForCommunicator
# to be sure - https://github.com/dotless-de/vagrant-vbguest/blob/master/lib/vagrant-vbguest.rb#L53
#
# For vagrant-libvirt WaitTillUp is used
def register(hook)
setup_logging

if vbguest_plugin?
hook.before(::VagrantVbguest::Middleware,
VagrantPlugins::Registration::Action.action_register)
if virtual_box?
hook.after(VagrantPlugins::ProviderVirtualBox::Action::WaitForCommunicator,
VagrantPlugins::Registration::Action.action_register)
elsif libvirt?
hook.after(VagrantPlugins::ProviderLibvirt::Action::WaitTillUp,
VagrantPlugins::Registration::Action.action_register)
else
hook.after(::Vagrant::Action::Builtin::SyncedFolders,
VagrantPlugins::Registration::Action.action_register)
hook.after(Vagrant::Action::Builtin::WaitForCommunicator,
VagrantPlugins::Registration::Action.action_register)
end
end

Expand Down Expand Up @@ -87,12 +95,14 @@ def self.setup_logging
end
end

# Determines if both VirtualBox provider and Vbguest plugin are present.
def self.vbguest_plugin?
@@vbguest_plugin ||= (
defined?(VagrantPlugins::ProviderVirtualBox::Provider) &&
defined?(VagrantVbguest::Middleware)
)
# Determines if VirtualBox is provider
def self.virtual_box?
defined?(VagrantPlugins::ProviderVirtualBox::Provider)
end

# Determines if LibVirt is provider
def self.libvirt?
defined?(VagrantPlugins::ProviderLibvirt::Provider)
end
end
end
Expand Down

0 comments on commit 99c47eb

Please sign in to comment.