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.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +84 -0
  7. data/Rakefile +3 -0
  8. data/example_box/Vagrantfile +26 -0
  9. data/example_box/vagrant_share/.keep +0 -0
  10. data/lib/vagrant-nfs_guest.rb +20 -0
  11. data/lib/vagrant-nfs_guest/action/mount_nfs.rb +64 -0
  12. data/lib/vagrant-nfs_guest/action/unmount_nfs.rb +28 -0
  13. data/lib/vagrant-nfs_guest/config.rb +32 -0
  14. data/lib/vagrant-nfs_guest/errors.rb +33 -0
  15. data/lib/vagrant-nfs_guest/guests/debian/cap/nfs_server.rb +24 -0
  16. data/lib/vagrant-nfs_guest/guests/debian/plugin.rb +25 -0
  17. data/lib/vagrant-nfs_guest/guests/linux/cap/nfs_server.rb +170 -0
  18. data/lib/vagrant-nfs_guest/guests/linux/cap/read_user_ids.rb +29 -0
  19. data/lib/vagrant-nfs_guest/guests/linux/plugin.rb +50 -0
  20. data/lib/vagrant-nfs_guest/guests/redhat/cap/nfs_server.rb +85 -0
  21. data/lib/vagrant-nfs_guest/guests/redhat/plugin.rb +35 -0
  22. data/lib/vagrant-nfs_guest/guests/ubuntu/cap/nfs_server.rb +18 -0
  23. data/lib/vagrant-nfs_guest/guests/ubuntu/plugin.rb +20 -0
  24. data/lib/vagrant-nfs_guest/hosts/bsd/cap/mount_nfs.rb +34 -0
  25. data/lib/vagrant-nfs_guest/hosts/bsd/cap/unmount_nfs.rb +35 -0
  26. data/lib/vagrant-nfs_guest/hosts/bsd/plugin.rb +20 -0
  27. data/lib/vagrant-nfs_guest/hosts/linux/cap/mount_nfs.rb +34 -0
  28. data/lib/vagrant-nfs_guest/hosts/linux/cap/unmount_nfs.rb +36 -0
  29. data/lib/vagrant-nfs_guest/hosts/linux/plugin.rb +20 -0
  30. data/lib/vagrant-nfs_guest/plugin.rb +109 -0
  31. data/lib/vagrant-nfs_guest/providers/docker/cap/nfs_settings.rb +19 -0
  32. data/lib/vagrant-nfs_guest/providers/docker/plugin.rb +15 -0
  33. data/lib/vagrant-nfs_guest/providers/parallels/cap/nfs_settings.rb +17 -0
  34. data/lib/vagrant-nfs_guest/providers/parallels/plugin.rb +15 -0
  35. data/lib/vagrant-nfs_guest/providers/virtualbox/cap/nfs_settings.rb +89 -0
  36. data/lib/vagrant-nfs_guest/providers/virtualbox/plugin.rb +15 -0
  37. data/lib/vagrant-nfs_guest/synced_folder.rb +96 -0
  38. data/lib/vagrant-nfs_guest/version.rb +5 -0
  39. data/templates/locales/en.yml +69 -0
  40. data/templates/nfs_guest/guest_export_linux.erb +7 -0
  41. data/vagrant-nfs_guest.gemspec +23 -0
  42. metadata +114 -0
