vagrant-unbundled 2.2.6.0 → 2.2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.hashibot.hcl +14 -0
  3. data/CHANGELOG.md +93 -2
  4. data/README.md +1 -3
  5. data/bin/vagrant +23 -0
  6. data/contrib/bash/completion.sh +13 -1
  7. data/lib/vagrant.rb +25 -0
  8. data/lib/vagrant/action.rb +5 -0
  9. data/lib/vagrant/action/builder.rb +145 -24
  10. data/lib/vagrant/action/builtin/box_add.rb +11 -4
  11. data/lib/vagrant/action/builtin/box_check_outdated.rb +12 -15
  12. data/lib/vagrant/action/builtin/cleanup_disks.rb +56 -0
  13. data/lib/vagrant/action/builtin/delayed.rb +26 -0
  14. data/lib/vagrant/action/builtin/disk.rb +52 -0
  15. data/lib/vagrant/action/builtin/handle_box.rb +2 -0
  16. data/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb +28 -9
  17. data/lib/vagrant/action/builtin/mixin_provisioners.rb +19 -1
  18. data/lib/vagrant/action/builtin/ssh_run.rb +21 -3
  19. data/lib/vagrant/action/builtin/trigger.rb +36 -0
  20. data/lib/vagrant/action/hook.rb +20 -2
  21. data/lib/vagrant/action/runner.rb +11 -26
  22. data/lib/vagrant/action/warden.rb +4 -18
  23. data/lib/vagrant/box_metadata.rb +17 -3
  24. data/lib/vagrant/bundler.rb +260 -53
  25. data/lib/vagrant/cli.rb +4 -2
  26. data/lib/vagrant/errors.rb +24 -0
  27. data/lib/vagrant/machine.rb +9 -6
  28. data/lib/vagrant/plugin/manager.rb +25 -14
  29. data/lib/vagrant/plugin/v2/command.rb +1 -1
  30. data/lib/vagrant/plugin/v2/manager.rb +53 -0
  31. data/lib/vagrant/plugin/v2/plugin.rb +1 -0
  32. data/lib/vagrant/plugin/v2/trigger.rb +64 -26
  33. data/lib/vagrant/shared_helpers.rb +28 -0
  34. data/lib/vagrant/ui.rb +50 -4
  35. data/lib/vagrant/util.rb +1 -0
  36. data/lib/vagrant/util/curl_helper.rb +8 -5
  37. data/lib/vagrant/util/downloader.rb +5 -1
  38. data/lib/vagrant/util/file_checksum.rb +6 -2
  39. data/lib/vagrant/util/guest_inspection.rb +9 -1
  40. data/lib/vagrant/util/io.rb +7 -27
  41. data/lib/vagrant/util/is_port_open.rb +1 -2
  42. data/lib/vagrant/util/map_command_options.rb +33 -0
  43. data/lib/vagrant/util/numeric.rb +69 -0
  44. data/lib/vagrant/util/platform.rb +8 -1
  45. data/plugins/commands/box/command/outdated.rb +14 -2
  46. data/plugins/commands/cloud/locales/en.yml +1 -1
  47. data/plugins/commands/cloud/publish.rb +1 -1
  48. data/plugins/commands/snapshot/command/save.rb +13 -8
  49. data/plugins/commands/ssh_config/command.rb +1 -1
  50. data/plugins/communicators/ssh/communicator.rb +18 -23
  51. data/plugins/communicators/winrm/config.rb +1 -1
  52. data/plugins/communicators/winrm/shell.rb +1 -1
  53. data/plugins/communicators/winssh/communicator.rb +126 -38
  54. data/plugins/communicators/winssh/config.rb +3 -7
  55. data/plugins/guests/alpine/cap/rsync.rb +1 -1
  56. data/plugins/guests/alpine/plugin.rb +16 -0
  57. data/plugins/guests/centos/cap/flavor.rb +24 -0
  58. data/plugins/guests/centos/guest.rb +9 -0
  59. data/plugins/guests/centos/plugin.rb +20 -0
  60. data/plugins/guests/darwin/cap/mount_vmware_shared_folder.rb +99 -13
  61. data/plugins/guests/darwin/plugin.rb +5 -0
  62. data/plugins/guests/debian/cap/configure_networks.rb +14 -6
  63. data/plugins/guests/linux/cap/halt.rb +9 -1
  64. data/plugins/guests/linux/cap/mount_smb_shared_folder.rb +16 -0
  65. data/plugins/guests/linux/cap/reboot.rb +48 -0
  66. data/plugins/guests/linux/plugin.rb +10 -0
  67. data/plugins/guests/redhat/cap/flavor.rb +3 -1
  68. data/plugins/guests/redhat/cap/nfs_client.rb +2 -2
  69. data/plugins/guests/redhat/cap/smb.rb +20 -0
  70. data/plugins/guests/redhat/plugin.rb +5 -0
  71. data/plugins/guests/suse/cap/change_host_name.rb +2 -2
  72. data/plugins/guests/windows/cap/public_key.rb +3 -3
  73. data/plugins/guests/windows/cap/reboot.rb +2 -1
  74. data/plugins/hosts/darwin/cap/nfs.rb +11 -0
  75. data/plugins/hosts/darwin/plugin.rb +5 -0
  76. data/plugins/hosts/linux/cap/nfs.rb +21 -2
  77. data/plugins/kernel_v2/config/disk.rb +199 -0
  78. data/plugins/kernel_v2/config/ssh_connect.rb +24 -0
  79. data/plugins/kernel_v2/config/vm.rb +109 -4
  80. data/plugins/kernel_v2/config/vm_provisioner.rb +4 -1
  81. data/plugins/kernel_v2/config/vm_trigger.rb +2 -5
  82. data/plugins/providers/docker/driver.rb +38 -10
  83. data/plugins/providers/docker/errors.rb +4 -0
  84. data/plugins/providers/docker/executor/local.rb +7 -1
  85. data/plugins/providers/hyperv/action/export.rb +4 -2
  86. data/plugins/providers/hyperv/driver.rb +10 -9
  87. data/plugins/providers/hyperv/scripts/set_vm_integration_services.ps1 +3 -3
  88. data/plugins/providers/hyperv/scripts/utils/VagrantVM/VagrantVM.psm1 +6 -6
  89. data/plugins/providers/virtualbox/action.rb +2 -0
  90. data/plugins/providers/virtualbox/action/clean_machine_folder.rb +10 -1
  91. data/plugins/providers/virtualbox/action/export.rb +4 -2
  92. data/plugins/providers/virtualbox/action/import.rb +8 -4
  93. data/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb +4 -2
  94. data/plugins/providers/virtualbox/action/snapshot_delete.rb +4 -2
  95. data/plugins/providers/virtualbox/action/snapshot_restore.rb +4 -2
  96. data/plugins/providers/virtualbox/cap/cleanup_disks.rb +54 -0
  97. data/plugins/providers/virtualbox/cap/configure_disks.rb +287 -0
  98. data/plugins/providers/virtualbox/cap/validate_disk_ext.rb +27 -0
  99. data/plugins/providers/virtualbox/driver/base.rb +15 -0
  100. data/plugins/providers/virtualbox/driver/meta.rb +14 -2
  101. data/plugins/providers/virtualbox/driver/version_5_0.rb +142 -2
  102. data/plugins/providers/virtualbox/driver/version_6_1.rb +39 -0
  103. data/plugins/providers/virtualbox/plugin.rb +21 -0
  104. data/plugins/provisioners/ansible/cap/guest/alpine/ansible_install.rb +44 -0
  105. data/plugins/provisioners/ansible/cap/guest/arch/ansible_install.rb +20 -3
  106. data/plugins/provisioners/ansible/cap/guest/debian/ansible_install.rb +4 -5
  107. data/plugins/provisioners/ansible/cap/guest/fedora/ansible_install.rb +2 -2
  108. data/plugins/provisioners/ansible/cap/guest/freebsd/ansible_install.rb +2 -2
  109. data/plugins/provisioners/ansible/cap/guest/pip/pip.rb +8 -4
  110. data/plugins/provisioners/ansible/cap/guest/redhat/ansible_install.rb +2 -2
  111. data/plugins/provisioners/ansible/cap/guest/suse/ansible_install.rb +2 -1
  112. data/plugins/provisioners/ansible/cap/guest/ubuntu/ansible_install.rb +3 -3
  113. data/plugins/provisioners/ansible/plugin.rb +5 -0
  114. data/plugins/provisioners/ansible/provisioner/base.rb +1 -1
  115. data/plugins/provisioners/container/client.rb +203 -0
  116. data/plugins/provisioners/container/config.rb +83 -0
  117. data/plugins/provisioners/container/installer.rb +13 -0
  118. data/plugins/provisioners/container/plugin.rb +23 -0
  119. data/plugins/provisioners/container/provisioner.rb +28 -0
  120. data/plugins/provisioners/docker/cap/{redhat → centos}/docker_install.rb +10 -7
  121. data/plugins/provisioners/docker/cap/centos/docker_start_service.rb +24 -0
  122. data/plugins/provisioners/docker/client.rb +4 -175
  123. data/plugins/provisioners/docker/config.rb +2 -72
  124. data/plugins/provisioners/docker/installer.rb +3 -5
  125. data/plugins/provisioners/docker/plugin.rb +6 -6
  126. data/plugins/provisioners/docker/provisioner.rb +4 -10
  127. data/plugins/provisioners/podman/cap/centos/podman_install.rb +35 -0
  128. data/plugins/provisioners/podman/cap/linux/podman_installed.rb +13 -0
  129. data/plugins/provisioners/podman/cap/redhat/podman_install.rb +26 -0
  130. data/plugins/provisioners/podman/client.rb +12 -0
  131. data/plugins/provisioners/podman/config.rb +28 -0
  132. data/plugins/provisioners/podman/installer.rb +33 -0
  133. data/plugins/provisioners/podman/plugin.rb +38 -0
  134. data/plugins/provisioners/podman/provisioner.rb +52 -0
  135. data/plugins/provisioners/salt/provisioner.rb +4 -0
  136. data/plugins/provisioners/shell/config.rb +1 -6
  137. data/plugins/provisioners/shell/provisioner.rb +54 -25
  138. data/plugins/synced_folders/smb/synced_folder.rb +1 -1
  139. data/templates/commands/init/Vagrantfile.erb +1 -1
  140. data/templates/locales/en.yml +123 -4
  141. data/templates/locales/providers_docker.yml +2 -0
  142. data/templates/nfs/exports_darwin.erb +7 -0
  143. data/vagrant.gemspec +8 -9
  144. data/version.txt +1 -1
  145. metadata +3731 -3663
  146. data/lib/vagrant/action/builtin/after_trigger.rb +0 -31
  147. data/lib/vagrant/action/builtin/before_trigger.rb +0 -28
  148. data/plugins/provisioners/docker/cap/redhat/docker_start_service.rb +0 -16
