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,19 @@
1
+ module VagrantPlugins
2
+ module SyncedFolderNFSGuest
3
+ module ProviderDocker
4
+ module Cap
5
+
6
+ def self.nfs_settings(machine)
7
+ provider = machine.provider
8
+
9
+ host_ip = provider.driver.docker_bridge_ip
10
+ machine_ip = provider.ssh_info[:host]
11
+
12
+ raise Vagrant::Errors::NFSNoHostonlyNetwork if !host_ip || !machine_ip
13
+
14
+ return host_ip, machine_ip
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module SyncedFolderNFSGuest
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "docker-provider"
7
+ description "Docker provider"
8
+
9
+ provider_capability(:docker, :nfs_settings) do
10
+ require_relative "cap/nfs_settings"
11
+ ProviderDocker::Cap
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module VagrantPlugins
2
+ module SyncedFolderNFSGuest
3
+ module ProviderParallels
4
+ module Cap
5
+
6
+ def self.nfs_settings(machine)
7
+ host_ip = machine.provider.driver.read_shared_interface[:ip]
8
+ machine_ip = machine.provider.driver.read_guest_ip
9
+
10
+ raise Vagrant::Errors::NFSNoHostonlyNetwork if !host_ip || !machine_ip
11
+
12
+ return host_ip, machine_ip
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module SyncedFolderNFSGuest
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "vagrant-parallels"
7
+ description "Parallels provider"
8
+
9
+ provider_capability(:parallels, :nfs_settings) do
10
+ require_relative "cap/nfs_settings"
11
+ ProviderParallels::Cap
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,89 @@
1
+ require "vagrant/util/retryable"
2
+
3
+ module VagrantPlugins
4
+ module SyncedFolderNFSGuest
5
+ module ProviderVirtualBox
6
+ module Cap
7
+ extend Vagrant::Util::Retryable
8
+
9
+ def self.nfs_settings(machine)
10
+ adapter, host_ip = self.find_host_only_adapter(machine)
11
+ machine_ip = self.read_static_machine_ips(machine) || self.read_dynamic_machine_ip(machine, adapter)
12
+
13
+ raise Vagrant::Errors::NFSNoHostonlyNetwork if !host_ip || !machine_ip
14
+
15
+ return host_ip, machine_ip
16
+ end
17
+
18
+ # Finds first host only network adapter and returns its adapter number
19
+ # and IP address
20
+ #
21
+ # @return [Integer, String] adapter number, ip address of found host-only adapter
22
+ def self.find_host_only_adapter(machine)
23
+ machine.provider.driver.read_network_interfaces.each do |adapter, opts|
24
+ if opts[:type] == :hostonly
25
+ machine.provider.driver.read_host_only_interfaces.each do |interface|
26
+ if interface[:name] == opts[:hostonly]
27
+ return adapter, interface[:ip]
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ nil
34
+ end
35
+
36
+ # Returns the IP address(es) of the guest by looking for static IPs
37
+ # given to host only adapters in the Vagrantfile
38
+ #
39
+ # @return [Array]<String> Configured static IPs
40
+ def self.read_static_machine_ips(machine)
41
+ ips = []
42
+ machine.config.vm.networks.each do |type, options|
43
+ if type == :private_network && options[:type] != :dhcp && options[:ip].is_a?(String)
44
+ ips << options[:ip]
45
+ end
46
+ end
47
+
48
+ if ips.empty?
49
+ return nil
50
+ end
51
+
52
+ ips
53
+ end
54
+
55
+ # Returns the IP address of the guest by looking at vbox guest property
56
+ # for the appropriate guest adapter.
57
+ #
58
+ # For DHCP interfaces, the guest property will not be present until the
59
+ # guest completes
60
+ #
61
+ # @param [Integer] adapter number to read IP for
62
+ # @return [String] ip address of adapter
63
+ def self.read_dynamic_machine_ip(machine, adapter)
64
+ return nil unless adapter
65
+
66
+ # vbox guest properties are 0-indexed, while showvminfo network
67
+ # interfaces are 1-indexed. go figure.
68
+ guestproperty_adapter = adapter - 1
69
+
70
+ # we need to wait for the guest's IP to show up as a guest property.
71
+ # retry thresholds are relatively high since we might need to wait
72
+ # for DHCP, but even static IPs can take a second or two to appear.
73
+ retryable(retry_options.merge(on: Vagrant::Errors::VirtualBoxGuestPropertyNotFound)) do
74
+ machine.provider.driver.read_guest_ip(guestproperty_adapter)
75
+ end
76
+ rescue Vagrant::Errors::VirtualBoxGuestPropertyNotFound
77
+ # this error is more specific with a better error message directing
78
+ # the user towards the fact that it's probably a reportable bug
79
+ raise Vagrant::Errors::NFSNoGuestIP
80
+ end
81
+
82
+ # Separating these out so we can stub out the sleep in tests
83
+ def self.retry_options
84
+ {tries: 15, sleep: 1}
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,15 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module SyncedFolderNFSGuest
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "VirtualBox provider"
7
+ description "VirtualBox provider"
8
+
9
+ provider_capability(:virtualbox, :nfs_settings) do
10
+ require_relative "cap/nfs_settings"
11
+ ProviderVirtualBox::Cap
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,96 @@
1
+ require 'zlib'
2
+
3
+ module VagrantPlugins
4
+ module SyncedFolderNFSGuest
5
+ class SyncedFolder < Vagrant.plugin("2", :synced_folder)
6
+
7
+ def initialize(*args)
8
+ super
9
+
10
+ @logger = Log4r::Logger.new("vagrant::synced_folders::nfs_guest")
11
+ end
12
+
13
+ def usable?(machine, raise_error=false)
14
+ # If the machine explicitly said NFS is not supported, then
15
+ # it isn't supported.
16
+ if !machine.config.nfs_guest.functional
17
+ return false
18
+ end
19
+ return true if machine.env.host.capability(:nfs_installed)
20
+ return false if !raise_error
21
+ raise Vagrant::Errors::NFSNotSupported
22
+ end
23
+
24
+ def enable(machine, folders, nfsopts)
25
+ if !machine.provider.capability?(:nfs_settings)
26
+ raise Errors::ProviderNFSSettingsCapMissing
27
+ end
28
+
29
+ # I've abstracted this out to a plugin provided capability per
30
+ # provider as it's impossible to resume a VM because the
31
+ # PrepareNFSSettings action NEVER is trigger on a resume because
32
+ # the host is exporting so therefore it's assumed to always be there.
33
+ # Easier to maintain and add new providers this way.
34
+ host_ip, machine_ip = machine.provider.capability(:nfs_settings)
35
+ machine_ip = [machine_ip] if !machine_ip.is_a?(Array)
36
+
37
+ raise Vagrant::Errors::NFSNoHostIP if !host_ip
38
+ raise Vagrant::Errors::NFSNoGuestIP if !machine_ip
39
+
40
+ if machine.config.nfs_guest.verify_installed
41
+ if machine.guest.capability?(:nfs_server_installed)
42
+ installed = machine.guest.capability(:nfs_server_installed)
43
+ if !installed
44
+ can_install = machine.guest.capability?(:nfs_server_install)
45
+ raise Errors::NFSServerNotInstalledInGuest if !can_install
46
+ machine.ui.info I18n.t("vagrant_nfs_guest.guests.linux.nfs_server_installing")
47
+ machine.guest.capability(:nfs_server_install)
48
+ end
49
+ end
50
+ end
51
+
52
+ # Prepare the folder, this means setting up various options
53
+ # and such on the folder itself.
54
+ folders.each { |id, opts| prepare_folder(machine, opts) }
55
+
56
+ # Only mount folders that have a guest path specified.
57
+ mount_folders = {}
58
+ folders.each do |id, opts|
59
+ mount_folders[id] = opts.dup if opts[:guestpath]
60
+ end
61
+
62
+ machine.ui.info I18n.t("vagrant_nfs_guest.actions.vm.nfs.exporting")
63
+ machine.guest.capability(:nfs_export, host_ip, mount_folders)
64
+ end
65
+
66
+ protected
67
+
68
+ def prepare_folder(machine, opts)
69
+ opts[:map_uid] = prepare_permission(machine, :uid, opts)
70
+ opts[:map_gid] = prepare_permission(machine, :gid, opts)
71
+ opts[:nfs_udp] = true if !opts.has_key?(:nfs_udp)
72
+ opts[:nfs_version] ||= 3
73
+
74
+ # We use a CRC32 to generate a 32-bit checksum so that the
75
+ # fsid is compatible with both old and new kernels.
76
+ opts[:uuid] = Zlib.crc32(opts[:hostpath]).to_s
77
+ end
78
+
79
+ # Prepares the UID/GID settings for a single folder.
80
+ def prepare_permission(machine, perm, opts)
81
+ key = "map_#{perm}".to_sym
82
+ return nil if opts.has_key?(key) && opts[key].nil?
83
+
84
+ # The options on the hash get priority, then the default
85
+ # values
86
+ value = opts.has_key?(key) ? opts[key] : machine.config.nfs.send(key)
87
+ return value if value != :auto
88
+
89
+ # Get UID/GID from guests user if we've made it this far
90
+ # (value == :auto)
91
+ return machine.guest.capability("read_#{perm}".to_sym)
92
+ end
93
+ end
94
+ end
95
+ end
96
+
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module SyncedFolderNFSGuest
3
+ VERSION = "0.1.9"
4
+ end
5
+ end
@@ -0,0 +1,69 @@
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
+ nfs_server_installing: "Installing nfs server on the guest..."
13
+ nfs_setup_firewall: "Setup firewall on the guest to allow NFS exports..."
14
+
15
+ errors:
16
+ nfs_update_exports_failed: |-
17
+ There was an error updating the guests /etc/exports file.
18
+
19
+ %{command}
20
+
21
+ Stdout from the command:
22
+ %{stdout}
23
+
24
+ Stderr from the command:
25
+ %{stderr}
26
+ nfs_start_failed: |-
27
+ Something failed while starting the NFS service on the guest.
28
+
29
+ %{command}
30
+
31
+ Stdout from the command:
32
+ %{stdout}
33
+
34
+ Stderr from the command:
35
+ %{stderr}
36
+ nfs_apply_failed: |-
37
+ Something failed while applying changes to the NFS service on the guest.
38
+
39
+ %{command}
40
+
41
+ Stdout from the command:
42
+ %{stdout}
43
+
44
+ Stderr from the command:
45
+ %{stderr}
46
+ nfs_create_mounts_failed: |-
47
+ Something failed while creating the NFS mounts on the guest.
48
+
49
+ %{command}
50
+
51
+ Stdout from the command:
52
+ %{stdout}
53
+
54
+ Stderr from the command:
55
+ %{stderr}
56
+
57
+ nfs_server_missing: |-
58
+ Guest is missing the required NFS server daemon.
59
+
60
+ nfs_server_not_installed: |-
61
+ Guest cannot install the required NFS server daemon.
62
+
63
+ nfs_guest_clean: |-
64
+ Something failed while cleaning up NFS shared folders on the guest.
65
+
66
+ provider_missing_nfs_setting_cap: |-
67
+ Missing provider support in vagrant-nfs_guest plugin for retrieving host and guest IPs.
68
+
69
+ Currently only Virtualbox provider is supported.
@@ -0,0 +1,7 @@
1
+ # VAGRANT-NFS_GUEST-BEGIN
2
+ <% ips.each do |ip| %>
3
+ <% folders.each do |dirs, opts| %>
4
+ "<%= opts[:guestpath] %>" <%= ip %>(<%= opts[:linux__nfs_options].join(",") %>)
5
+ <% end %>
6
+ <% end %>
7
+ # VAGRANT-NFS_GUEST-END
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-nfs_guest/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-nfs_guest_vbfix"
8
+ spec.version = VagrantPlugins::SyncedFolderNFSGuest::VERSION
9
+ spec.authors = ["Alan Garfield", "Liam Staskawicz"]
10
+ spec.email = ["alan.garfield@learnosity.com", "liam@3drobotics.com"]
11
+ spec.description = %q{Adds support for guest nfs exporting of synced folders}
12
+ spec.summary = %q{Adds support for guest nfs exporting of synced folders}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-nfs_guest_vbfix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.9
5
+ platform: ruby
6
+ authors:
7
+ - Alan Garfield
8
+ - Liam Staskawicz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-04-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: Adds support for guest nfs exporting of synced folders
43
+ email:
44
+ - alan.garfield@learnosity.com
45
+ - liam@3drobotics.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - ".ruby-version"
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - example_box/Vagrantfile
57
+ - example_box/vagrant_share/.keep
58
+ - lib/vagrant-nfs_guest.rb
59
+ - lib/vagrant-nfs_guest/action/mount_nfs.rb
60
+ - lib/vagrant-nfs_guest/action/unmount_nfs.rb
61
+ - lib/vagrant-nfs_guest/config.rb
62
+ - lib/vagrant-nfs_guest/errors.rb
63
+ - lib/vagrant-nfs_guest/guests/debian/cap/nfs_server.rb
64
+ - lib/vagrant-nfs_guest/guests/debian/plugin.rb
65
+ - lib/vagrant-nfs_guest/guests/linux/cap/nfs_server.rb
66
+ - lib/vagrant-nfs_guest/guests/linux/cap/read_user_ids.rb
67
+ - lib/vagrant-nfs_guest/guests/linux/plugin.rb
68
+ - lib/vagrant-nfs_guest/guests/redhat/cap/nfs_server.rb
69
+ - lib/vagrant-nfs_guest/guests/redhat/plugin.rb
70
+ - lib/vagrant-nfs_guest/guests/ubuntu/cap/nfs_server.rb
71
+ - lib/vagrant-nfs_guest/guests/ubuntu/plugin.rb
72
+ - lib/vagrant-nfs_guest/hosts/bsd/cap/mount_nfs.rb
73
+ - lib/vagrant-nfs_guest/hosts/bsd/cap/unmount_nfs.rb
74
+ - lib/vagrant-nfs_guest/hosts/bsd/plugin.rb
75
+ - lib/vagrant-nfs_guest/hosts/linux/cap/mount_nfs.rb
76
+ - lib/vagrant-nfs_guest/hosts/linux/cap/unmount_nfs.rb
77
+ - lib/vagrant-nfs_guest/hosts/linux/plugin.rb
78
+ - lib/vagrant-nfs_guest/plugin.rb
79
+ - lib/vagrant-nfs_guest/providers/docker/cap/nfs_settings.rb
80
+ - lib/vagrant-nfs_guest/providers/docker/plugin.rb
81
+ - lib/vagrant-nfs_guest/providers/parallels/cap/nfs_settings.rb
82
+ - lib/vagrant-nfs_guest/providers/parallels/plugin.rb
83
+ - lib/vagrant-nfs_guest/providers/virtualbox/cap/nfs_settings.rb
84
+ - lib/vagrant-nfs_guest/providers/virtualbox/plugin.rb
85
+ - lib/vagrant-nfs_guest/synced_folder.rb
86
+ - lib/vagrant-nfs_guest/version.rb
87
+ - templates/locales/en.yml
88
+ - templates/nfs_guest/guest_export_linux.erb
89
+ - vagrant-nfs_guest.gemspec
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.5.1
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Adds support for guest nfs exporting of synced folders
114
+ test_files: []