vagrant-nfs_guest_vbfix 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.ruby-version +1 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +84 -0
- data/Rakefile +3 -0
- data/example_box/Vagrantfile +26 -0
- data/example_box/vagrant_share/.keep +0 -0
- data/lib/vagrant-nfs_guest.rb +20 -0
- data/lib/vagrant-nfs_guest/action/mount_nfs.rb +64 -0
- data/lib/vagrant-nfs_guest/action/unmount_nfs.rb +28 -0
- data/lib/vagrant-nfs_guest/config.rb +32 -0
- data/lib/vagrant-nfs_guest/errors.rb +33 -0
- data/lib/vagrant-nfs_guest/guests/debian/cap/nfs_server.rb +24 -0
- data/lib/vagrant-nfs_guest/guests/debian/plugin.rb +25 -0
- data/lib/vagrant-nfs_guest/guests/linux/cap/nfs_server.rb +170 -0
- data/lib/vagrant-nfs_guest/guests/linux/cap/read_user_ids.rb +29 -0
- data/lib/vagrant-nfs_guest/guests/linux/plugin.rb +50 -0
- data/lib/vagrant-nfs_guest/guests/redhat/cap/nfs_server.rb +85 -0
- data/lib/vagrant-nfs_guest/guests/redhat/plugin.rb +35 -0
- data/lib/vagrant-nfs_guest/guests/ubuntu/cap/nfs_server.rb +18 -0
- data/lib/vagrant-nfs_guest/guests/ubuntu/plugin.rb +20 -0
- data/lib/vagrant-nfs_guest/hosts/bsd/cap/mount_nfs.rb +34 -0
- data/lib/vagrant-nfs_guest/hosts/bsd/cap/unmount_nfs.rb +35 -0
- data/lib/vagrant-nfs_guest/hosts/bsd/plugin.rb +20 -0
- data/lib/vagrant-nfs_guest/hosts/linux/cap/mount_nfs.rb +34 -0
- data/lib/vagrant-nfs_guest/hosts/linux/cap/unmount_nfs.rb +36 -0
- data/lib/vagrant-nfs_guest/hosts/linux/plugin.rb +20 -0
- data/lib/vagrant-nfs_guest/plugin.rb +109 -0
- data/lib/vagrant-nfs_guest/providers/docker/cap/nfs_settings.rb +19 -0
- data/lib/vagrant-nfs_guest/providers/docker/plugin.rb +15 -0
- data/lib/vagrant-nfs_guest/providers/parallels/cap/nfs_settings.rb +17 -0
- data/lib/vagrant-nfs_guest/providers/parallels/plugin.rb +15 -0
- data/lib/vagrant-nfs_guest/providers/virtualbox/cap/nfs_settings.rb +89 -0
- data/lib/vagrant-nfs_guest/providers/virtualbox/plugin.rb +15 -0
- data/lib/vagrant-nfs_guest/synced_folder.rb +96 -0
- data/lib/vagrant-nfs_guest/version.rb +5 -0
- data/templates/locales/en.yml +69 -0
- data/templates/nfs_guest/guest_export_linux.erb +7 -0
- data/vagrant-nfs_guest.gemspec +23 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4795e050e128c0868a4d886dfc5a40646c6399cd
|
4
|
+
data.tar.gz: 8bafef786bdb6f24c384c477f714625f94afb60b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 84cd21286772e147640ca26b4bcddf220f67d090fe8e9aa62e8c43a10820e1100f30883d4e2e282bee067e1e8e696d421fec4b1b6ddb5c573bc1567f9bd704bd
|
7
|
+
data.tar.gz: 4e7cc40af53adcc800434bb8b6e5acd97cd2dc02928ca119c04e9beea789b43718117036256f8b5a539ab7da2fc6ba38f05badd82f17dc3cb0c6f95b6191079a
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.3
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
# We depend on Vagrant for development, but we don't add it as a
|
5
|
+
# gem dependency because we expect to be installed within the
|
6
|
+
# Vagrant environment itself using `vagrant plugin`.
|
7
|
+
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
|
8
|
+
end
|
9
|
+
|
10
|
+
group :plugins do
|
11
|
+
gem "vagrant-nfs_guest_vbfix", path: "."
|
12
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Alan Garfield
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Vagrant-NFS_Guest
|
2
|
+
|
3
|
+
## What's New?
|
4
|
+
|
5
|
+
- NEW: added untested support for Docker providers (Please raise any issues if they don't work!).
|
6
|
+
- NEW: added Parallels provider support
|
7
|
+
- NEW: Redhat/CentOS guest support added.
|
8
|
+
- FIXED: suspend and resume with 'up' instead of 'resume' fixed.
|
9
|
+
- Supports Vagrant > 1.6.
|
10
|
+
- Handles actions ```up```, ```halt```, ```destroy```, ```suspend```, ```resume``` and ```package``` properly.
|
11
|
+
- Uses retryable() for host to guest communications allow more fault tolerance.
|
12
|
+
- Better error messages and handling.
|
13
|
+
- Re-organisation of modules and class to better match Vagrant proper.
|
14
|
+
- Simplified the plugin events binding.
|
15
|
+
- Will install the NFS daemon on the guest if the guest capability is supported (Ubuntu and Debian only at this stage).
|
16
|
+
- Supports BSD/OSX, and Linux based Hosts that support NFS mounting.
|
17
|
+
|
18
|
+
## Overview
|
19
|
+
|
20
|
+
Allows a guest VM to export synced folders via NFS and the host to mount them.
|
21
|
+
|
22
|
+
Basically it's just the usual NFS synced folders in Vagrant but the roles are reversed.
|
23
|
+
|
24
|
+
Guest VMs we've tested include:
|
25
|
+
- Ubuntu (precise, trusty)
|
26
|
+
- CentOS (6.5, 6.6, 7)
|
27
|
+
- Debian (wheezy)
|
28
|
+
- other Linux based guests may work fine with the generic Linux support. But no guarantee
|
29
|
+
|
30
|
+
Hosts we've tested include:
|
31
|
+
- OSX (Mavericks, Yosemite, El Capitan)
|
32
|
+
- Ubuntu (precise, trusty)
|
33
|
+
- other Linux based OSs should work fine, but will need testing, again no guarantee
|
34
|
+
|
35
|
+
We're happy to receive pull-request to support alternatives hosts and guests. To implement this support it's relatively trivial if you look in ./lib/hosts and ./lib/guests.
|
36
|
+
|
37
|
+
## Installation
|
38
|
+
|
39
|
+
vagrant plugin install vagrant-nfs_guest
|
40
|
+
|
41
|
+
## Install from sources
|
42
|
+
|
43
|
+
git clone https://github.com/Learnosity/vagrant-nfs_guest.git
|
44
|
+
cd vagrant-nfs_guest
|
45
|
+
bundle install
|
46
|
+
bundle exec rake build
|
47
|
+
vagrant plugin install pkg/vagrant-nfs_guest-VERSION.gem
|
48
|
+
|
49
|
+
## Usage
|
50
|
+
|
51
|
+
To enable for example put similar in the Vagrantfile:
|
52
|
+
|
53
|
+
config.vm.synced_folder 'srv', '/srv', type: 'nfs_guest'
|
54
|
+
|
55
|
+
## Building
|
56
|
+
|
57
|
+
We use 'chruby' to allow a virtual ruby environment for developement. The 'bundle' gem is needed to build and run
|
58
|
+
|
59
|
+
git clone https://github.com/Learnosity/vagrant-nfs_guest.git
|
60
|
+
cd vagrant-nfs_guest
|
61
|
+
bundle install
|
62
|
+
bundle exec vagrant
|
63
|
+
|
64
|
+
You can test your handy work using the ```example_box``` by doing the following:
|
65
|
+
|
66
|
+
cd ./example_box/
|
67
|
+
bundle exec vagrant up
|
68
|
+
|
69
|
+
You can ssh into the test VM using:
|
70
|
+
|
71
|
+
bundle exec vagrant ssh
|
72
|
+
|
73
|
+
... and you can clean up with:
|
74
|
+
|
75
|
+
bundle exec vagrant destroy
|
76
|
+
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
1. Fork it
|
81
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
82
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
83
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
84
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
5
|
+
VAGRANTFILE_API_VERSION = "2"
|
6
|
+
|
7
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
8
|
+
|
9
|
+
# Every Vagrant virtual environment requires a box to build off of.
|
10
|
+
config.vm.box = "ubuntu/trusty64" # ubuntu
|
11
|
+
#config.vm.box = "centos/7" # centos/7
|
12
|
+
#config.vm.box = "nrel/CentOS-6.5-x86_64" # centos/6.5
|
13
|
+
|
14
|
+
# Create a private network, which allows host-only access to the machine
|
15
|
+
# using a specific IP.
|
16
|
+
config.vm.network "private_network", ip: "192.168.55.10"
|
17
|
+
|
18
|
+
# Share an additional folder to the guest VM. The first argument is
|
19
|
+
# the path on the host to the actual folder. The second argument is
|
20
|
+
# the path on the guest to mount the folder. And the optional third
|
21
|
+
# argument is a set of non-required options.
|
22
|
+
config.vm.synced_folder '.', '/vagrant', disabled: true
|
23
|
+
|
24
|
+
config.vm.synced_folder './vagrant_share', '/vagrant', type: 'nfs_guest'
|
25
|
+
|
26
|
+
end
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
require "vagrant-nfs_guest/plugin"
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module SyncedFolderNFSGuest
|
7
|
+
lib_path = Pathname.new(File.expand_path("../vagrant-nfs_guest", __FILE__))
|
8
|
+
autoload :Errors, lib_path.join("errors")
|
9
|
+
|
10
|
+
# This returns the path to the source of this plugin.
|
11
|
+
#
|
12
|
+
# @return [Pathname]
|
13
|
+
def self.source_root
|
14
|
+
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
|
15
|
+
end
|
16
|
+
|
17
|
+
I18n.load_path << File.expand_path("templates/locales/en.yml", source_root)
|
18
|
+
I18n.reload!
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module SyncedFolderNFSGuest
|
3
|
+
module Action
|
4
|
+
class MountNFS
|
5
|
+
|
6
|
+
def initialize(app,env)
|
7
|
+
@app = app
|
8
|
+
@logger = Log4r::Logger.new("vagrant-nfs_guest::action::unmount_nfs")
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
@machine = env[:machine]
|
13
|
+
|
14
|
+
# because we're hooked into Vagrant::Action::Builtin::SyncedFolders and
|
15
|
+
# Vagrant::Action::Builtin::WaitForCommunicator we need to figure out
|
16
|
+
# if we're 'up'ing from 'poweroff' or 'up'ing from 'suspend'
|
17
|
+
# If 'poweroff' we get called twice once with state.id = 'poweroff' and
|
18
|
+
# again with state.id = 'running'. This toggle around @app.call() allows
|
19
|
+
# the second call to actually do the mount after the SyncFolder setup
|
20
|
+
# has completed properly. If 'running' well then we just do the mount
|
21
|
+
# as we're obvioulsy coming from a 'suspended' instance. Stupid bug.
|
22
|
+
if !env[:nfs_guest_first_state]
|
23
|
+
env[:nfs_guest_first_state] = @machine.state.id
|
24
|
+
end
|
25
|
+
|
26
|
+
@app.call(env)
|
27
|
+
|
28
|
+
# ... and also deal with 'reload' :weary:
|
29
|
+
if env[:nfs_guest_first_state] == :poweroff and env[:action_name] != :machine_action_reload
|
30
|
+
env[:nfs_guest_first_state] = @machine.state.id
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
if @machine.state.id == :running
|
35
|
+
if !@machine.provider.capability?(:nfs_settings)
|
36
|
+
raise SyncedFolderNFSGuest::Errors::ProviderNFSSettingsCapMissing
|
37
|
+
end
|
38
|
+
|
39
|
+
# grab the ips from the provider
|
40
|
+
host_ip, machine_ip = @machine.provider.capability(:nfs_settings)
|
41
|
+
|
42
|
+
raise Vagrant::Errors::NFSNoHostIP if !host_ip
|
43
|
+
raise Vagrant::Errors::NFSNoGuestIP if !machine_ip
|
44
|
+
|
45
|
+
machine_ip = [machine_ip] if !machine_ip.is_a?(Array)
|
46
|
+
|
47
|
+
if @machine.config.nfs_guest.verify_installed
|
48
|
+
if @machine.guest.capability?(:nfs_server_installed)
|
49
|
+
installed = @machine.guest.capability(:nfs_server_installed)
|
50
|
+
if installed
|
51
|
+
# Mount guest NFS folders
|
52
|
+
@machine.ui.info(I18n.t("vagrant_nfs_guest.actions.vm.nfs.mounting"))
|
53
|
+
folders = @machine.config.vm.synced_folders
|
54
|
+
|
55
|
+
@machine.env.host.capability(:nfs_mount, @machine.ui, @machine.id, machine_ip, folders)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module SyncedFolderNFSGuest
|
3
|
+
module Action
|
4
|
+
class UnmountNFS
|
5
|
+
|
6
|
+
def initialize(app,env)
|
7
|
+
@app = app
|
8
|
+
@logger = Log4r::Logger.new("vagrant-nfs_guest::action::unmount_nfs")
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
@machine = env[:machine]
|
13
|
+
|
14
|
+
if @machine.state.id == :running
|
15
|
+
# unmount any host mounted NFS folders
|
16
|
+
@machine.ui.info(I18n.t("vagrant_nfs_guest.actions.vm.nfs.unmounting"))
|
17
|
+
folders = @machine.config.vm.synced_folders
|
18
|
+
|
19
|
+
@machine.env.host.capability(:nfs_unmount, @machine.ui, folders)
|
20
|
+
end
|
21
|
+
|
22
|
+
@app.call(env)
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module SyncedFolderNFSGuest
|
5
|
+
class Config < Vagrant.plugin("2", :config)
|
6
|
+
attr_accessor :functional
|
7
|
+
attr_accessor :map_uid
|
8
|
+
attr_accessor :map_gid
|
9
|
+
attr_accessor :verify_installed
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
|
14
|
+
@functional = UNSET_VALUE
|
15
|
+
@map_uid = UNSET_VALUE
|
16
|
+
@map_gid = UNSET_VALUE
|
17
|
+
@verify_installed = UNSET_VALUE
|
18
|
+
end
|
19
|
+
|
20
|
+
def finalize!
|
21
|
+
@functional = true if @functional == UNSET_VALUE
|
22
|
+
@map_uid = nil if @map_uid == UNSET_VALUE
|
23
|
+
@map_gid = nil if @map_gid == UNSET_VALUE
|
24
|
+
@verify_installed = true if @verify_installed == UNSET_VALUE
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
"NFS_Guest"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module SyncedFolderNFSGuest
|
5
|
+
module Errors
|
6
|
+
|
7
|
+
class Error < Vagrant::Errors::VagrantError
|
8
|
+
error_namespace("vagrant_nfs_guest.errors")
|
9
|
+
end
|
10
|
+
|
11
|
+
class GuestNFSError < Error
|
12
|
+
error_key(:nfs_server_missing)
|
13
|
+
error_key(:nfs_start_failed)
|
14
|
+
error_key(:nfs_apply_failed)
|
15
|
+
error_key(:nfs_update_exports_failed)
|
16
|
+
error_key(:nfs_guest_clean)
|
17
|
+
error_key(:nfs_create_mounts_failed)
|
18
|
+
end
|
19
|
+
|
20
|
+
class NFSServerMissing < Error
|
21
|
+
error_key(:nfs_server_missing)
|
22
|
+
end
|
23
|
+
|
24
|
+
class NFSServerNotInstalledInGuest < Error
|
25
|
+
error_key(:nfs_server_not_installed)
|
26
|
+
end
|
27
|
+
|
28
|
+
class ProviderNFSSettingsCapMissing < Error
|
29
|
+
error_key(:provider_missing_nfs_setting_cap)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module SyncedFolderNFSGuest
|
3
|
+
module GuestDebian
|
4
|
+
module Cap
|
5
|
+
class NFSServer
|
6
|
+
def self.nfs_server_install(machine)
|
7
|
+
machine.communicate.sudo("apt-get update")
|
8
|
+
machine.communicate.sudo("apt-get -y install nfs-kernel-server")
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.nfs_server_installed(machine)
|
12
|
+
machine.communicate.test("test -e /etc/init.d/nfs-kernel-server")
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.nfs_test_command(machine)
|
16
|
+
machine.communicate.test(
|
17
|
+
"test -x /usr/sbin/exportfs"
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module SyncedFolderNFSGuest
|
5
|
+
class Plugin < Vagrant.plugin("2")
|
6
|
+
name "Debian guest"
|
7
|
+
description "Debian guest support."
|
8
|
+
|
9
|
+
guest_capability(:debian, :nfs_test_command) do
|
10
|
+
require_relative "cap/nfs_server"
|
11
|
+
GuestDebian::Cap::NFSServer
|
12
|
+
end
|
13
|
+
|
14
|
+
guest_capability(:debian, :nfs_server_installed) do
|
15
|
+
require_relative "cap/nfs_server"
|
16
|
+
GuestDebian::Cap::NFSServer
|
17
|
+
end
|
18
|
+
|
19
|
+
guest_capability(:debian, :nfs_server_install) do
|
20
|
+
require_relative "cap/nfs_server"
|
21
|
+
GuestDebian::Cap::NFSServer
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require "vagrant/util/retryable"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module SyncedFolderNFSGuest
|
5
|
+
module GuestLinux
|
6
|
+
module Cap
|
7
|
+
class NFSServer
|
8
|
+
extend Vagrant::Util::Retryable
|
9
|
+
|
10
|
+
def self.nfs_apply_command(machine)
|
11
|
+
machine.communicate.sudo(
|
12
|
+
"exportfs -r",
|
13
|
+
error_class: Errors::GuestNFSError,
|
14
|
+
error_key: :nfs_apply_failed
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.nfs_start_command(machine)
|
19
|
+
machine.communicate.sudo(
|
20
|
+
"/etc/init.d/nfs-kernel-server start",
|
21
|
+
error_class: Errors::GuestNFSError,
|
22
|
+
error_key: :nfs_start_failed
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.nfs_check_command(machine)
|
27
|
+
machine.communicate.test(
|
28
|
+
"/etc/init.d/nfs-kernel-server status"
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.nfs_test_command(machine)
|
33
|
+
machine.communicate.test(
|
34
|
+
"which exportfs"
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.nfs_exports_template(machine)
|
39
|
+
VagrantPlugins::SyncedFolderNFSGuest.source_root.join(
|
40
|
+
"templates/nfs_guest/guest_export_linux")
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.nfs_capable?(machine)
|
44
|
+
machine.guest.capability(:nfs_test_command)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.nfs_apply_changes!(machine)
|
48
|
+
machine.guest.capability(:nfs_apply_command)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.nfs_start!(machine)
|
52
|
+
machine.guest.capability(:nfs_start_command)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.nfs_running?(machine)
|
56
|
+
machine.guest.capability(:nfs_check_command)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.nfs_export(machine, ip, folders)
|
60
|
+
if !nfs_capable?(machine)
|
61
|
+
raise Errors::NFSServerMissing
|
62
|
+
end
|
63
|
+
|
64
|
+
if machine.guest.capability?(:nfs_setup_firewall)
|
65
|
+
machine.ui.info I18n.t("vagrant_nfs_guest.guests.linux.nfs_setup_firewall")
|
66
|
+
machine.guest.capability(:nfs_setup_firewall, ip)
|
67
|
+
end
|
68
|
+
|
69
|
+
nfs_exports_template = machine.guest.capability(:nfs_exports_template)
|
70
|
+
|
71
|
+
nfs_opts_setup(machine, folders)
|
72
|
+
|
73
|
+
output = Vagrant::Util::TemplateRenderer.render(
|
74
|
+
nfs_exports_template,
|
75
|
+
uuid: machine.id,
|
76
|
+
ips: [ip],
|
77
|
+
folders: folders,
|
78
|
+
user: Process.uid)
|
79
|
+
|
80
|
+
machine.ui.info I18n.t("vagrant_nfs_guest.guests.linux.nfs_export")
|
81
|
+
sleep 0.5
|
82
|
+
|
83
|
+
nfs_cleanup(machine)
|
84
|
+
|
85
|
+
retryable(on: Errors::GuestNFSError, tries: 8, sleep: 3) do
|
86
|
+
output.split("\n").each do |line|
|
87
|
+
machine.communicate.sudo(
|
88
|
+
%Q[echo '#{line}' >> /etc/exports],
|
89
|
+
error_class: Errors::GuestNFSError,
|
90
|
+
error_key: :nfs_update_exports_failed
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
if nfs_running?(machine)
|
95
|
+
nfs_apply_changes!(machine)
|
96
|
+
else
|
97
|
+
nfs_start!(machine)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.nfs_cleanup(machine)
|
103
|
+
return if !nfs_capable?(machine)
|
104
|
+
|
105
|
+
id = machine.id
|
106
|
+
user = Process.uid
|
107
|
+
|
108
|
+
# Use sed to just strip out the block of code which was inserted
|
109
|
+
# by Vagrant
|
110
|
+
#
|
111
|
+
machine.communicate.sudo(
|
112
|
+
"sed -r -e '/^# VAGRANT(-NFS_GUEST)?-BEGIN/,/^# VAGRANT(-NFS_GUEST)?-END/ d' -ibak /etc/exports",
|
113
|
+
error_class: Errors::GuestNFSError,
|
114
|
+
error_key: :nfs_guest_clean
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.nfs_opts_setup(machine, folders)
|
119
|
+
folders.each do |k, opts|
|
120
|
+
if !opts[:linux__nfs_options]
|
121
|
+
opts[:linux__nfs_options] ||= ["rw", "no_subtree_check", "all_squash", "insecure"]
|
122
|
+
end
|
123
|
+
|
124
|
+
# Only automatically set anonuid/anongid if they weren't
|
125
|
+
# explicitly set by the user.
|
126
|
+
hasgid = false
|
127
|
+
hasuid = false
|
128
|
+
opts[:linux__nfs_options].each do |opt|
|
129
|
+
hasgid = !!(opt =~ /^anongid=/) if !hasgid
|
130
|
+
hasuid = !!(opt =~ /^anonuid=/) if !hasuid
|
131
|
+
end
|
132
|
+
|
133
|
+
opts[:linux__nfs_options] << "anonuid=#{opts[:map_uid]}" if !hasuid
|
134
|
+
opts[:linux__nfs_options] << "anongid=#{opts[:map_gid]}" if !hasgid
|
135
|
+
opts[:linux__nfs_options] << "fsid=#{opts[:uuid]}"
|
136
|
+
|
137
|
+
# Expand the guest path so we can handle things like "~/vagrant"
|
138
|
+
expanded_guest_path = machine.guest.capability(
|
139
|
+
:shell_expand_guest_path, opts[:guestpath])
|
140
|
+
|
141
|
+
retryable(on: Errors::GuestNFSError, tries: 8, sleep: 3) do
|
142
|
+
# Do the actual creating and mounting
|
143
|
+
machine.communicate.sudo(
|
144
|
+
"mkdir -p #{expanded_guest_path}",
|
145
|
+
error_class: Errors::GuestNFSError,
|
146
|
+
error_key: :nfs_create_mounts_failed
|
147
|
+
)
|
148
|
+
|
149
|
+
# Folder options
|
150
|
+
opts[:owner] ||= machine.ssh_info[:username]
|
151
|
+
opts[:group] ||= machine.ssh_info[:username]
|
152
|
+
|
153
|
+
machine.communicate.sudo(
|
154
|
+
"chown -R #{opts[:owner]}:#{opts[:group]} #{expanded_guest_path}",
|
155
|
+
error_class: Errors::GuestNFSError,
|
156
|
+
error_key: :nfs_create_mounts_failed
|
157
|
+
)
|
158
|
+
machine.communicate.sudo(
|
159
|
+
"chmod 2775 #{expanded_guest_path}",
|
160
|
+
error_class: Errors::GuestNFSError,
|
161
|
+
error_key: :nfs_create_mounts_failed
|
162
|
+
)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|