@@ -6,6 +6,11 @@ module VagrantPlugins
6
6
  name "Darwin guest"
7
7
  description "Darwin guest support."
8
8
 
9
+ action_hook(:apfs_firmlinks, :synced_folders) do |hook|
10
+ require_relative "cap/mount_vmware_shared_folder"
11
+ hook.prepend(Vagrant::Action::Builtin::Delayed, Cap::MountVmwareSharedFolder.method(:write_apfs_firmlinks))
12
+ end
13
+
9
14
  guest(:darwin, :bsd) do
10
15
  require_relative "guest"
11
16
  Guest
@@ -10,7 +10,6 @@ module VagrantPlugins
10
10
  extend Vagrant::Util::GuestInspection::Linux
11
11
 
12
12
  NETPLAN_DEFAULT_VERSION = 2
13
- NETPLAN_DEFAULT_RENDERER = "networkd".freeze
14
13
  NETPLAN_DIRECTORY = "/etc/netplan".freeze
15
14
  NETWORKD_DIRECTORY = "/etc/systemd/network".freeze
16
15
 
@@ -61,12 +60,21 @@ module VagrantPlugins
61
60
  # By default, netplan expects the renderer to be systemd-networkd,
62
61
  # but if any device is managed by NetworkManager, then we use that renderer