@@ -0,0 +1,29 @@
1
+ module VagrantPlugins
2
+ module SyncedFolderNFSGuest
3
+ module GuestLinux
4
+ module Cap
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
@@ -0,0 +1,50 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module SyncedFolderNFSGuest
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "Linux guest."
7
+ description "Linux guest support."
8
+
9
+ guest_capability(:linux, :nfs_export) do
10
+ require_relative "cap/nfs_server"
11
+ GuestLinux::Cap::NFSServer
12
+ end
13
+
14
+ guest_capability(:linux, :nfs_apply_command) do
15
+ require_relative "cap/nfs_server"
16
+ GuestLinux::Cap::NFSServer
17
+ end
18
+
19
+ guest_capability(:linux, :nfs_check_command) do
20
+ require_relative "cap/nfs_server"
21
+ GuestLinux::Cap::NFSServer
22
+ end
23
+
24
+ guest_capability(:linux, :nfs_start_command) do
25
+ require_relative "cap/nfs_server"
26
+ GuestLinux::Cap::NFSServer
27
+ end
28
+
29
+ guest_capability(:linux, :nfs_test_command) do
30
+ require_relative "cap/nfs_server"
31
+ GuestLinux::Cap::NFSServer
32
+ end
33
+
34
+ guest_capability(:linux, :nfs_exports_template) do
35
+ require_relative "cap/nfs_server"
36
+ GuestLinux::Cap::NFSServer
37
+ end
38
+
39
+ guest_capability(:linux, :read_uid) do
40
+ require_relative "cap/read_user_ids"
41
+ GuestLinux::Cap::ReadUserIDs
42
+ end
43
+
44
+ guest_capability(:linux, :read_gid) do
45
+ require_relative "cap/read_user_ids"
46
+ GuestLinux::Cap::ReadUserIDs
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,85 @@
1
+ module VagrantPlugins
2
+ module SyncedFolderNFSGuest
3
+ module GuestRedHat
4
+ module Cap
5
+ class NFSServer
6
+
7
+ def self.systemd?(machine)
8
+ machine.communicate.test("test $(ps -o comm= 1) == 'systemd'")
9
+ end
10
+
11
+ def self.nfs_server_install(machine)
12
+ machine.communicate.sudo("yum -y install nfs-utils nfs-utils-lib")
13
+
14
+ if systemd?(machine)
15
+ machine.communicate.sudo("systemctl enable rpcbind nfs-server")
16
+ else
17
+ machine.communicate.sudo("chkconfig nfs on")
18
+
19
+ end
20
+ end
21
+
22
+ def self.nfs_setup_firewall(machine, ip)
23
+ if not systemd?(machine)
24
+ # centos 6.5 has iptables on by default is would seem
25
+ machine.communicate.sudo(
26
+ "sed -i \"s/#LOCKD_/LOCKD_/\" /etc/sysconfig/nfs"
27
+ )
28
+ machine.communicate.sudo(
29
+ "sed -i \"s/#MOUNTD_PORT/MOUNTD_PORT/\" /etc/sysconfig/nfs"
30
+ )
31
+ machine.communicate.sudo(
32
+ "iptables -I INPUT -m state --state NEW -p udp -m multiport " +
33
+ "--dport 111,892,2049,32803 -s #{ip}/32 -j ACCEPT"
34
+ )
35
+ machine.communicate.sudo(
36
+ "iptables -I INPUT -m state --state NEW -p tcp -m multiport " +
37
+ "--dport 111,892,2049,32803 -s #{ip}/32 -j ACCEPT"
38
+ )
39
+
40
+ nfs_start_command(machine)
41
+ end
42
+ end
43
+
44
+ def self.nfs_server_installed(machine)
45
+ if systemd?(machine)
46
+ machine.communicate.test("systemctl status nfs-server.service")
47
+ else
48
+ machine.communicate.test("service nfs status")
49
+ end
50
+ end
51
+
52
+ def self.nfs_check_command(machine)
53
+ if systemd?(machine)
54
+ machine.communicate.test(
55
+ "systemctl status rpcbind nfs-server"
56
+ )
57
+ else
58
+ machine.communicate.test(
59
+ "service nfs status"
60
+ )
61
+ end
62
+ end
63
+
64
+ def self.nfs_start_command(machine)
65
+ if systemd?(machine)
66
+ machine.communicate.sudo(
67
+ "systemctl start rpcbind nfs-server",
68
+ error_class: Errors::GuestNFSError,
69
+ error_key: :nfs_start_failed
70
+ )
71
+ else
72
+ ['rpcbind', 'nfs'].each do |i|
73
+ machine.communicate.sudo(
74
+ "service #{i} restart",
75
+ error_class: Errors::GuestNFSError,
76
+ error_key: :nfs_start_failed
77
+ )
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,35 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module SyncedFolderNFSGuest
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "Red Hat Enterprise Linux guest"
7
+ description "Red Hat Enterprise Linux guest support."
8
+
9
+ guest_capability(:redhat, :nfs_server_installed) do
10
+ require_relative "cap/nfs_server"
11
+ GuestRedHat::Cap::NFSServer
12
+ end
13
+
14
+ guest_capability(:redhat, :nfs_server_install) do
15
+ require_relative "cap/nfs_server"
16
+ GuestRedHat::Cap::NFSServer
17
+ end
18
+
19
+ guest_capability(:redhat, :nfs_check_command) do
20
+ require_relative "cap/nfs_server"
21
+ GuestRedHat::Cap::NFSServer
22
+ end
23
+
24
+ guest_capability(:redhat, :nfs_start_command) do
25
+ require_relative "cap/nfs_server"
26
+ GuestRedHat::Cap::NFSServer
27
+ end
28
+
29
+ guest_capability(:redhat, :nfs_setup_firewall) do
30
+ require_relative "cap/nfs_server"
31
+ GuestRedHat::Cap::NFSServer
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module SyncedFolderNFSGuest
3
+ module GuestUbuntu
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
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module SyncedFolderNFSGuest
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "Ubuntu guest"
7
+ description "Ubuntu guest support."
8
+
9
+ guest_capability(:ubuntu, :nfs_server_installed) do
10
+ require_relative "cap/nfs_server"
11
+ GuestUbuntu::Cap::NFSServer
12
+ end
13
+
14
+ guest_capability(:ubuntu, :nfs_server_install) do
15
+ require_relative "cap/nfs_server"
16
+ GuestUbuntu::Cap::NFSServer
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ module VagrantPlugins
2
+ module SyncedFolderNFSGuest
3
+ module HostBSD
4
+ module Cap
5
+ class MountNFS
6
+
7
+ def self.nfs_mount(environment, ui, id, ips, folders)
8
+ folders.each do |name, opts|
9
+ if opts[:type] != :nfs_guest
10
+ next
11
+ end
12
+
13
+ ips.each do |ip|
14
+ ui.detail(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
15
+ guestpath: opts[:guestpath],
16
+ hostpath: opts[:hostpath]))
17
+
18
+ mount_options = opts.fetch(:mount_options, ["noatime"])
19
+ nfs_options = mount_options.empty? ? "" : "-o #{mount_options.join(',')}"
20
+
21
+ system("mkdir -p #{opts[:hostpath]}")
22
+ mount_command = "mount -t nfs #{nfs_options} '#{ip}:#{opts[:guestpath]}' '#{opts[:hostpath]}'"
23
+ if system(mount_command)
24
+ break
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,35 @@
1
+ module VagrantPlugins
2
+ module SyncedFolderNFSGuest
3
+ module HostBSD
4
+ module Cap
5
+ class UnmountNFS
6
+
7
+ def self.nfs_unmount(environment, ui, folders)
8
+ folders.each do |name, opts|
9
+ if opts[:type] != :nfs_guest
10
+ next
11
+ end
12
+
13
+ ui.detail(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
14
+ guestpath: opts[:guestpath],
15
+ hostpath: opts[:hostpath]))
16
+
17
+ unmount_options = opts.fetch(:unmount_options, []).join(" ")
18
+
19
+ expanded_host_path = `printf #{opts[:hostpath]}`
20
+ umount_msg = `umount #{unmount_options} '#{expanded_host_path}' 2>&1`
21
+
22
+ if $?.exitstatus != 0
23
+ if not umount_msg.include? 'not currently mounted'
24
+ ui.info "NFS mounts still in use!"
25
+ exit(1)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module SyncedFolderNFSGuest
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "BSD host"
7
+ description "BSD host support."
8
+
9
+ host_capability("bsd", "nfs_mount") do
10
+ require_relative "cap/mount_nfs"
11
+ HostBSD::Cap::MountNFS
12
+ end
13
+
14
+ host_capability("bsd", "nfs_unmount") do
15
+ require_relative "cap/unmount_nfs"
16
+ HostBSD::Cap::UnmountNFS
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ module VagrantPlugins
2
+ module SyncedFolderNFSGuest
3
+ module HostLinux
4
+ module Cap
5
+ class MountNFS
6
+
7
+ def self.nfs_mount(environment, ui, id, ips, folders)
8
+ folders.each do |name, opts|
9
+ if opts[:type] != :nfs_guest
10
+ next
11
+ end
12
+
13
+ ips.each do |ip|
14
+ ui.detail(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
15
+ guestpath: opts[:guestpath],
16
+ hostpath: opts[:hostpath]))
17
+
18
+ mount_options = opts.fetch(:mount_options, ["noatime"])
19
+ nfs_options = mount_options.empty? ? "" : "-o #{mount_options.join(',')}"
20
+
21
+ system("mkdir -p #{opts[:hostpath]}")
22
+ mount_command = "sudo mount -t nfs #{nfs_options} '#{ip}:#{opts[:guestpath]}' '#{opts[:hostpath]}'"
23
+ if system(mount_command)
24
+ break
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ module VagrantPlugins
2
+ module SyncedFolderNFSGuest
3
+ module HostLinux
4
+ module Cap
5
+ class UnmountNFS
6
+
7
+ def self.nfs_unmount(environment, ui, folders)
8
+ folders.each do |name, opts|
9
+ if opts[:type] != :nfs_guest
10
+ next
11
+ end
12
+
13
+ ui.detail(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
14
+ guestpath: opts[:guestpath],
15
+ hostpath: opts[:hostpath]))
16
+
17
+ unmount_options = opts.fetch(:unmount_options, []).join(" ")
18
+
19
+ expanded_host_path = `printf #{opts[:hostpath]}`
20
+ umount_msg = `sudo umount #{unmount_options} '#{expanded_host_path}' 2>&1`
21
+
22
+ if $?.exitstatus != 0
23
+ if not umount_msg.include? 'not currently mounted'
24
+ ui.info umount_msg
25
+ ui.info "Maybe NFS mounts still in use!"
26
+ exit(1)
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module SyncedFolderNFSGuest
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "Linux host"
7
+ description "Linux host support."
8
+
9
+ host_capability(:linux, "nfs_mount") do
10
+ require_relative "cap/mount_nfs"
11
+ HostLinux::Cap::MountNFS
12
+ end
13
+
14
+ host_capability(:linux, "nfs_unmount") do
15
+ require_relative "cap/unmount_nfs"
16
+ HostLinux::Cap::UnmountNFS
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,109 @@
1
+ begin
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.2.0"
10
+ raise "The Vagrant NFS Guest plugin is only compatible with Vagrant 1.2+"
11
+ end
12
+
13
+ require_relative "guests/debian/plugin"
14
+ require_relative "guests/linux/plugin"
15
+ require_relative "guests/redhat/plugin"
16
+ require_relative "guests/ubuntu/plugin"
17
+ require_relative "hosts/bsd/plugin"
18
+ require_relative "hosts/linux/plugin"
19
+ require_relative "providers/virtualbox/plugin"
20
+ require_relative "providers/parallels/plugin"
21
+ require_relative "providers/docker/plugin"
22
+
23
+ module VagrantPlugins
24
+ module SyncedFolderNFSGuest
25
+ # This plugin implements Guest Exported NFS folders.
26
+ #
27
+ class Plugin < Vagrant.plugin("2")
28
+ name "vagrant-nfs_guest_vbfix"
29
+ description <<-DESC
30
+ The Vagrant NFS Guest synced folders plugin enables you to use NFS exports from
31
+ the Guest as a synced folder implementation. This allows the guest to utilise
32
+ inotify (eg. file watchers) and other filesystem related functions that don't
33
+ work across NFS from the host.
34
+ DESC
35
+
36
+ config(:nfs_guest) do
37
+ require_relative "config"
38
+ Config
39
+ end
40
+
41
+ synced_folder(:nfs_guest, 5) do
42
+ require_relative "synced_folder"
43
+ SyncedFolder
44
+ end
45
+
46
+ action_hook(:nfs_guest, :machine_action_up) do |hook|
47
+ require_relative "action/mount_nfs"
48
+ hook.before(
49
+ Vagrant::Action::Builtin::WaitForCommunicator,
50
+ Action::MountNFS
51
+ )
52
+ hook.before(
53
+ Vagrant::Action::Builtin::SyncedFolders,
54
+ Action::MountNFS
55
+ )
56
+ end
57
+
58
+ action_hook(:nfs_guest, :machine_action_suspend) do |hook|
59
+ require_relative "action/unmount_nfs"
60
+ hook.prepend(Action::UnmountNFS)
61
+ end
62
+
63
+ action_hook(:nfs_guest, :machine_action_resume) do |hook|
64
+ require_relative "action/mount_nfs"
65
+ hook.after(
66
+ Vagrant::Action::Builtin::WaitForCommunicator,
67
+ Action::MountNFS
68
+ )
69
+ end
70
+
71
+ action_hook(:nfs_guest, :machine_action_halt) do |hook|
72
+ require_relative "action/unmount_nfs"
73
+ hook.before(
74
+ Vagrant::Action::Builtin::GracefulHalt,
75
+ Action::UnmountNFS
76
+ )
77
+ end
78
+
79
+ action_hook(:nfs_guest, :machine_action_reload) do |hook|
80
+ require_relative "action/unmount_nfs"
81
+ require_relative "action/mount_nfs"
82
+ hook.before(
83
+ Vagrant::Action::Builtin::GracefulHalt,
84
+ Action::UnmountNFS
85
+ )
86
+ hook.before(
87
+ Vagrant::Action::Builtin::SyncedFolders,
88
+ Action::MountNFS
89
+ )
90
+ end
91
+
92
+ action_hook(:nfs_guest, :machine_action_destroy) do |hook|
93
+ require_relative "action/unmount_nfs"
94
+ hook.after(
95
+ Vagrant::Action::Builtin::DestroyConfirm,
96
+ Action::UnmountNFS
97
+ )
98
+ end
99
+
100
+ action_hook(:nfs_guest, :machine_action_package) do |hook|
101
+ require_relative "action/unmount_nfs"
102
+ hook.before(
103
+ Vagrant::Action::Builtin::GracefulHalt,
104
+ Action::UnmountNFS
105
+ )
106
+ end
107
+ end
108
+ end
109
+ end