core: Implement support for built in synced folders and add required logic for NFS
This commit is contained in:
parent
056e47d364
commit
d5abb523de
4 changed files with 103 additions and 3 deletions
|
@ -15,9 +15,10 @@ require 'vagrant-lxc/action/forward_ports'
|
|||
require 'vagrant-lxc/action/handle_box_metadata'
|
||||
require 'vagrant-lxc/action/is_running'
|
||||
require 'vagrant-lxc/action/message'
|
||||
require 'vagrant-lxc/action/prepare_nfs_settings'
|
||||
require 'vagrant-lxc/action/prepare_nfs_valid_ids'
|
||||
require 'vagrant-lxc/action/remove_temporary_files'
|
||||
require 'vagrant-lxc/action/setup_package_files'
|
||||
require 'vagrant-lxc/action/share_folders'
|
||||
require 'vagrant-lxc/action/warn_networks'
|
||||
|
||||
unless Vagrant::Backports.vagrant_1_3_or_later?
|
||||
|
@ -59,7 +60,15 @@ module Vagrant
|
|||
b.use Builtin::Provision
|
||||
b.use Builtin::EnvSet, :port_collision_repair => true
|
||||
b.use Builtin::HandleForwardedPortCollisions
|
||||
b.use ShareFolders
|
||||
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/action/share_folders'
|
||||
b.use ShareFolders
|
||||
end
|
||||
b.use Builtin::SetHostname
|
||||
b.use WarnNetworks
|
||||
b.use ForwardPorts
|
||||
|
|
64
lib/vagrant-lxc/action/prepare_nfs_settings.rb
Normal file
64
lib/vagrant-lxc/action/prepare_nfs_settings.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
module Vagrant
|
||||
module LXC
|
||||
module Action
|
||||
class PrepareNFSSettings
|
||||
include Vagrant::Util::Retryable
|
||||
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
@logger = Log4r::Logger.new("vagrant::action::vm::nfs")
|
||||
end
|
||||
|
||||
def call(env)
|
||||
@machine = env[:machine]
|
||||
|
||||
@app.call(env)
|
||||
|
||||
# if using_nfs? # TODO: && !privileged_container?
|
||||
# raise Errors::NfsWithoutPrivilegedError
|
||||
# end
|
||||
|
||||
if using_nfs?
|
||||
@logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP")
|
||||
add_ips_to_env!(env)
|
||||
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
|
||||
|
||||
# TODO:
|
||||
# def privileged_container?
|
||||
# @machine.provider.driver.privileged?(@machine.id)
|
||||
# end
|
||||
|
||||
# Extracts the proper host and guest IPs for NFS mounts and stores them
|
||||
# in the environment for the SyncedFolder action to use them in
|
||||
# mounting.
|
||||
#
|
||||
# The ! indicates that this method modifies its argument.
|
||||
def add_ips_to_env!(env)
|
||||
provider = @machine.provider
|
||||
|
||||
host_ip = read_host_ip
|
||||
machine_ip = provider.ssh_info[:host]
|
||||
|
||||
raise Vagrant::Errors::NFSNoHostonlyNetwork if !host_ip || !machine_ip
|
||||
|
||||
env[:nfs_host_ip] = host_ip
|
||||
env[:nfs_machine_ip] = machine_ip
|
||||
end
|
||||
|
||||
def read_host_ip
|
||||
@machine.communicate.execute 'echo $SSH_CLIENT' do |buffer, output|
|
||||
return output.chomp.split(' ')[0] if buffer == :stdout
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
lib/vagrant-lxc/action/prepare_nfs_valid_ids.rb
Normal file
19
lib/vagrant-lxc/action/prepare_nfs_valid_ids.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
module Vagrant
|
||||
module LXC
|
||||
module Action
|
||||
class PrepareNFSValidIds
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
@logger = Log4r::Logger.new("vagrant::action::vm::nfs")
|
||||
end
|
||||
|
||||
def call(env)
|
||||
machine = env[:machine]
|
||||
env[:nfs_valid_ids] = machine.provider.driver.all_containers
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -31,6 +31,10 @@ module Vagrant
|
|||
raise ContainerNotFound if @container_name && ! @cli.list.include?(@container_name)
|
||||
end
|
||||
|
||||
def all_containers
|
||||
@cli.list
|
||||
end
|
||||
|
||||
def base_path
|
||||
Pathname.new("#{CONTAINERS_PATH}/#{@container_name}")
|
||||
end
|
||||
|
@ -68,10 +72,14 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
@customizations << ['mount.entry', "#{folder[:hostpath]} #{guestpath} none bind 0 0"]
|
||||
share_folder(folder[:hostpath], guestpath)
|
||||
end
|
||||
end
|
||||
|
||||
def share_folder(host_path, guest_path)
|
||||
@customizations << ['mount.entry', "#{host_path} #{guest_path} none bind 0 0"]
|
||||
end
|
||||
|
||||
def start(customizations)
|
||||
@logger.info('Starting container...')
|
||||
|
||||
|
|
Loading…
Reference in a new issue