63
62
  # ref: https://netplan.io/reference
64
- renderer = NETPLAN_DEFAULT_RENDERER
65
- ethernets.keys.each do |k|
66
- if nm_controlled?(comm, k)
67
- renderer = "NetworkManager"
68
- break
63
+ if systemd_networkd?(comm)
64
+ renderer = "networkd"
65
+ ethernets.keys.each do |k|
66
+ if nm_controlled?(comm, k)
67
+ render = "NetworkManager"
68
+ if !nmcli?(comm)
69
+ raise Vagrant::Errors::NetworkManagerNotInstalled, device: k
70
+ end
71
+ break
72
+ end
69
73
  end
74
+ elsif nmcli?(comm)
75
+ renderer = "NetworkManager"
76
+ else
77
+ raise Vagrant::Errors::NetplanNoAvailableRenderers
70
78
  end
71
79
 
72
80
  np_config = {"network" => {"version" => NETPLAN_DEFAULT_VERSION,
@@ -1,10 +1,18 @@
1
+ require 'vagrant/util/guest_inspection'
2
+
1
3
  module VagrantPlugins
2
4
  module GuestLinux
3
5
  module Cap
4
6
  class Halt
7
+ extend Vagrant::Util::GuestInspection::Linux
8
+
5
9
  def self.halt(machine)
6
10
  begin
7
- machine.communicate.sudo("shutdown -h now")
11
+ if systemd?(machine.communicate)
12
+ machine.communicate.sudo("systemctl poweroff")
13
+ else
14
+ machine.communicate.sudo("shutdown -h now")
15
+ end
8
16
  rescue IOError, Vagrant::Errors::SSHDisconnected
9
17
  # Do nothing, because it probably means the machine shut down
10
18
  # and SSH connection was lost.
@@ -1,3 +1,4 @@
1
+ require "fileutils"
1
2
  require "shellwords"
2
3
  require_relative "../../../synced_folders/unix_mount_helpers"
3
4
 
@@ -34,10 +35,17 @@ module VagrantPlugins
34
35
  mnt_opts << "credentials=/etc/smb_creds_#{name}"
35
36
  mnt_opts << "uid=#{mount_uid}"
36
37
  mnt_opts << "gid=#{mount_gid}"
38
+ if !ENV['VAGRANT_DISABLE_SMBMFSYMLINKS']
39
+ mnt_opts << "mfsymlinks"
40
+ end
37
41
 
38
42
  mnt_opts = merge_mount_options(mnt_opts, options[:mount_options] || [])
39
43
 
40
44
  mount_options = "-o #{mnt_opts.join(",")}"
45
+ if mount_options.include?("mfsymlinks")
46
+ display_mfsymlinks_warning(machine.env)
47
+ end
48
+
41
49
  mount_command = "mount -t cifs #{mount_options} #{mount_device} #{expanded_guest_path}"
42
50
 
43
51
  # Create the guest path if it doesn't exist
@@ -94,6 +102,14 @@ SCRIPT
94
102
  [key, value].compact.join("=")
95
103
  end
96
104
  end
105
+
106
+ def self.display_mfsymlinks_warning(env)
107
+ d_file = env.data_dir.join("mfsymlinks_warning")
108
+ if !d_file.exist?
109
+ FileUtils.touch(d_file.to_path)
110
+ env.ui.warn(I18n.t("vagrant.actions.vm.smb.mfsymlink_warning"))
111
+ end
112
+ end
97
113
  end
98
114
  end
99
115
  end
@@ -0,0 +1,48 @@
1
+ require 'vagrant/util/guest_inspection'
2
+ require "log4r"
3
+
4
+ module VagrantPlugins
5
+ module GuestLinux
6
+ module Cap
7
+ class Reboot
8
+ extend Vagrant::Util::GuestInspection::Linux
9
+ MAX_REBOOT_RETRY_DURATION = 120
10
+
11
+ def self.reboot(machine)
12
+ @logger = Log4r::Logger.new("vagrant::linux::reboot")
13
+ if systemd?(machine.communicate)
14
+ reboot_script = "systemctl reboot"
15
+ else
16
+ reboot_script = "reboot"
17
+ end
18
+
19
+ comm = machine.communicate
20
+
21
+ @logger.debug("Issuing reboot command for guest")
22
+ comm.sudo(reboot_script)
23
+
24
+ machine.ui.info(I18n.t("vagrant.guests.capabilities.rebooting"))
25
+
26
+ @logger.debug("Waiting for machine to finish rebooting")
27
+
28
+ wait_remaining = MAX_REBOOT_RETRY_DURATION
29
+ begin
30
+ wait_for_reboot(machine)
31
+ rescue Vagrant::Errors::MachineGuestNotReady => e
32
+ raise if wait_remaining < 0
33
+ @logger.warn("Machine not ready, cannot start reboot yet. Trying again")
34
+ sleep(5)
35
+ wait_remaining -= 5
36
+ retry
37
+ end
38
+ end
39
+
40
+ def self.wait_for_reboot(machine)
41
+ while !machine.guest.ready?
42
+ sleep 10
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -82,6 +82,16 @@ module VagrantPlugins
82
82
  Cap::ReadIPAddress
83
83
  end
84
84
 
85
+ guest_capability(:linux, :wait_for_reboot) do
86
+ require_relative "cap/reboot"
87
+ Cap::Reboot
88
+ end
89
+
90
+ guest_capability(:linux, :reboot) do
91
+ require_relative "cap/reboot"
92
+ Cap::Reboot
93
+ end
94
+
85
95
  guest_capability(:linux, :remove_public_key) do
86
96
  require_relative "cap/public_key"
87
97
  Cap::PublicKey
@@ -10,8 +10,10 @@ module VagrantPlugins
10
10
  end
11
11
 
12
12
  # Detect various flavors we care about
13
- if output =~ /(CentOS|Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 7/i
13
+ if output =~ /(Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 7/i
14
14
  return :rhel_7
15
+ elsif output =~ /(Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 8/i
16
+ return :rhel_8
15
17
  else
16
18
  return :rhel
17
19
  end
@@ -5,7 +5,7 @@ module VagrantPlugins
5
5
  def self.nfs_client_install(machine)
6
6
  machine.communicate.sudo <<-EOH.gsub(/^ {12}/, '')
7
7
  if command -v dnf; then
8
- if `dnf info -q libnfs-utils > /dev/null 2>&1` ; then
8
+ if `dnf info -q libnfs-utils > /dev/null 2>&1` ; then
9
9
  dnf -y install nfs-utils libnfs-utils portmap
10
10
  else
11
11
  dnf -y install nfs-utils nfs-utils-lib portmap
@@ -15,7 +15,7 @@ module VagrantPlugins
15
15
  fi
16
16
 
17
17
  if test $(ps -o comm= 1) == 'systemd'; then
18
- /bin/systemctl restart rpcbind nfs
18
+ /bin/systemctl restart rpcbind nfs-server
19
19
  else
20
20
  /etc/init.d/rpcbind restart
21
21
  /etc/init.d/nfs restart
@@ -0,0 +1,20 @@
1
+ module VagrantPlugins
2
+ module GuestRedHat
3
+ module Cap
4
+ class SMB
5
+ def self.smb_install(machine)
6
+ comm = machine.communicate
7
+ if !comm.test("test -f /sbin/mount.cifs")
8
+ comm.sudo <<-EOH.gsub(/^ {14}/, '')
9
+ if command -v dnf; then
10
+ dnf -y install cifs-utils
11
+ else
12
+ yum -y install cifs-utils
13
+ fi
14
+ EOH
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -40,6 +40,11 @@ module VagrantPlugins
40
40
  require_relative "cap/rsync"
41
41
  Cap::RSync
42
42
  end
43
+
44
+ guest_capability(:redhat, :smb_install) do
45
+ require_relative "cap/smb"
46
+ Cap::SMB
47
+ end
43
48
  end
44
49
  end
45
50
  end
@@ -5,8 +5,8 @@ module VagrantPlugins
5
5
  def self.change_host_name(machine, name)
6
6
  comm = machine.communicate
7
7
 
8
- if !comm.test("getent hosts '#{name}'", sudo: false)
9
- basename = name.split(".", 2)[0]
8
+ basename = name.split(".", 2)[0]
9
+ if !comm.test('test "$(hostnamectl --static status)" = "#{basename}"', sudo: false)
10
10
  comm.sudo <<-EOH.gsub(/^ {14}/, '')
11
11
  hostnamectl set-hostname '#{basename}'
12
12
 
@@ -37,7 +37,7 @@ module VagrantPlugins
37
37
 
38
38
  # Ensure the user's ssh directory exists
39
39
  remote_ssh_dir = "#{home_dir}\\.ssh"
40
- comm.execute("dir \"#{remote_ssh_dir}\"\n if errorlevel 1 (mkdir \"#{remote_ssh_dir}\")", shell: "cmd")
40
+ comm.execute("New-Item -Path '#{remote_ssh_dir}' -ItemType directory -Force", shell: "powershell")
41
41
  remote_upload_path = "#{temp_dir}\\vagrant-insert-pubkey-#{Time.now.to_i}"
42
42
  remote_authkeys_path = "#{remote_ssh_dir}\\authorized_keys"
43
43
 
@@ -55,7 +55,7 @@ module VagrantPlugins
55
55
  File.write(keys_file.path, keys.join("\r\n") + "\r\n")
56
56
  comm.upload(keys_file.path, remote_upload_path)
57
57
  keys_file.delete
58
- comm.execute <<-EOC.gsub(/^\s*/, ""), shell: "powershell"
58
+ comm.execute(<<-EOC.gsub(/^\s*/, ""), shell: "powershell")
59
59
  Set-Acl "#{remote_upload_path}" (Get-Acl "#{remote_authkeys_path}")
60
60
  Move-Item -Force "#{remote_upload_path}" "#{remote_authkeys_path}"
61
61
  EOC
@@ -67,7 +67,7 @@ module VagrantPlugins
67
67
  # @return [Hash] {:temp, :home}
68
68
  def self.fetch_guest_paths(communicator)
69
69
  output = ""
70
- communicator.execute("echo %TEMP%\necho %USERPROFILE%", shell: "cmd") do |type, data|
70
+ communicator.execute("Write-Output $env:TEMP\nWrite-Output $env:USERPROFILE", shell: "powershell") do |type, data|
71
71
  if type == :stdout
72
72
  output << data
73
73
  end
@@ -28,8 +28,9 @@ module VagrantPlugins
28
28
  wait_remaining = MAX_REBOOT_RETRY_DURATION
29
29
  begin
30
30
  wait_for_reboot(machine)
31
- rescue HTTPClient::ConnectTimeoutError, Vagrant::Errors::MachineGuestNotReady, WinRM::WinRMHTTPTransportError => e
31
+ rescue => err
32
32
  raise if wait_remaining < 0
33
+ @logger.debug("Exception caught while waiting for reboot: #{err}")
33
34
  @logger.warn("Machine not ready, cannot start reboot yet. Trying again")
34
35
  sleep(5)
35
36
  wait_remaining -= 5
@@ -0,0 +1,11 @@
1
+ module VagrantPlugins
2
+ module HostDarwin
3
+ module Cap
4
+ class NFS
5
+ def self.nfs_exports_template(environment)
6
+ "nfs/exports_darwin"
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -55,6 +55,11 @@ module VagrantPlugins
55
55
  require_relative "cap/configured_ip_addresses"
56
56
  Cap::ConfiguredIPAddresses
57
57
  end
58
+
59
+ host_capability("darwin", "nfs_exports_template") do
60
+ require_relative "cap/nfs"
61
+ Cap::NFS
62
+ end
58
63
  end
59
64
  end
60
65
  end
@@ -67,6 +67,7 @@ module VagrantPlugins
67
67
 
68
68
  nfs_opts_setup(folders)
69
69
  folders = folder_dupe_check(folders)
70
+ ips = ips.uniq
70
71
  output = Vagrant::Util::TemplateRenderer.render('nfs/exports_linux',
71
72
  uuid: id,
72
73
  ips: ips,
@@ -77,7 +78,7 @@ module VagrantPlugins
77
78
  sleep 0.5
78
79
 
79
80
  nfs_cleanup("#{Process.uid} #{id}")
80
- output = "#{nfs_exports_content}\n#{output}"
81
+ output = nfs_exports_content + output
81
82
  nfs_write_exports(output)
82
83
 
83
84
  if nfs_running?(nfs_check_command)
@@ -93,7 +94,7 @@ module VagrantPlugins
93
94
  "systemctl --no-pager --no-legend --plain list-unit-files --all --type=service " \
94
95
  "| grep #{nfs_service_name_systemd}").exit_code == 0
95
96
  else
96
- Vagrant::Util::Subprocess.execute("modinfo", "nfsd").exit_code == 0 ||
97
+ Vagrant::Util::Subprocess.execute(modinfo_path, "nfsd").exit_code == 0 ||
97
98
  Vagrant::Util::Subprocess.execute("grep", "nfsd", "/proc/filesystems").exit_code == 0
98
99
  end
99
100
  end
@@ -261,6 +262,24 @@ module VagrantPlugins
261
262
  Vagrant::Util::Subprocess.execute(*Shellwords.split(check_command)).exit_code == 0
262
263
  end
263
264
 
265
+ def self.modinfo_path
266
+ if !defined?(@_modinfo_path)
267
+ @_modinfo_path = Vagrant::Util::Which.which("modinfo")
268
+
269
+ if @_modinfo_path.to_s.empty?
270
+ path = "/sbin/modinfo"
271
+ if File.file?(path)
272
+ @_modinfo_path = path
273
+ end
274
+ end
275
+
276
+ if @_modinfo_path.to_s.empty?
277
+ @_modinfo_path = "modinfo"
278
+ end
279
+ end
280
+ @_modinfo_path
281
+ end
282
+
264
283
  # @private
265
284
  # Reset the cached values for capability. This is not considered a public
266
285
  # API and should only be used for testing.
@@ -0,0 +1,199 @@
1
+ require "log4r"
2
+ require "securerandom"
3
+
4
+ require "vagrant/util/numeric"
5
+
6
+ module VagrantPlugins
7
+ module Kernel_V2
8
+ class VagrantConfigDisk < Vagrant.plugin("2", :config)
9
+ #-------------------------------------------------------------------
10
+ # Config class for a given Disk
11
+ #-------------------------------------------------------------------
12
+
13
+ DEFAULT_DISK_TYPES = [:disk, :dvd, :floppy].freeze
14
+
15
+ # Note: This value is for internal use only
16
+ #
17
+ # @return [String]
18
+ attr_reader :id
19
+
20
+ # File name for the given disk. Defaults to a generated name that is:
21
+ #
22
+ # vagrant_<disk_type>_<short_uuid>
23
+ #
24
+ # @return [String]
25
+ attr_accessor :name
26
+
27
+ # Type of disk to create. Defaults to `:disk`
28
+ #
29
+ # @return [Symbol]
30
+ attr_accessor :type
31
+
32
+ # Type of disk extension to create. Defaults to `vdi`
33
+ #
34
+ # @return [String]
35
+ attr_accessor :disk_ext
36
+
37
+ # Size of disk to create
38
+ #
39
+ # @return [Integer,String]
40
+ attr_accessor :size
41
+
42
+ # Path to the location of the disk file (Optional)
43
+ #
44
+ # @return [String]
45
+ attr_accessor :file
46
+
47
+ # Determines if this disk is the _main_ disk, or an attachment.
48
+ # Defaults to true.
49
+ #
50
+ # @return [Boolean]
51
+ attr_accessor :primary
52
+
53
+ # Provider specific options
54
+ #
55
+ # @return [Hash]
56
+ attr_accessor :provider_config
57
+
58
+ def initialize(type)
59
+ @logger = Log4r::Logger.new("vagrant::config::vm::disk")
60
+
61
+ @type = type
62
+ @provider_config = {}
63
+
64
+ @name = UNSET_VALUE
65
+ @provider_type = UNSET_VALUE
66
+ @size = UNSET_VALUE
67
+ @primary = UNSET_VALUE
68
+ @file = UNSET_VALUE
69
+ @disk_ext = UNSET_VALUE
70
+
71
+ # Internal options
72
+ @id = SecureRandom.uuid
73
+ end
74
+
75
+ # Helper method for storing provider specific config options
76
+ #
77
+ # Expected format is:
78
+ #
79
+ # - `provider__diskoption: value`
80
+ # - `{provider: {diskoption: value, otherdiskoption: value, ...}`
81
+ #
82
+ # Duplicates will be overriden
83
+ #
84
+ # @param [Hash] options
85
+ def add_provider_config(**options, &block)
86
+ current = {}
87
+ options.each do |k,v|
88
+ opts = k.to_s.split("__")
89
+
90
+ if opts.size == 2
91
+ current[opts[0].to_sym] = {opts[1].to_sym => v}
92
+ elsif v.is_a?(Hash)
93
+ current[k] = v
94
+ else
95
+ @logger.warn("Disk option '#{k}' found that does not match expected provider disk config schema.")
96
+ end
97
+ end
98
+
99
+ current = @provider_config.merge(current) if !@provider_config.empty?
100
+ @provider_config = current
101
+ end
102
+
103
+ def finalize!
104
+ # Ensure all config options are set to nil or default value if untouched
105
+ # by user
106
+ @type = :disk if @type == UNSET_VALUE
107
+ @size = nil if @size == UNSET_VALUE
108
+ @file = nil if @file == UNSET_VALUE
109
+
110
+ @disk_ext = "vdi" if @disk_ext == UNSET_VALUE
111
+
112
+ if @primary == UNSET_VALUE
113
+ @primary = false
114
+ end
115
+
116
+ if @name == UNSET_VALUE
117
+ if @primary
118
+ @name = "vagrant_primary"
119
+ else
120
+ @name = nil
121
+ end
122
+ end
123
+
124
+ @provider_config = nil if @provider_config == {}
125
+ end
126
+
127
+ # @return [Array] array of strings of error messages from config option validation
128
+ def validate(machine)
129
+ errors = _detected_errors
130
+
131
+ # validate type with list of known disk types
132
+
133
+ if !DEFAULT_DISK_TYPES.include?(@type)
134
+ errors << I18n.t("vagrant.config.disk.invalid_type", type: @type,
135
+ types: DEFAULT_DISK_TYPES.join(', '))
136
+ end
137
+
138
+ if @disk_ext
139
+ @disk_ext = @disk_ext.downcase
140
+
141
+ if machine.provider.capability?(:validate_disk_ext)
142
+ if !machine.provider.capability(:validate_disk_ext, @disk_ext)
143
+ if machine.provider.capability?(:get_default_disk_ext)
144
+ disk_exts = machine.provider.capability(:get_default_disk_ext).join(', ')
145
+ else
146
+ disk_exts = "not found"
147
+ end
148
+ errors << I18n.t("vagrant.config.disk.invalid_ext", ext: @disk_ext,
149
+ name: @name,
150
+ exts: disk_exts)
151
+ end
152
+ else
153
+ @logger.warn("No provider capability defined to validate 'disk_ext' type")
154
+ end
155
+ end
156
+
157
+ if @size && !@size.is_a?(Integer)
158
+ if @size.is_a?(String)
159
+ @size = Vagrant::Util::Numeric.string_to_bytes(@size)
160
+ end
161
+
162
+ if !@size
163
+ errors << I18n.t("vagrant.config.disk.invalid_size", name: @name, machine: machine.name)
164
+ end
165
+ end
166
+
167
+ if @file
168
+ if !@file.is_a?(String)
169
+ errors << I18n.t("vagrant.config.disk.invalid_file_type", file: @file, machine: machine.name)
170
+ elsif !File.file?(@file)
171
+ errors << I18n.t("vagrant.config.disk.missing_file", file_path: @file,
172
+ name: @name, machine: machine.name)
173
+ end
174
+ end
175
+
176
+ if @provider_config
177
+ if !@provider_config.keys.include?(machine.provider_name)
178
+ machine.env.ui.warn(I18n.t("vagrant.config.disk.missing_provider",
179
+ machine: machine.name,
180
+ provider_name: machine.provider_name))
181
+ end
182
+ end
183
+
184
+ if !@name
185
+ errors << I18n.t("vagrant.config.disk.no_name_set", machine: machine.name)
186
+ end
187
+
188
+ errors
189
+ end
190
+
191
+ # The String representation of this Disk.
192
+ #
193
+ # @return [String]
194
+ def to_s
195
+ "disk config"
196
+ end
197
+ end
198
+ end
199
+ end