Cleanup nfs config for Vagrant 1.4+

Fix checks if a synced_folder should be nfs or not

Reorder up and start actions
This commit is contained in:
Jason DeTiberus 2014-01-23 13:46:44 -05:00
parent 54408733e0
commit 25fe1ea2c2
5 changed files with 50 additions and 27 deletions

View File

@ -1,10 +1,12 @@
require 'vagrant/action/builder'
require 'log4r'
module VagrantPlugins
module ProviderLibvirt
module Action
# Include the built-in modules so we can use them as top-level things.
include Vagrant::Action::Builtin
@logger = Log4r::Logger.new('vagrant_libvirt::action')
# This action is called to bring the box up from nothing.
def self.action_up
@ -25,9 +27,13 @@ module VagrantPlugins
b2.use CreateNetworks
b2.use CreateNetworkInterfaces
b2.use StartDomain
b2.use WaitTillUp
if Vagrant::VERSION < "1.4.0"
b2.use NFS
else
b2.use PrepareNFSValidIds
b2.use SyncedFolderCleanup
b2.use SyncedFolders
end
@ -35,8 +41,6 @@ module VagrantPlugins
b2.use PrepareNFSSettings
b2.use ShareFolders
b2.use SetHostname
b2.use StartDomain
b2.use WaitTillUp
b2.use SyncFolders
else
b2.use action_start
@ -68,22 +72,24 @@ module VagrantPlugins
# Ensure networks are created and active
b3.use CreateNetworks
# Handle shared folders
if Vagrant::VERSION < "1.4.0"
b3.use NFS
else
b3.use SyncedFolderCleanup
b3.use SyncedFolders
end
b3.use PrepareNFSSettings
b3.use ShareFolders
# Start it..
b3.use StartDomain
# Machine should gain IP address when comming up,
# so wait for dhcp lease and store IP into machines data_dir.
b3.use WaitTillUp
# Handle shared folders
if Vagrant::VERSION < "1.4.0"
b3.use NFS
else
b3.use PrepareNFSValidIds
b3.use SyncedFolderCleanup
b3.use SyncedFolders
end
b3.use PrepareNFSSettings
b3.use ShareFolders
end
end
end
@ -308,6 +314,7 @@ module VagrantPlugins
autoload :MessageNotRunning, action_root.join('message_not_running')
autoload :MessageNotSuspended, action_root.join('message_not_suspended')
autoload :PrepareNFSSettings, action_root.join('prepare_nfs_settings')
autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids')
autoload :PruneNFSExports, action_root.join('prune_nfs_exports')
autoload :ReadSSHInfo, action_root.join('read_ssh_info')
autoload :ReadState, action_root.join('read_state')

View File

@ -9,25 +9,27 @@ module VagrantPlugins
end
def call(env)
@machine = env[:machine]
@app.call(env)
using_nfs = false
env[:machine].config.vm.synced_folders.each do |id, opts|
if opts[:nfs]
using_nfs = true
break
end
end
if using_nfs
if using_nfs?
@logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP")
env[:nfs_host_ip] = read_host_ip(env[:machine],env)
env[:nfs_machine_ip] = env[:machine].ssh_info[:host]
raise Vagrant::Errors::NFSNoHostonlyNetwork if !env[:nfs_machine_ip]
@logger.info("host IP: #{env[:nfs_host_ip]} machine IP: #{env[:nfs_machine_ip]}")
raise Vagrant::Errors::NFSNoHostonlyNetwork if !env[:nfs_machine_ip] || !env[:nfs_host_ip]
end
end
# We're using NFS if we have any synced folder with NFS configured. If
# we are not using NFS we don't need to do the extra work to
# populate these fields in the environment.
def using_nfs?
@machine.config.vm.synced_folders.any? { |_, opts| opts[:type] == :nfs }
end
# Returns the IP address of the first host only network adapter
#
# @param [Machine] machine

View File

@ -0,0 +1,17 @@
module VagrantPlugins
module ProviderLibvirt
module Action
class PrepareNFSValidIds
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant::action::vm::nfs")
end
def call(env)
env[:nfs_valid_ids] = env[:libvirt_compute].servers.all.map(&:id)
@app.call(env)
end
end
end
end
end

View File

@ -26,10 +26,7 @@ module VagrantPlugins
{}.tap do |result|
@env[:machine].config.vm.synced_folders.each do |id, data|
# Ignore NFS shared folders
next if !data[:nfs]
# convert to NFS share
#data[:nfs] = true
next if !data[:type] == :nfs
# This to prevent overwriting the actual shared folders data
result[id] = data.dup

View File

@ -18,7 +18,7 @@ module VagrantPlugins
ssh_info = env[:machine].ssh_info
env[:machine].config.vm.synced_folders.each do |id, data|
next if data[:nfs]
next if data[:type] == :nfs
proxycommand = "-o ProxyCommand='#{ssh_info[:proxy_command]}'" if ssh_info[:proxy_command]
hostpath = File.expand_path(data[:hostpath], env[:root_path])
guestpath = data[:guestpath]