vagrant-nfs_guest 0.0.4 → 0.1.0
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/Gemfile +9 -5
- data/README.md +11 -0
- data/lib/vagrant-nfs_guest/action/mount_nfs.rb +39 -0
- data/lib/vagrant-nfs_guest/action/prepare_nfs_guest_settings.rb +27 -7
- data/lib/vagrant-nfs_guest/action/unmount_nfs.rb +31 -0
- data/lib/vagrant-nfs_guest/config.rb +5 -2
- data/lib/vagrant-nfs_guest/errors.rb +12 -2
- data/lib/vagrant-nfs_guest/guests/linux/cap/nfs_export.rb +141 -0
- data/lib/vagrant-nfs_guest/guests/linux/cap/read_user_ids.rb +27 -0
- data/lib/vagrant-nfs_guest/hosts/bsd/cap/mount_nfs.rb +31 -0
- data/lib/vagrant-nfs_guest/hosts/bsd/cap/unmount_nfs.rb +33 -0
- data/lib/vagrant-nfs_guest/hosts/bsd/plugin.rb +18 -0
- data/lib/vagrant-nfs_guest/plugin.rb +104 -25
- data/lib/vagrant-nfs_guest/synced_folder.rb +18 -16
- data/lib/vagrant-nfs_guest/version.rb +1 -1
- data/lib/vagrant-nfs_guest.rb +9 -15
- data/templates/locales/en.yml +43 -0
- data/templates/nfs_guest/guest_export_linux.erb +1 -1
- metadata +20 -31
- data/lib/vagrant-nfs_guest/action/unmount_mounts.rb +0 -20
- data/lib/vagrant-nfs_guest/cap/linux/export_nfs_folders.rb +0 -116
- data/lib/vagrant-nfs_guest/cap/linux/halt.rb +0 -20
- data/lib/vagrant-nfs_guest/cap/linux/read_user_ids.rb +0 -29
- data/lib/vagrant-nfs_guest/hosts/bsd/host.rb +0 -37
- data/lib/vagrant-nfs_guest/hosts/host.rb +0 -23
- data/locales/en.yml +0 -6
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dce3470eb4d34a59abc8737fa5163830ab382f2f
|
4
|
+
data.tar.gz: b81fd5ff295c881ec9c6ee377010970bdca3bc5a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a32e270cbdb9481d83a7f213986b6927ac7c3c28cbad7a7cea979ba1969b0076cab824f7255418e8927140bca1a410a6fea9fb447839e6802668dee69d46d46
|
7
|
+
data.tar.gz: b5b32a5a565c58420ad3c2d733740f073f208914c25a8c2d3d3a4f44ad9f3968dbb915e02c1b964096e527e9d8b705ac14a4504f1d03dce78ce86e00426ecb2b
|
data/Gemfile
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in vagrant-nfs_guest.gemspec
|
4
|
-
gemspec
|
4
|
+
#gemspec
|
5
5
|
|
6
6
|
group :development do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
# We depend on Vagrant for development, but we don't add it as a
|
8
|
+
# gem dependency because we expect to be installed within the
|
9
|
+
# Vagrant environment itself using `vagrant plugin`.
|
10
|
+
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
|
11
|
+
end
|
12
|
+
|
13
|
+
group :plugins do
|
14
|
+
gem "vagrant-nfs_guest", path: "."
|
11
15
|
end
|
data/README.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Vagrant-NFS_Guest
|
2
2
|
|
3
|
+
## What's New?
|
4
|
+
|
5
|
+
- Supports Vagrant 1.6!
|
6
|
+
- Handles actions 'up', 'halt', 'destroy', 'suspend', 'resume' and 'package' properly
|
7
|
+
- Uses retryable() for host to guest communications allow more fault tolerance
|
8
|
+
- Better error messages and handling
|
9
|
+
- Re-organisation of modules and class to better match Vagrant proper
|
10
|
+
- Simplified the plugin events binding
|
11
|
+
|
12
|
+
## Overview
|
13
|
+
|
3
14
|
Allows a guest VM to export synced folders via NFS and the host to mount them.
|
4
15
|
|
5
16
|
Basically it's just the usual NFS synced folders in Vagrant but the roles are reversed.
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'json'
|
2
|
+
module VagrantPlugins
|
3
|
+
module SyncedFolderNFSGuest
|
4
|
+
module Action
|
5
|
+
class MountNFS
|
6
|
+
|
7
|
+
def initialize(app,env)
|
8
|
+
@app = app
|
9
|
+
@logger = Log4r::Logger.new("vagrant-nfs_guest::action::unmount_nfs")
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
@machine = env[:machine]
|
14
|
+
|
15
|
+
if @machine.state.id == :running
|
16
|
+
|
17
|
+
raise Vagrant::Errors::NFSNoHostIP if !env[:nfs_guest_host_ip]
|
18
|
+
raise Vagrant::Errors::NFSNoGuestIP if !env[:nfs_guest_machine_ip]
|
19
|
+
|
20
|
+
machine_ip = env[:nfs_guest_machine_ip]
|
21
|
+
machine_ip = [machine_ip] if !machine_ip.is_a?(Array)
|
22
|
+
|
23
|
+
# Mount guest NFS folders
|
24
|
+
@machine.ui.info(I18n.t("vagrant_nfs_guest.actions.vm.nfs.mounting"))
|
25
|
+
folders = @machine.config.vm.synced_folders
|
26
|
+
|
27
|
+
@machine.env.host.capability(
|
28
|
+
:nfs_mount,
|
29
|
+
@machine.ui, @machine.id, machine_ip, folders
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
@app.call(env)
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -10,17 +10,19 @@ module VagrantPlugins
|
|
10
10
|
|
11
11
|
def initialize(app,env)
|
12
12
|
@app = app
|
13
|
-
@logger = Log4r::Logger.new("vagrant::action::
|
13
|
+
@logger = Log4r::Logger.new("vagrant-nfs_guest::action::prepare_nfs_guest_settings")
|
14
14
|
end
|
15
15
|
|
16
16
|
def call(env)
|
17
17
|
@machine = env[:machine]
|
18
|
-
@app.call(env)
|
19
18
|
|
20
19
|
if using_nfs?
|
21
20
|
@logger.info("Using NFS_guest, preparing NFS settings by reading host IP and machine IP")
|
22
|
-
|
21
|
+
add_ips_to_env!(env)
|
23
22
|
end
|
23
|
+
|
24
|
+
@app.call(env)
|
25
|
+
|
24
26
|
end
|
25
27
|
|
26
28
|
# We're using NFS if we have any synced folder with NFS configured. If
|
@@ -35,10 +37,9 @@ module VagrantPlugins
|
|
35
37
|
# mounting.
|
36
38
|
#
|
37
39
|
# The ! indicates that this method modifies its argument.
|
38
|
-
def
|
40
|
+
def add_ips_to_env!(env)
|
39
41
|
adapter, host_ip = find_host_only_adapter
|
40
|
-
machine_ip =
|
41
|
-
machine_ip = read_machine_ip(adapter) if adapter
|
42
|
+
machine_ip = read_static_machine_ips || read_dynamic_machine_ip(adapter)
|
42
43
|
|
43
44
|
raise Vagrant::Errors::NFSNoHostonlyNetwork if !host_ip || !machine_ip
|
44
45
|
|
@@ -64,6 +65,25 @@ module VagrantPlugins
|
|
64
65
|
nil
|
65
66
|
end
|
66
67
|
|
68
|
+
# Returns the IP address(es) of the guest by looking for static IPs
|
69
|
+
# given to host only adapters in the Vagrantfile
|
70
|
+
#
|
71
|
+
# @return [Array]<String> Configured static IPs
|
72
|
+
def read_static_machine_ips
|
73
|
+
ips = []
|
74
|
+
@machine.config.vm.networks.each do |type, options|
|
75
|
+
if type == :private_network && options[:ip].is_a?(String)
|
76
|
+
ips << options[:ip]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
if ips.empty?
|
81
|
+
return nil
|
82
|
+
end
|
83
|
+
|
84
|
+
ips
|
85
|
+
end
|
86
|
+
|
67
87
|
# Returns the IP address of the guest by looking at vbox guest property
|
68
88
|
# for the appropriate guest adapter.
|
69
89
|
#
|
@@ -72,7 +92,7 @@ module VagrantPlugins
|
|
72
92
|
#
|
73
93
|
# @param [Integer] adapter number to read IP for
|
74
94
|
# @return [String] ip address of adapter
|
75
|
-
def
|
95
|
+
def read_dynamic_machine_ip(adapter)
|
76
96
|
# vbox guest properties are 0-indexed, while showvminfo network
|
77
97
|
# interfaces are 1-indexed. go figure.
|
78
98
|
guestproperty_adapter = adapter - 1
|
@@ -0,0 +1,31 @@
|
|
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(
|
20
|
+
:nfs_unmount,
|
21
|
+
@machine.ui, folders
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
@app.call(env)
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -3,17 +3,20 @@ require "vagrant"
|
|
3
3
|
module VagrantPlugins
|
4
4
|
module SyncedFolderNFSGuest
|
5
5
|
class Config < Vagrant.plugin("2", :config)
|
6
|
+
attr_accessor :functional
|
6
7
|
attr_accessor :map_uid
|
7
8
|
attr_accessor :map_gid
|
8
9
|
|
9
10
|
def initialize
|
10
11
|
super
|
11
12
|
|
12
|
-
@
|
13
|
-
@
|
13
|
+
@functional = UNSET_VALUE
|
14
|
+
@map_uid = UNSET_VALUE
|
15
|
+
@map_gid = UNSET_VALUE
|
14
16
|
end
|
15
17
|
|
16
18
|
def finalize!
|
19
|
+
@functional = true if @functional == UNSET_VALUE
|
17
20
|
@map_uid = nil if @map_uid == UNSET_VALUE
|
18
21
|
@map_gid = nil if @map_gid == UNSET_VALUE
|
19
22
|
end
|
@@ -2,8 +2,18 @@ require "vagrant"
|
|
2
2
|
|
3
3
|
module VagrantPlugins
|
4
4
|
module SyncedFolderNFSGuest
|
5
|
-
|
6
|
-
|
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_start_failed)
|
13
|
+
error_key(:nfs_apply_failed)
|
14
|
+
error_key(:nfs_update_exports_failed)
|
15
|
+
end
|
16
|
+
|
7
17
|
end
|
8
18
|
end
|
9
19
|
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
require "vagrant/util"
|
4
|
+
require "vagrant/util/retryable"
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module SyncedFolderNFSGuest
|
8
|
+
module GuestLinux
|
9
|
+
module Cap
|
10
|
+
class NFSExport
|
11
|
+
extend Vagrant::Util::Retryable
|
12
|
+
|
13
|
+
def self.nfs_apply_command(env)
|
14
|
+
"exportfs -r"
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.nfs_check_command(env)
|
18
|
+
"/etc/init.d/nfs-kernel-server status"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.nfs_start_command(env)
|
22
|
+
"/etc/init.d/nfs-kernel-server start"
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.nfs_exports_template(machine)
|
26
|
+
VagrantPlugins::SyncedFolderNFSGuest.source_root.join(
|
27
|
+
"templates/nfs_guest/guest_export_linux")
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.nfs_capable?(machine)
|
31
|
+
nfs_check_command = machine.guest.capability(:nfs_check_command)
|
32
|
+
machine.communicate.test(nfs_check_command)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.nfs_apply_changes!(machine)
|
36
|
+
nfs_apply_command = machine.guest.capability(:nfs_apply_command)
|
37
|
+
machine.communicate.sudo(nfs_apply_command,
|
38
|
+
error_class: Errors::GuestNFSError,
|
39
|
+
error_key: :nfs_apply_failed
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.nfs_start!(machine)
|
44
|
+
nfs_start_command = machine.guest.capability(:nfs_start_command)
|
45
|
+
machine.communicate.sudo(nfs_start_command,
|
46
|
+
error_class: Errors::GuestNFSError,
|
47
|
+
error_key: :nfs_start_failed
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.nfs_export(machine, ip, folders)
|
52
|
+
nfs_exports_template = machine.guest.capability(:nfs_exports_template)
|
53
|
+
|
54
|
+
nfs_opts_setup(machine, folders)
|
55
|
+
|
56
|
+
output = Vagrant::Util::TemplateRenderer.render(
|
57
|
+
nfs_exports_template,
|
58
|
+
uuid: machine.id,
|
59
|
+
ips: [ip],
|
60
|
+
folders: folders,
|
61
|
+
user: Process.uid)
|
62
|
+
|
63
|
+
machine.ui.info I18n.t("vagrant_nfs_guest.guests.linux.nfs_export")
|
64
|
+
sleep 0.5
|
65
|
+
|
66
|
+
nfs_cleanup(machine)
|
67
|
+
|
68
|
+
retryable(on: Errors::GuestNFSError, tries: 8, sleep: 3) do
|
69
|
+
output.split("\n").each do |line|
|
70
|
+
machine.communicate.sudo(
|
71
|
+
%Q[echo '#{line}' >> /etc/exports],
|
72
|
+
error_class: Errors::GuestNFSError,
|
73
|
+
error_key: :nfs_update_exports_failed
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
if nfs_capable?(machine)
|
78
|
+
nfs_apply_changes!(machine)
|
79
|
+
else
|
80
|
+
nfs_start!(machine)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.nfs_cleanup(machine)
|
86
|
+
id = machine.id
|
87
|
+
user = Process.uid
|
88
|
+
|
89
|
+
# Use sed to just strip out the block of code which was inserted
|
90
|
+
# by Vagrant
|
91
|
+
#
|
92
|
+
machine_do(
|
93
|
+
machine,
|
94
|
+
"sed -r -e '/^# VAGRANT-BEGIN:( #{user})? #{id}/,/^# " +
|
95
|
+
"VAGRANT-END:( #{user})? #{id}/ d' -ibak /etc/exports")
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.nfs_opts_setup(machine, folders)
|
99
|
+
folders.each do |k, opts|
|
100
|
+
if !opts[:linux__nfs_options]
|
101
|
+
opts[:linux__nfs_options] ||= ["rw", "no_subtree_check", "all_squash", "insecure"]
|
102
|
+
end
|
103
|
+
|
104
|
+
# Only automatically set anonuid/anongid if they weren't
|
105
|
+
# explicitly set by the user.
|
106
|
+
hasgid = false
|
107
|
+
hasuid = false
|
108
|
+
opts[:linux__nfs_options].each do |opt|
|
109
|
+
hasgid = !!(opt =~ /^anongid=/) if !hasgid
|
110
|
+
hasuid = !!(opt =~ /^anonuid=/) if !hasuid
|
111
|
+
end
|
112
|
+
|
113
|
+
opts[:linux__nfs_options] << "anonuid=#{opts[:map_uid]}" if !hasuid
|
114
|
+
opts[:linux__nfs_options] << "anongid=#{opts[:map_gid]}" if !hasgid
|
115
|
+
opts[:linux__nfs_options] << "fsid=#{opts[:uuid]}"
|
116
|
+
|
117
|
+
# Expand the guest path so we can handle things like "~/vagrant"
|
118
|
+
expanded_guest_path = machine.guest.capability(
|
119
|
+
:shell_expand_guest_path, opts[:guestpath])
|
120
|
+
|
121
|
+
begin
|
122
|
+
retryable(on: Vagrant::Errors::VagrantError, tries: 8, sleep: 3) do
|
123
|
+
# Do the actual creating and mounting
|
124
|
+
machine_do(machine, "mkdir -p #{expanded_guest_path}")
|
125
|
+
machine_do(machine, "chown -R vagrant:vagrant #{expanded_guest_path}")
|
126
|
+
machine_do(machine, "chmod 2775 #{expanded_guest_path}")
|
127
|
+
end
|
128
|
+
rescue Vagrant::Errors::VagrantError
|
129
|
+
raise Errors::CreateMountsFailed
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.machine_do(machine, command)
|
135
|
+
machine.communicate.sudo(command)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module GuestLinux
|
3
|
+
module Cap
|
4
|
+
class ReadUserIDs
|
5
|
+
def self.read_uid(machine)
|
6
|
+
command = "id -u"
|
7
|
+
result = ""
|
8
|
+
machine.communicate.execute(command) do |type, data|
|
9
|
+
result << data if type == :stdout
|
10
|
+
end
|
11
|
+
|
12
|
+
result.chomp.split("\n").first
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.read_gid(machine)
|
16
|
+
command = "id -g"
|
17
|
+
result = ""
|
18
|
+
machine.communicate.execute(command) do |type, data|
|
19
|
+
result << data if type == :stdout
|
20
|
+
end
|
21
|
+
|
22
|
+
result.chomp.split("\n").first
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module HostBSD
|
5
|
+
module Cap
|
6
|
+
class MountNFS
|
7
|
+
|
8
|
+
def self.nfs_mount(environment, ui, id, ips, folders)
|
9
|
+
folders.each do |name, opts|
|
10
|
+
if opts[:type] != :nfs_guest
|
11
|
+
next
|
12
|
+
end
|
13
|
+
|
14
|
+
ips.each do |ip|
|
15
|
+
ui.detail(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
|
16
|
+
guestpath: opts[:guestpath],
|
17
|
+
hostpath: opts[:hostpath]))
|
18
|
+
|
19
|
+
system("mkdir -p #{opts[:hostpath]}")
|
20
|
+
mount_command = "mount -t nfs -o noatime '#{ip}:#{opts[:guestpath]}' '#{opts[:hostpath]}'"
|
21
|
+
if system(mount_command)
|
22
|
+
break
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module HostBSD
|
5
|
+
module Cap
|
6
|
+
class UnmountNFS
|
7
|
+
|
8
|
+
def self.nfs_unmount(environment, ui, folders)
|
9
|
+
folders.each do |name, opts|
|
10
|
+
if opts[:type] != :nfs_guest
|
11
|
+
next
|
12
|
+
end
|
13
|
+
|
14
|
+
ui.detail(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
|
15
|
+
guestpath: opts[:guestpath],
|
16
|
+
hostpath: opts[:hostpath]))
|
17
|
+
|
18
|
+
expanded_host_path = `printf #{opts[:hostpath]}`
|
19
|
+
umount_msg = `umount '#{expanded_host_path}' 2>&1`
|
20
|
+
|
21
|
+
if $?.exitstatus != 0
|
22
|
+
if not umount_msg.include? 'not currently mounted'
|
23
|
+
ui.info "NFS mounts still in use!"
|
24
|
+
exit(1)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module HostBSD
|
5
|
+
class Plugin < Vagrant.plugin("2")
|
6
|
+
|
7
|
+
host_capability("bsd", "nfs_mount") do
|
8
|
+
require_relative "cap/mount_nfs"
|
9
|
+
Cap::MountNFS
|
10
|
+
end
|
11
|
+
|
12
|
+
host_capability("bsd", "nfs_unmount") do
|
13
|
+
require_relative "cap/unmount_nfs"
|
14
|
+
Cap::UnmountNFS
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,59 +1,138 @@
|
|
1
|
-
|
2
|
-
require
|
1
|
+
begin
|
2
|
+
require "vagrant"
|
3
|
+
rescue LoadError
|
4
|
+
raise "The Vagrant AWS plugin must be run within Vagrant."
|
5
|
+
end
|
6
|
+
|
7
|
+
# This is a sanity check to make sure no one is attempting to install
|
8
|
+
# this into an early Vagrant version.
|
9
|
+
if Vagrant::VERSION < "1.2.0"
|
10
|
+
raise "The Vagrant AWS plugin is only compatible with Vagrant 1.2+"
|
11
|
+
end
|
3
12
|
|
4
13
|
module VagrantPlugins
|
5
14
|
module SyncedFolderNFSGuest
|
15
|
+
# This plugin implements Guest Exported NFS folders.
|
16
|
+
#
|
6
17
|
class Plugin < Vagrant.plugin("2")
|
7
18
|
name "vagrant-nfs_guest"
|
8
19
|
description <<-DESC
|
9
|
-
|
20
|
+
The NFS Guest synced folders plugin enables you to use NFS exports from
|
21
|
+
the Guest as a synced folder implementation.
|
10
22
|
DESC
|
11
23
|
|
12
24
|
config(:nfs_guest) do
|
13
|
-
|
25
|
+
require_relative "config"
|
14
26
|
Config
|
15
27
|
end
|
16
28
|
|
17
29
|
synced_folder(:nfs_guest, 4) do
|
18
|
-
|
30
|
+
require_relative "synced_folder"
|
19
31
|
SyncedFolder
|
20
32
|
end
|
21
33
|
|
22
|
-
guest_capability(:linux, :
|
23
|
-
|
24
|
-
Cap::
|
34
|
+
guest_capability(:linux, :nfs_export) do
|
35
|
+
require_relative "guests/linux/cap/nfs_export"
|
36
|
+
GuestLinux::Cap::NFSExport
|
25
37
|
end
|
26
38
|
|
27
|
-
guest_capability(:linux, :
|
28
|
-
|
29
|
-
Cap::
|
39
|
+
guest_capability(:linux, :nfs_apply_command) do
|
40
|
+
require_relative "guests/linux/cap/nfs_export"
|
41
|
+
GuestLinux::Cap::NFSExport
|
42
|
+
end
|
43
|
+
|
44
|
+
guest_capability(:linux, :nfs_check_command) do
|
45
|
+
require_relative "guests/linux/cap/nfs_export"
|
46
|
+
GuestLinux::Cap::NFSExport
|
47
|
+
end
|
48
|
+
|
49
|
+
guest_capability(:linux, :nfs_start_command) do
|
50
|
+
require_relative "guests/linux/cap/nfs_export"
|
51
|
+
GuestLinux::Cap::NFSExport
|
52
|
+
end
|
53
|
+
|
54
|
+
guest_capability(:linux, :nfs_exports_template) do
|
55
|
+
require_relative "guests/linux/cap/nfs_export"
|
56
|
+
GuestLinux::Cap::NFSExport
|
30
57
|
end
|
31
58
|
|
32
59
|
guest_capability(:linux, :read_uid) do
|
33
|
-
|
34
|
-
Cap::
|
60
|
+
require_relative "guests/linux/cap/read_user_ids"
|
61
|
+
GuestLinux::Cap::ReadUserIDs
|
35
62
|
end
|
36
63
|
|
37
64
|
guest_capability(:linux, :read_gid) do
|
38
|
-
|
39
|
-
Cap::
|
65
|
+
require_relative "guests/linux/cap/read_user_ids"
|
66
|
+
GuestLinux::Cap::ReadUserIDs
|
40
67
|
end
|
41
68
|
|
42
|
-
|
43
|
-
|
44
|
-
|
69
|
+
action_hook(:nfs_guest, :machine_action_up) do |hook|
|
70
|
+
require_relative "action/prepare_nfs_guest_settings"
|
71
|
+
hook.after(
|
72
|
+
VagrantPlugins::ProviderVirtualBox::Action::Boot,
|
73
|
+
Action::PrepareNFSGuestSettings
|
74
|
+
)
|
45
75
|
end
|
46
76
|
|
47
|
-
|
48
|
-
|
49
|
-
hook.before(
|
50
|
-
|
77
|
+
action_hook(:nfs_guest, :machine_action_reload) do |hook|
|
78
|
+
require_relative "action/prepare_nfs_guest_settings"
|
79
|
+
hook.before(
|
80
|
+
VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings,
|
81
|
+
Action::PrepareNFSGuestSettings
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
action_hook(:nfs_guest, :machine_action_resume) do |hook|
|
86
|
+
require_relative "action/mount_nfs"
|
87
|
+
require_relative "action/prepare_nfs_guest_settings"
|
88
|
+
hook.after(
|
89
|
+
VagrantPlugins::ProviderVirtualBox::Action::WaitForCommunicator,
|
90
|
+
Action::PrepareNFSGuestSettings
|
91
|
+
)
|
92
|
+
hook.after(
|
93
|
+
Action::PrepareNFSGuestSettings,
|
94
|
+
Action::MountNFS
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
action_hook(:nfs_guest, :machine_action_halt) do |hook|
|
99
|
+
require_relative "action/unmount_nfs"
|
100
|
+
hook.before(
|
101
|
+
Vagrant::Action::Builtin::GracefulHalt,
|
102
|
+
Action::UnmountNFS
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
action_hook(:nfs_guest, :machine_action_reload) do |hook|
|
107
|
+
require_relative "action/unmount_nfs"
|
108
|
+
hook.before(
|
109
|
+
Vagrant::Action::Builtin::GracefulHalt,
|
110
|
+
Action::UnmountNFS
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
action_hook(:nfs_guest, :machine_action_package) do |hook|
|
115
|
+
require_relative "action/unmount_nfs"
|
116
|
+
hook.before(
|
117
|
+
Vagrant::Action::Builtin::GracefulHalt,
|
118
|
+
Action::UnmountNFS
|
119
|
+
)
|
51
120
|
end
|
52
121
|
|
53
|
-
require File.expand_path("../action/unmount_mounts", __FILE__)
|
54
122
|
action_hook(:nfs_guest, :machine_action_destroy) do |hook|
|
55
|
-
|
56
|
-
|
123
|
+
require_relative "action/unmount_nfs"
|
124
|
+
hook.after(
|
125
|
+
Vagrant::Action::Builtin::DestroyConfirm,
|
126
|
+
Action::UnmountNFS
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
action_hook(:nfs_guest, :machine_action_suspend) do |hook|
|
131
|
+
require_relative "action/unmount_nfs"
|
132
|
+
hook.before(
|
133
|
+
VagrantPlugins::ProviderVirtualBox::Action::Suspend,
|
134
|
+
Action::UnmountNFS
|
135
|
+
)
|
57
136
|
end
|
58
137
|
end
|
59
138
|
end
|
@@ -1,25 +1,25 @@
|
|
1
1
|
require 'zlib'
|
2
|
+
require 'json'
|
2
3
|
|
3
4
|
module VagrantPlugins
|
4
5
|
module SyncedFolderNFSGuest
|
5
6
|
class SyncedFolder < Vagrant.plugin("2", :synced_folder)
|
6
|
-
def usable?(machine)
|
7
|
-
# NFS is
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
def usable?(machine, raise_error=false)
|
8
|
+
# If the machine explicitly said NFS is not supported, then
|
9
|
+
# it isn't supported.
|
10
|
+
if !machine.config.nfs_guest.functional
|
11
|
+
return false
|
12
|
+
end
|
13
|
+
return true if machine.env.host.capability(:nfs_installed)
|
14
|
+
return true if machine.guest.capability(:nfs_installed)
|
15
|
+
return false if !raise_error
|
16
|
+
raise Vagrant::Errors::NFSNotSupported
|
13
17
|
end
|
14
18
|
|
15
19
|
def enable(machine, folders, nfsopts)
|
16
20
|
raise Vagrant::Errors::NFSNoHostIP if !nfsopts[:nfs_guest_host_ip]
|
17
21
|
raise Vagrant::Errors::NFSNoGuestIP if !nfsopts[:nfs_guest_machine_ip]
|
18
22
|
|
19
|
-
if !machine.guest.capability(:export_nfs_capable)
|
20
|
-
raise VagrantPlugins::SyncedFolderNFSGuest::Error, :no_nfsd
|
21
|
-
end
|
22
|
-
|
23
23
|
machine_ip = nfsopts[:nfs_guest_machine_ip]
|
24
24
|
machine_ip = [machine_ip] if !machine_ip.is_a?(Array)
|
25
25
|
|
@@ -33,13 +33,15 @@ module VagrantPlugins
|
|
33
33
|
mount_folders[id] = opts.dup if opts[:guestpath]
|
34
34
|
end
|
35
35
|
|
36
|
-
machine.ui.info I18n.t("
|
36
|
+
machine.ui.info I18n.t("vagrant_nfs_guest.actions.vm.nfs.exporting")
|
37
37
|
machine.guest.capability(
|
38
|
-
:
|
38
|
+
:nfs_export, nfsopts[:nfs_guest_host_ip], mount_folders)
|
39
39
|
|
40
|
-
machine.ui.info I18n.t("
|
41
|
-
machine.env.host.
|
42
|
-
|
40
|
+
machine.ui.info I18n.t("vagrant_nfs_guest.actions.vm.nfs.mounting")
|
41
|
+
machine.env.host.capability(
|
42
|
+
:nfs_mount,
|
43
|
+
machine.ui, machine.id, machine_ip, mount_folders
|
44
|
+
)
|
43
45
|
end
|
44
46
|
|
45
47
|
protected
|
data/lib/vagrant-nfs_guest.rb
CHANGED
@@ -1,27 +1,21 @@
|
|
1
|
-
|
2
|
-
require "vagrant"
|
3
|
-
rescue LoadError
|
4
|
-
raise "The Vagrant nfs_guest plugin must be run within Vagrant."
|
5
|
-
end
|
6
|
-
|
7
|
-
# This is a sanity check to make sure no one is attempting to install
|
8
|
-
# this into an early Vagrant version.
|
9
|
-
if Vagrant::VERSION < "1.4.0"
|
10
|
-
raise "The Vagrant nfs_guest plugin is only compatible with Vagrant 1.4+"
|
11
|
-
end
|
1
|
+
require "pathname"
|
12
2
|
|
13
3
|
require "vagrant-nfs_guest/plugin"
|
14
|
-
require
|
15
|
-
|
16
|
-
require "pathname"
|
4
|
+
require "vagrant-nfs_guest/hosts/bsd/plugin"
|
17
5
|
|
18
6
|
module VagrantPlugins
|
19
7
|
module SyncedFolderNFSGuest
|
8
|
+
lib_path = Pathname.new(File.expand_path("../vagrant-nfs_guest", __FILE__))
|
9
|
+
autoload :Errors, lib_path.join("errors")
|
10
|
+
|
11
|
+
# This returns the path to the source of this plugin.
|
12
|
+
#
|
13
|
+
# @return [Pathname]
|
20
14
|
def self.source_root
|
21
15
|
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
|
22
16
|
end
|
23
17
|
|
24
|
-
I18n.load_path << File.expand_path(
|
18
|
+
I18n.load_path << File.expand_path("templates/locales/en.yml", source_root)
|
25
19
|
I18n.reload!
|
26
20
|
end
|
27
21
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
en:
|
2
|
+
vagrant_nfs_guest:
|
3
|
+
actions:
|
4
|
+
vm:
|
5
|
+
nfs:
|
6
|
+
exporting: "Exporting NFS shared folders from guest..."
|
7
|
+
mounting: "Mounting NFS shared folders from guest..."
|
8
|
+
unmounting: "Unmounting NFS shared folders from guest..."
|
9
|
+
guests:
|
10
|
+
linux:
|
11
|
+
nfs_export: "Preparing to edit /etc/exports on the guest..."
|
12
|
+
|
13
|
+
errors:
|
14
|
+
nfs_update_exports_failed: |-
|
15
|
+
There was an error updating the guests /etc/exports file.
|
16
|
+
|
17
|
+
%{command}
|
18
|
+
|
19
|
+
Stdout from the command:
|
20
|
+
%{stdout}
|
21
|
+
|
22
|
+
Stderr from the command:
|
23
|
+
%{stderr}
|
24
|
+
nfs_start_failed: |-
|
25
|
+
Something failed while starting the NFS service on the guest.
|
26
|
+
|
27
|
+
%{command}
|
28
|
+
|
29
|
+
Stdout from the command:
|
30
|
+
%{stdout}
|
31
|
+
|
32
|
+
Stderr from the command:
|
33
|
+
%{stderr}
|
34
|
+
nfs_apply_failed: |-
|
35
|
+
Something failed while applying changes to the NFS service on the guest.
|
36
|
+
|
37
|
+
%{command}
|
38
|
+
|
39
|
+
Stdout from the command:
|
40
|
+
%{stdout}
|
41
|
+
|
42
|
+
Stderr from the command:
|
43
|
+
%{stderr}
|
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-nfs_guest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Alan Garfield
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.3'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.3'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: Adds support for guest nfs exporting of synced folders
|
@@ -50,56 +45,50 @@ executables: []
|
|
50
45
|
extensions: []
|
51
46
|
extra_rdoc_files: []
|
52
47
|
files:
|
53
|
-
- .gitignore
|
48
|
+
- ".gitignore"
|
54
49
|
- Gemfile
|
55
50
|
- LICENSE.txt
|
56
51
|
- README.md
|
57
52
|
- Rakefile
|
58
53
|
- lib/vagrant-nfs_guest.rb
|
54
|
+
- lib/vagrant-nfs_guest/action/mount_nfs.rb
|
59
55
|
- lib/vagrant-nfs_guest/action/prepare_nfs_guest_settings.rb
|
60
|
-
- lib/vagrant-nfs_guest/action/
|
61
|
-
- lib/vagrant-nfs_guest/cap/linux/export_nfs_folders.rb
|
62
|
-
- lib/vagrant-nfs_guest/cap/linux/halt.rb
|
63
|
-
- lib/vagrant-nfs_guest/cap/linux/read_user_ids.rb
|
56
|
+
- lib/vagrant-nfs_guest/action/unmount_nfs.rb
|
64
57
|
- lib/vagrant-nfs_guest/config.rb
|
65
58
|
- lib/vagrant-nfs_guest/errors.rb
|
66
|
-
- lib/vagrant-nfs_guest/
|
67
|
-
- lib/vagrant-nfs_guest/
|
59
|
+
- lib/vagrant-nfs_guest/guests/linux/cap/nfs_export.rb
|
60
|
+
- lib/vagrant-nfs_guest/guests/linux/cap/read_user_ids.rb
|
61
|
+
- lib/vagrant-nfs_guest/hosts/bsd/cap/mount_nfs.rb
|
62
|
+
- lib/vagrant-nfs_guest/hosts/bsd/cap/unmount_nfs.rb
|
63
|
+
- lib/vagrant-nfs_guest/hosts/bsd/plugin.rb
|
68
64
|
- lib/vagrant-nfs_guest/plugin.rb
|
69
65
|
- lib/vagrant-nfs_guest/synced_folder.rb
|
70
66
|
- lib/vagrant-nfs_guest/version.rb
|
71
|
-
- locales/en.yml
|
67
|
+
- templates/locales/en.yml
|
72
68
|
- templates/nfs_guest/guest_export_linux.erb
|
73
69
|
- vagrant-nfs_guest.gemspec
|
74
70
|
homepage: ''
|
75
71
|
licenses:
|
76
72
|
- MIT
|
73
|
+
metadata: {}
|
77
74
|
post_install_message:
|
78
75
|
rdoc_options: []
|
79
76
|
require_paths:
|
80
77
|
- lib
|
81
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
79
|
requirements:
|
84
|
-
- -
|
80
|
+
- - ">="
|
85
81
|
- !ruby/object:Gem::Version
|
86
82
|
version: '0'
|
87
|
-
segments:
|
88
|
-
- 0
|
89
|
-
hash: 4128011817276071124
|
90
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
-
none: false
|
92
84
|
requirements:
|
93
|
-
- -
|
85
|
+
- - ">="
|
94
86
|
- !ruby/object:Gem::Version
|
95
87
|
version: '0'
|
96
|
-
segments:
|
97
|
-
- 0
|
98
|
-
hash: 4128011817276071124
|
99
88
|
requirements: []
|
100
89
|
rubyforge_project:
|
101
|
-
rubygems_version:
|
90
|
+
rubygems_version: 2.2.2
|
102
91
|
signing_key:
|
103
|
-
specification_version:
|
92
|
+
specification_version: 4
|
104
93
|
summary: Adds support for guest nfs exporting of synced folders
|
105
94
|
test_files: []
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module SyncedFolderNFSGuest
|
3
|
-
module Action
|
4
|
-
class UnmountMounts
|
5
|
-
def initialize(app,env)
|
6
|
-
@app = app
|
7
|
-
@logger = Log4r::Logger.new("vagrant::action::vm::nfs_guest")
|
8
|
-
end
|
9
|
-
|
10
|
-
def call(env)
|
11
|
-
@machine = env[:machine]
|
12
|
-
@app.call(env)
|
13
|
-
|
14
|
-
folders = @machine.config.vm.synced_folders
|
15
|
-
@machine.env.host.unmount_nfs_folders(folders)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'vagrant/util/platform'
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module SyncedFolderNFSGuest
|
5
|
-
module Cap
|
6
|
-
module Linux
|
7
|
-
class ExportNFS
|
8
|
-
include Vagrant::Util
|
9
|
-
|
10
|
-
def self.export_nfs_capable(machine)
|
11
|
-
me = self.new(machine)
|
12
|
-
return me.nfs_capable?
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.export_nfs_folders(machine, ip, folders)
|
16
|
-
me = self.new(machine, ip, folders)
|
17
|
-
|
18
|
-
me.nfs_opts_setup()
|
19
|
-
|
20
|
-
tpl_path = VagrantPlugins::SyncedFolderNFSGuest.source_root.join(
|
21
|
-
'templates/nfs_guest/guest_export_linux')
|
22
|
-
output = TemplateRenderer.render(tpl_path,
|
23
|
-
:uuid => machine.id,
|
24
|
-
:ips => [ip],
|
25
|
-
:folders => folders,
|
26
|
-
:user => Process.uid)
|
27
|
-
|
28
|
-
machine.ui.info I18n.t("vagrant.hosts.linux.nfs_export")
|
29
|
-
sleep 0.5
|
30
|
-
|
31
|
-
me.nfs_cleanup()
|
32
|
-
|
33
|
-
output.split("\n").each do |line|
|
34
|
-
machine.communicate.sudo(%Q[echo '#{line}' >> /etc/exports])
|
35
|
-
end
|
36
|
-
|
37
|
-
me.restart_nfs()
|
38
|
-
end
|
39
|
-
|
40
|
-
def initialize(machine, ip = [], folders = [])
|
41
|
-
@machine = machine
|
42
|
-
@ip = ip
|
43
|
-
@folders = folders
|
44
|
-
|
45
|
-
@folder_test_command = "test -d"
|
46
|
-
@nfs_test_command = "test -e /etc/exports"
|
47
|
-
@nfs_apply_command = "/usr/sbin/exportfs -r"
|
48
|
-
@nfs_check_command = "/etc/init.d/nfs-kernel-server status"
|
49
|
-
@nfs_start_command = "/etc/init.d/nfs-kernel-server start"
|
50
|
-
end
|
51
|
-
|
52
|
-
def nfs_running?
|
53
|
-
@machine.communicate.test("#{@nfs_check_command}")
|
54
|
-
end
|
55
|
-
|
56
|
-
def nfs_capable?
|
57
|
-
@machine.communicate.test("#{@nfs_test_command}")
|
58
|
-
end
|
59
|
-
|
60
|
-
# TODO - DRY this; ripped completely from plugins/hosts/linux/host.rb
|
61
|
-
def nfs_opts_setup()
|
62
|
-
@folders.each do |k, opts|
|
63
|
-
if !opts[:linux__nfs_options]
|
64
|
-
opts[:linux__nfs_options] ||= ["rw", "no_subtree_check", "all_squash", "insecure"]
|
65
|
-
end
|
66
|
-
|
67
|
-
# Only automatically set anonuid/anongid if they weren't
|
68
|
-
# explicitly set by the user.
|
69
|
-
hasgid = false
|
70
|
-
hasuid = false
|
71
|
-
opts[:linux__nfs_options].each do |opt|
|
72
|
-
hasgid = !!(opt =~ /^anongid=/) if !hasgid
|
73
|
-
hasuid = !!(opt =~ /^anonuid=/) if !hasuid
|
74
|
-
end
|
75
|
-
|
76
|
-
opts[:linux__nfs_options] << "anonuid=#{opts[:map_uid]}" if !hasuid
|
77
|
-
opts[:linux__nfs_options] << "anongid=#{opts[:map_gid]}" if !hasgid
|
78
|
-
opts[:linux__nfs_options] << "fsid=#{opts[:uuid]}"
|
79
|
-
|
80
|
-
# Expand the guest path so we can handle things like "~/vagrant"
|
81
|
-
expanded_guest_path = @machine.guest.capability(
|
82
|
-
:shell_expand_guest_path, opts[:guestpath])
|
83
|
-
|
84
|
-
# Do the actual creating and mounting
|
85
|
-
@machine.communicate.sudo("mkdir -p #{expanded_guest_path}")
|
86
|
-
@machine.communicate.sudo("chown -R vagrant:vagrant #{expanded_guest_path}")
|
87
|
-
@machine.communicate.sudo("chmod u+rw #{expanded_guest_path}")
|
88
|
-
@machine.communicate.sudo("chmod g+rws #{expanded_guest_path}")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def nfs_cleanup()
|
93
|
-
return if !nfs_capable?
|
94
|
-
|
95
|
-
id = @machine.id
|
96
|
-
user = Process.uid
|
97
|
-
|
98
|
-
# Use sed to just strip out the block of code which was inserted
|
99
|
-
# by Vagrant
|
100
|
-
@machine.communicate.sudo("sed -r -e '/^# VAGRANT-BEGIN:( #{user})? #{id}/,/^# VAGRANT-END:( #{user})? #{id}/ d' -ibak /etc/exports")
|
101
|
-
end
|
102
|
-
|
103
|
-
def restart_nfs()
|
104
|
-
if nfs_running?
|
105
|
-
@machine.communicate.sudo("#{@nfs_apply_command}")
|
106
|
-
else
|
107
|
-
@machine.communicate.sudo("#{@nfs_start_command}")
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require Vagrant.source_root.join("plugins/guests/linux/cap/halt")
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module SyncedFolderNFSGuest
|
5
|
-
module Cap
|
6
|
-
module Linux
|
7
|
-
class Halt
|
8
|
-
def self.halt(machine)
|
9
|
-
# unmount any host mounted NFS folders
|
10
|
-
folders = machine.config.vm.synced_folders
|
11
|
-
machine.env.host.unmount_nfs_folders(folders)
|
12
|
-
|
13
|
-
VagrantPlugins::GuestLinux::Cap::Halt.halt(machine)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module SyncedFolderNFSGuest
|
3
|
-
module Cap
|
4
|
-
module Linux
|
5
|
-
class ReadUserIDs
|
6
|
-
def self.read_uid(machine)
|
7
|
-
command = "id -u"
|
8
|
-
result = ""
|
9
|
-
machine.communicate.execute(command) do |type, data|
|
10
|
-
result << data if type == :stdout
|
11
|
-
end
|
12
|
-
|
13
|
-
result.chomp.split("\n").first
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.read_gid(machine)
|
17
|
-
command = "id -g"
|
18
|
-
result = ""
|
19
|
-
machine.communicate.execute(command) do |type, data|
|
20
|
-
result << data if type == :stdout
|
21
|
-
end
|
22
|
-
|
23
|
-
result.chomp.split("\n").first
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module HostBSD
|
3
|
-
class Host < Vagrant.plugin("2", :host)
|
4
|
-
def mount_nfs_folders(id, ips, folders)
|
5
|
-
@logger.debug "Mounting NFS mounts..."
|
6
|
-
folders.each do |name, opts|
|
7
|
-
@logger.info opts
|
8
|
-
ips.each do |ip|
|
9
|
-
system("mkdir -p #{opts[:hostpath]}")
|
10
|
-
mount_command = "mount -t nfs -o noatime '#{ip}:#{opts[:guestpath]}' '#{opts[:hostpath]}'"
|
11
|
-
if system(mount_command)
|
12
|
-
break
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def unmount_nfs_folders(folders)
|
19
|
-
@logger.debug "Unmounting NFS mounts..."
|
20
|
-
folders.each do |name, opts|
|
21
|
-
if opts[:type] == :nfs_guest
|
22
|
-
expanded_host_path = `printf #{opts[:hostpath]}`
|
23
|
-
umount_msg = `umount '#{expanded_host_path}' 2>&1`
|
24
|
-
@ui.info umount_msg
|
25
|
-
if $?.exitstatus != 0
|
26
|
-
if not umount_msg.include? 'not currently mounted'
|
27
|
-
@ui.info "NFS mounts still in use!"
|
28
|
-
exit(1)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Vagrant
|
2
|
-
module Plugin
|
3
|
-
module V2
|
4
|
-
class Host
|
5
|
-
# Mounts the given hash of folders via the guests NFS export
|
6
|
-
#
|
7
|
-
# @param [String] id A unique ID that is guaranteed to be unique to
|
8
|
-
# match these sets of folders.
|
9
|
-
# @param [Array<String>] ip IPs of the guest machine.
|
10
|
-
# @param [Hash] folders Shared folders to sync.
|
11
|
-
def mount_nfs_folders(id, ips, folders)
|
12
|
-
end
|
13
|
-
|
14
|
-
# Unmounts the given hash of folders
|
15
|
-
#
|
16
|
-
# @param [Hash] folders Shared folders to sync.
|
17
|
-
def unmount_nfs_folders(folders)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|