vagrant-unbundled 2.2.6.1 → 2.2.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +4 -4
  2. data/.hashibot.hcl +14 -0
  3. data/CHANGELOG.md +153 -2
  4. data/README.md +5 -7
  5. data/bin/vagrant +23 -0
  6. data/contrib/README.md +1 -0
  7. data/contrib/bash/completion.sh +13 -1
  8. data/contrib/sudoers/linux-suse +2 -2
  9. data/contrib/zsh/_vagrant +736 -0
  10. data/contrib/zsh/generate_zsh_completion.rb +166 -0
  11. data/lib/vagrant.rb +25 -0
  12. data/lib/vagrant/action.rb +8 -0
  13. data/lib/vagrant/action/builder.rb +193 -38
  14. data/lib/vagrant/action/builtin/box_add.rb +15 -7
  15. data/lib/vagrant/action/builtin/box_check_outdated.rb +12 -15
  16. data/lib/vagrant/action/builtin/cleanup_disks.rb +56 -0
  17. data/lib/vagrant/action/builtin/cloud_init_setup.rb +127 -0
  18. data/lib/vagrant/action/builtin/cloud_init_wait.rb +30 -0
  19. data/lib/vagrant/action/builtin/delayed.rb +26 -0
  20. data/lib/vagrant/action/builtin/disk.rb +52 -0
  21. data/lib/vagrant/action/builtin/handle_box.rb +3 -1
  22. data/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb +28 -9
  23. data/lib/vagrant/action/builtin/has_provisioner.rb +36 -0
  24. data/lib/vagrant/action/builtin/mixin_provisioners.rb +20 -1
  25. data/lib/vagrant/action/builtin/mixin_synced_folders.rb +20 -21
  26. data/lib/vagrant/action/builtin/set_hostname.rb +5 -1
  27. data/lib/vagrant/action/builtin/ssh_run.rb +21 -3
  28. data/lib/vagrant/action/builtin/synced_folders.rb +10 -0
  29. data/lib/vagrant/action/builtin/trigger.rb +37 -0
  30. data/lib/vagrant/action/hook.rb +76 -23
  31. data/lib/vagrant/action/runner.rb +11 -26
  32. data/lib/vagrant/action/warden.rb +28 -22
  33. data/lib/vagrant/box.rb +5 -4
  34. data/lib/vagrant/box_metadata.rb +17 -3
  35. data/lib/vagrant/bundler.rb +265 -53
  36. data/lib/vagrant/cli.rb +4 -2
  37. data/lib/vagrant/errors.rb +61 -1
  38. data/lib/vagrant/machine.rb +56 -6
  39. data/lib/vagrant/machine_index.rb +27 -1
  40. data/lib/vagrant/plugin/manager.rb +25 -14
  41. data/lib/vagrant/plugin/v2/command.rb +6 -2
  42. data/lib/vagrant/plugin/v2/components.rb +6 -0
  43. data/lib/vagrant/plugin/v2/manager.rb +67 -0
  44. data/lib/vagrant/plugin/v2/plugin.rb +13 -0
  45. data/lib/vagrant/plugin/v2/synced_folder.rb +50 -0
  46. data/lib/vagrant/plugin/v2/trigger.rb +64 -25
  47. data/lib/vagrant/shared_helpers.rb +28 -0
  48. data/lib/vagrant/ui.rb +51 -5
  49. data/lib/vagrant/util.rb +1 -0
  50. data/lib/vagrant/util/ansi_escape_code_remover.rb +1 -1
  51. data/lib/vagrant/util/caps.rb +48 -0
  52. data/lib/vagrant/util/credential_scrubber.rb +1 -1
  53. data/lib/vagrant/util/curl_helper.rb +8 -5
  54. data/lib/vagrant/util/directory.rb +19 -0
  55. data/lib/vagrant/util/downloader.rb +7 -3
  56. data/lib/vagrant/util/file_checksum.rb +6 -2
  57. data/lib/vagrant/util/guest_hosts.rb +68 -0
  58. data/lib/vagrant/util/guest_inspection.rb +9 -1
  59. data/lib/vagrant/util/install_cli_autocomplete.rb +118 -0
  60. data/lib/vagrant/util/io.rb +7 -27
  61. data/lib/vagrant/util/ipv4_interfaces.rb +15 -0
  62. data/lib/vagrant/util/is_port_open.rb +8 -20
  63. data/lib/vagrant/util/map_command_options.rb +33 -0
  64. data/lib/vagrant/util/network_ip.rb +11 -1
  65. data/lib/vagrant/util/numeric.rb +69 -0
  66. data/lib/vagrant/util/platform.rb +8 -1
  67. data/lib/vagrant/util/powershell.rb +1 -1
  68. data/lib/vagrant/util/subprocess.rb +9 -1
  69. data/lib/vagrant/vagrantfile.rb +1 -1
  70. data/plugins/commands/autocomplete/command/install.rb +49 -0
  71. data/plugins/commands/autocomplete/command/root.rb +64 -0
  72. data/plugins/commands/autocomplete/plugin.rb +18 -0
  73. data/plugins/commands/box/command/outdated.rb +14 -2
  74. data/plugins/commands/cloud/locales/en.yml +1 -1
  75. data/plugins/commands/cloud/publish.rb +1 -1
  76. data/plugins/commands/destroy/command.rb +6 -2
  77. data/plugins/commands/snapshot/command/save.rb +13 -8
  78. data/plugins/commands/ssh_config/command.rb +1 -1
  79. data/plugins/communicators/ssh/communicator.rb +25 -24
  80. data/plugins/communicators/winrm/config.rb +1 -1
  81. data/plugins/communicators/winrm/helper.rb +1 -1
  82. data/plugins/communicators/winrm/shell.rb +1 -1
  83. data/plugins/communicators/winssh/communicator.rb +126 -38
  84. data/plugins/communicators/winssh/config.rb +3 -7
  85. data/plugins/guests/alpine/cap/change_host_name.rb +10 -11
  86. data/plugins/guests/alpine/cap/rsync.rb +1 -1
  87. data/plugins/guests/alpine/plugin.rb +16 -0
  88. data/plugins/guests/alt/cap/change_host_name.rb +40 -53
  89. data/plugins/guests/arch/cap/change_host_name.rb +5 -14
  90. data/plugins/guests/arch/cap/configure_networks.rb +27 -10
  91. data/plugins/guests/atomic/cap/change_host_name.rb +5 -14
  92. data/plugins/guests/centos/cap/flavor.rb +24 -0
  93. data/plugins/guests/centos/guest.rb +9 -0
  94. data/plugins/guests/centos/plugin.rb +20 -0
  95. data/plugins/guests/darwin/cap/change_host_name.rb +10 -6
  96. data/plugins/guests/darwin/cap/mount_vmware_shared_folder.rb +99 -13
  97. data/plugins/guests/darwin/plugin.rb +5 -0
  98. data/plugins/guests/debian/cap/change_host_name.rb +11 -11
  99. data/plugins/guests/debian/cap/configure_networks.rb +14 -6
  100. data/plugins/guests/esxi/cap/public_key.rb +3 -1
  101. data/plugins/guests/freebsd/cap/change_host_name.rb +10 -6
  102. data/plugins/guests/gentoo/cap/change_host_name.rb +14 -22
  103. data/plugins/guests/haiku/cap/rsync.rb +19 -0
  104. data/plugins/guests/haiku/plugin.rb +15 -0
  105. data/plugins/guests/linux/cap/change_host_name.rb +46 -0
  106. data/plugins/guests/linux/cap/halt.rb +9 -1
  107. data/plugins/guests/linux/cap/mount_smb_shared_folder.rb +16 -0
  108. data/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb +4 -11
  109. data/plugins/guests/linux/cap/persist_mount_shared_folder.rb +62 -0
  110. data/plugins/guests/linux/cap/reboot.rb +48 -0
  111. data/plugins/guests/linux/plugin.rb +20 -0
  112. data/plugins/guests/omnios/cap/change_host_name.rb +10 -16
  113. data/plugins/guests/openbsd/cap/change_host_name.rb +10 -6
  114. data/plugins/guests/photon/cap/change_host_name.rb +9 -15
  115. data/plugins/guests/pld/cap/change_host_name.rb +11 -17
  116. data/plugins/guests/redhat/cap/change_host_name.rb +10 -5
  117. data/plugins/guests/redhat/cap/flavor.rb +3 -1
  118. data/plugins/guests/redhat/cap/nfs_client.rb +2 -2
  119. data/plugins/guests/redhat/cap/smb.rb +20 -0
  120. data/plugins/guests/redhat/plugin.rb +5 -0
  121. data/plugins/guests/slackware/cap/change_host_name.rb +11 -17
  122. data/plugins/guests/solaris11/plugin.rb +5 -0
  123. data/plugins/guests/suse/cap/change_host_name.rb +13 -12
  124. data/plugins/guests/windows/cap/public_key.rb +3 -3
  125. data/plugins/guests/windows/cap/reboot.rb +2 -1
  126. data/plugins/hosts/darwin/cap/fs_iso.rb +49 -0
  127. data/plugins/hosts/darwin/cap/nfs.rb +11 -0
  128. data/plugins/hosts/darwin/plugin.rb +15 -0
  129. data/plugins/hosts/linux/cap/fs_iso.rb +49 -0
  130. data/plugins/hosts/linux/cap/nfs.rb +21 -2
  131. data/plugins/hosts/linux/cap/rdp.rb +1 -1
  132. data/plugins/hosts/linux/plugin.rb +10 -0
  133. data/plugins/hosts/windows/cap/fs_iso.rb +48 -0
  134. data/plugins/hosts/windows/cap/rdp.rb +1 -1
  135. data/plugins/hosts/windows/plugin.rb +15 -0
  136. data/plugins/kernel_v2/config/cloud_init.rb +126 -0
  137. data/plugins/kernel_v2/config/disk.rb +221 -0
  138. data/plugins/kernel_v2/config/ssh_connect.rb +24 -0
  139. data/plugins/kernel_v2/config/vm.rb +225 -11
  140. data/plugins/kernel_v2/config/vm_provisioner.rb +17 -3
  141. data/plugins/kernel_v2/config/vm_trigger.rb +6 -5
  142. data/plugins/providers/docker/action.rb +8 -17
  143. data/plugins/providers/docker/action/forwarded_ports.rb +2 -0
  144. data/plugins/providers/docker/action/prepare_forwarded_port_collision_params.rb +61 -0
  145. data/plugins/providers/docker/cap/has_communicator.rb +11 -0
  146. data/plugins/providers/docker/communicator.rb +1 -1
  147. data/plugins/providers/docker/driver.rb +73 -10
  148. data/plugins/providers/docker/errors.rb +4 -0
  149. data/plugins/providers/docker/executor/local.rb +7 -1
  150. data/plugins/providers/docker/plugin.rb +5 -0
  151. data/plugins/providers/hyperv/action.rb +2 -0
  152. data/plugins/providers/hyperv/action/configure.rb +8 -0
  153. data/plugins/providers/hyperv/action/export.rb +4 -2
  154. data/plugins/providers/hyperv/cap/cleanup_disks.rb +54 -0
  155. data/plugins/providers/hyperv/cap/configure_disks.rb +200 -0
  156. data/plugins/providers/hyperv/cap/validate_disk_ext.rb +34 -0
  157. data/plugins/providers/hyperv/config.rb +5 -0
  158. data/plugins/providers/hyperv/driver.rb +90 -9
  159. data/plugins/providers/hyperv/plugin.rb +25 -0
  160. data/plugins/providers/hyperv/scripts/attach_disk_drive.ps1 +28 -0
  161. data/plugins/providers/hyperv/scripts/dismount_vhd.ps1 +13 -0
  162. data/plugins/providers/hyperv/scripts/get_vhd.ps1 +16 -0
  163. data/plugins/providers/hyperv/scripts/get_vm_status.ps1 +1 -1
  164. data/plugins/providers/hyperv/scripts/list_hdds.ps1 +17 -0
  165. data/plugins/providers/hyperv/scripts/new_vhd.ps1 +31 -0
  166. data/plugins/providers/hyperv/scripts/remove_disk_drive.ps1 +25 -0
  167. data/plugins/providers/hyperv/scripts/resize_disk_drive.ps1 +18 -0
  168. data/plugins/providers/hyperv/scripts/set_enhanced_session_transport_type.ps1 +24 -0
  169. data/plugins/providers/hyperv/scripts/set_vm_integration_services.ps1 +3 -3
  170. data/plugins/providers/hyperv/scripts/utils/VagrantVM/VagrantVM.psm1 +14 -6
  171. data/plugins/providers/virtualbox/action.rb +14 -1
  172. data/plugins/providers/virtualbox/action/clean_machine_folder.rb +10 -1
  173. data/plugins/providers/virtualbox/action/export.rb +4 -2
  174. data/plugins/providers/virtualbox/action/forward_ports.rb +2 -2
  175. data/plugins/providers/virtualbox/action/import.rb +8 -4
  176. data/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb +4 -2
  177. data/plugins/providers/virtualbox/action/snapshot_delete.rb +4 -2
  178. data/plugins/providers/virtualbox/action/snapshot_restore.rb +4 -2
  179. data/plugins/providers/virtualbox/cap/cleanup_disks.rb +85 -0
  180. data/plugins/providers/virtualbox/cap/configure_disks.rb +440 -0
  181. data/plugins/providers/virtualbox/cap/mount_options.rb +35 -0
  182. data/plugins/providers/virtualbox/cap/validate_disk_ext.rb +34 -0
  183. data/plugins/providers/virtualbox/driver/base.rb +15 -0
  184. data/plugins/providers/virtualbox/driver/meta.rb +17 -2
  185. data/plugins/providers/virtualbox/driver/version_5_0.rb +217 -2
  186. data/plugins/providers/virtualbox/driver/version_6_1.rb +39 -0
  187. data/plugins/providers/virtualbox/model/storage_controller.rb +135 -0
  188. data/plugins/providers/virtualbox/model/storage_controller_array.rb +100 -0
  189. data/plugins/providers/virtualbox/plugin.rb +38 -0
  190. data/plugins/providers/virtualbox/synced_folder.rb +1 -0
  191. data/plugins/provisioners/ansible/cap/guest/alpine/ansible_install.rb +44 -0
  192. data/plugins/provisioners/ansible/cap/guest/arch/ansible_install.rb +20 -3
  193. data/plugins/provisioners/ansible/cap/guest/debian/ansible_install.rb +4 -5
  194. data/plugins/provisioners/ansible/cap/guest/fedora/ansible_install.rb +2 -2
  195. data/plugins/provisioners/ansible/cap/guest/freebsd/ansible_install.rb +2 -2
  196. data/plugins/provisioners/ansible/cap/guest/pip/pip.rb +8 -4
  197. data/plugins/provisioners/ansible/cap/guest/redhat/ansible_install.rb +2 -2
  198. data/plugins/provisioners/ansible/cap/guest/suse/ansible_install.rb +2 -1
  199. data/plugins/provisioners/ansible/cap/guest/ubuntu/ansible_install.rb +3 -3
  200. data/plugins/provisioners/ansible/plugin.rb +5 -0
  201. data/plugins/provisioners/ansible/provisioner/base.rb +1 -1
  202. data/plugins/provisioners/container/client.rb +203 -0
  203. data/plugins/provisioners/container/config.rb +83 -0
  204. data/plugins/provisioners/container/installer.rb +13 -0
  205. data/plugins/provisioners/container/plugin.rb +23 -0
  206. data/plugins/provisioners/container/provisioner.rb +28 -0
  207. data/plugins/provisioners/docker/cap/{redhat → centos}/docker_install.rb +10 -7
  208. data/plugins/provisioners/docker/cap/centos/docker_start_service.rb +24 -0
  209. data/plugins/provisioners/docker/client.rb +4 -175
  210. data/plugins/provisioners/docker/config.rb +2 -72
  211. data/plugins/provisioners/docker/installer.rb +3 -5
  212. data/plugins/provisioners/docker/plugin.rb +6 -6
  213. data/plugins/provisioners/docker/provisioner.rb +4 -10
  214. data/plugins/provisioners/podman/cap/centos/podman_install.rb +35 -0
  215. data/plugins/provisioners/podman/cap/linux/podman_installed.rb +13 -0
  216. data/plugins/provisioners/podman/cap/redhat/podman_install.rb +26 -0
  217. data/plugins/provisioners/podman/client.rb +12 -0
  218. data/plugins/provisioners/podman/config.rb +28 -0
  219. data/plugins/provisioners/podman/installer.rb +33 -0
  220. data/plugins/provisioners/podman/plugin.rb +38 -0
  221. data/plugins/provisioners/podman/provisioner.rb +52 -0
  222. data/plugins/provisioners/salt/provisioner.rb +4 -0
  223. data/plugins/provisioners/shell/config.rb +1 -6
  224. data/plugins/provisioners/shell/provisioner.rb +61 -26
  225. data/plugins/synced_folders/nfs/synced_folder.rb +3 -1
  226. data/plugins/synced_folders/smb/cap/default_fstab_modification.rb +11 -0
  227. data/plugins/synced_folders/smb/cap/mount_options.rb +36 -0
  228. data/plugins/synced_folders/smb/plugin.rb +10 -0
  229. data/plugins/synced_folders/smb/synced_folder.rb +2 -2
  230. data/plugins/synced_folders/unix_mount_helpers.rb +14 -0
  231. data/templates/commands/init/Vagrantfile.erb +1 -1
  232. data/templates/guests/arch/{network_dhcp.erb → default_network/network_dhcp.erb} +0 -0
  233. data/templates/guests/arch/{network_static.erb → default_network/network_static.erb} +0 -0
  234. data/templates/guests/arch/{network_static6.erb → default_network/network_static6.erb} +0 -0
  235. data/templates/guests/arch/systemd_networkd/network_dhcp.erb +6 -0
  236. data/templates/guests/arch/systemd_networkd/network_static.erb +9 -0
  237. data/templates/guests/arch/systemd_networkd/network_static6.erb +9 -0
  238. data/templates/guests/linux/etc_fstab.erb +6 -0
  239. data/templates/locales/en.yml +235 -6
  240. data/templates/locales/providers_docker.yml +6 -0
  241. data/templates/nfs/exports_darwin.erb +7 -0
  242. data/vagrant.gemspec +12 -12
  243. data/version.txt +1 -1
  244. metadata +3937 -3686
  245. data/lib/vagrant/action/builtin/after_trigger.rb +0 -31
  246. data/lib/vagrant/action/builtin/before_trigger.rb +0 -28
  247. data/plugins/provisioners/docker/cap/redhat/docker_start_service.rb +0 -16
@@ -56,7 +56,7 @@ module VagrantPlugins
56
56
  errors << "winrm.port cannot be nil." if @port.nil?
57
57
  errors << "winrm.guest_port cannot be nil." if @guest_port.nil?
58
58
  errors << "winrm.max_tries cannot be nil." if @max_tries.nil?
59
- errors << "winrm.retry_delay cannot be nil." if @max_tries.nil?
59
+ errors << "winrm.retry_delay cannot be nil." if @retry_delay.nil?
60
60
  errors << "winrm.timeout cannot be nil." if @timeout.nil?
61
61
  errors << "winrm.execution_time_limit cannot be nil." if @execution_time_limit.nil?
62
62
  unless @ssl_peer_verification == true || @ssl_peer_verification == false
@@ -58,7 +58,7 @@ module VagrantPlugins
58
58
  # ports.
59
59
  port = nil
60
60
  if machine.provider.capability?(:forwarded_ports)
61
- machine.provider.capability(:forwarded_ports).each do |host, guest|
61
+ Array(machine.provider.capability(:forwarded_ports)).each do |host, guest|
62
62
  if guest == machine.config.winrm.guest_port
63
63
  port = host
64
64
  break
@@ -19,7 +19,7 @@ module VagrantPlugins
19
19
 
20
20
  # Exit code generated when user is invalid. Can occur
21
21
  # after a hostname update
22
- INVALID_USERID_EXITCODE = -196608
22
+ INVALID_USERID_EXITCODE = -2147024809
23
23
 
24
24
  # These are the exceptions that we retry because they represent
25
25
  # errors that are generally fixed from a retry and don't
@@ -1,27 +1,39 @@
1
1
  require File.expand_path("../../ssh/communicator", __FILE__)
2
2
 
3
+ require 'net/sftp'
4
+
3
5
  module VagrantPlugins
4
6
  module CommunicatorWinSSH
5
7
  # This class provides communication with a Windows VM running
6
8
  # the Windows native port of OpenSSH
7
9
  class Communicator < VagrantPlugins::CommunicatorSSH::Communicator
10
+ # Command to run when checking if connection is ready and working
11
+ READY_COMMAND="dir"
8
12
 
9
13
  def initialize(machine)
10
14
  super
11
15
  @logger = Log4r::Logger.new("vagrant::communication::winssh")
12
16
  end
13
17
 
18
+ # Wrap the shell if required. By default we are using powershell
19
+ # which requires no modification. If cmd is defined as shell, add
20
+ # prefix to start within cmd.exe
21
+ def shell_cmd(opts)
22
+ case opts[:shell].to_s
23
+ when "cmd"
24
+ "cmd.exe /c '#{opts[:command]}'"
25
+ else
26
+ opts[:command]
27
+ end
28
+ end
29
+
14
30
  # Executes the command on an SSH connection within a login shell.
15
31
  def shell_execute(connection, command, **opts)
16
- opts = {
17
- sudo: false,
18
- shell: nil
19
- }.merge(opts)
32
+ opts[:shell] ||= machine_config_ssh.shell
20
33
 
21
- sudo = opts[:sudo]
22
- shell = (opts[:shell] || machine_config_ssh.shell).to_s
34
+ command = shell_cmd(opts.merge(command: command))
23
35
 
24
- @logger.info("Execute: #{command} (sudo=#{sudo.inspect})")
36
+ @logger.info("Execute: #{command} - opts: #{opts}")
25
37
  exit_status = nil
26
38
 
27
39
  # Open the channel so we can execute or command
@@ -31,36 +43,10 @@ module VagrantPlugins
31
43
  stderr_marker_found = false
32
44
  stderr_data_buffer = ''
33
45
 
34
- tfile = Tempfile.new('vagrant-ssh')
35
- remote_ext = shell == "powershell" ? "ps1" : "bat"
36
- remote_name = "#{machine_config_ssh.upload_directory}\\#{File.basename(tfile.path)}.#{remote_ext}"
37
-
38
- if shell == "powershell"
39
- base_cmd = "powershell -File #{remote_name}"
40
- tfile.puts <<-SCRIPT.force_encoding('ASCII-8BIT')
41
- Remove-Item #{remote_name}
42
- Write-Host #{CMD_GARBAGE_MARKER}
43
- [Console]::Error.WriteLine("#{CMD_GARBAGE_MARKER}")
44
- #{command}
45
- SCRIPT
46
- else
47
- base_cmd = remote_name
48
- tfile.puts <<-SCRIPT.force_encoding('ASCII-8BIT')
49
- ECHO OFF
50
- ECHO #{CMD_GARBAGE_MARKER}
51
- ECHO #{CMD_GARBAGE_MARKER} 1>&2
52
- #{command}
53
- SCRIPT
54
- end
55
-
56
- tfile.close
57
- upload(tfile.path, remote_name)
58
- tfile.delete
59
-
60
- base_cmd = shell_cmd(opts.merge(shell: base_cmd))
61
- @logger.debug("Base SSH exec command: #{base_cmd}")
46
+ @logger.debug("Base SSH exec command: #{command}")
47
+ command = "$ProgressPreference = 'SilentlyContinue';Write-Output #{CMD_GARBAGE_MARKER};[Console]::Error.WriteLine('#{CMD_GARBAGE_MARKER}');#{command}"
62
48
 
63
- ch.exec(base_cmd) do |ch2, _|
49
+ ch.exec(command) do |ch2, _|
64
50
  # Setup the channel callbacks so we can get data and exit status
65
51
  ch2.on_data do |ch3, data|
66
52
  # Filter out the clear screen command
@@ -90,14 +76,14 @@ SCRIPT
90
76
  stderr_data_buffer << data
91
77
  marker_index = stderr_data_buffer.index(CMD_GARBAGE_MARKER)
92
78
  if marker_index
93
- marker_found = true
79
+ stderr_marker_found = true
94
80
  stderr_data_buffer.slice!(0, marker_index + CMD_GARBAGE_MARKER.size)
95
81
  data.replace(stderr_data_buffer.lstrip)
96
82
  data_buffer = nil
97
83
  end
98
84
  end
99
85
 
100
- if block_given? && marker_found
86
+ if block_given? && stderr_marker_found && !data.empty?
101
87
  yield :stderr, data
102
88
  end
103
89
  end
@@ -156,6 +142,108 @@ SCRIPT
156
142
  @machine.config.winssh
157
143
  end
158
144
 
145
+ def download(from, to=nil)
146
+ @logger.debug("Downloading: #{from} to #{to}")
147
+
148
+ sftp_connect do |sftp|
149
+ sftp.download!(from, to)
150
+ end
151
+ end
152
+
153
+ # Note: I could not get Net::SFTP to throw a permissions denied error,
154
+ # even when uploading to a directory where I did not have write
155
+ # privileges. I believe this is because Windows SSH sessions are started
156
+ # in an elevated process.
157
+ def upload(from, to)
158
+ to = Vagrant::Util::Platform.unix_windows_path(to)
159
+ @logger.debug("Uploading: #{from} to #{to}")
160
+
161
+ if File.directory?(from)
162
+ if from.end_with?(".")
163
+ @logger.debug("Uploading directory contents of: #{from}")
164
+ from = from.sub(/\.$/, "")
165
+ else
166
+ @logger.debug("Uploading full directory container of: #{from}")
167
+ to = File.join(to, File.basename(File.expand_path(from)))
168
+ end
169
+ end
170
+
171
+ sftp_connect do |sftp|
172
+ uploader = lambda do |path, remote_dest=nil|
173
+ if File.directory?(path)
174
+ Dir.new(path).each do |entry|
175
+ next if entry == "." || entry == ".."
176
+ full_path = File.join(path, entry)
177
+ dest = File.join(to, path.sub(/^#{Regexp.escape(from)}/, ""))
178
+ sftp.mkdir(dest)
179
+ uploader.call(full_path, dest)
180
+ end
181
+ else
182
+ if remote_dest
183
+ dest = File.join(remote_dest, File.basename(path))
184
+ else
185
+ dest = to
186
+ if to.end_with?(File::SEPARATOR)
187
+ dest = File.join(to, File.basename(path))
188
+ end
189
+ end
190
+ @logger.debug("Ensuring remote directory exists for destination upload")
191
+ sftp.mkdir(File.dirname(dest))
192
+ @logger.debug("Uploading file #{path} to remote #{dest}")
193
+ upload_file = File.open(path, "rb")
194
+ begin
195
+ sftp.upload!(upload_file, dest)
196
+ ensure
197
+ upload_file.close
198
+ end
199
+ end
200
+ end
201
+ uploader.call(from)
202
+ end
203
+ end
204
+
205
+ # Opens an SFTP connection and yields it so that you can download and
206
+ # upload files. SFTP works more reliably than SCP on Windows due to
207
+ # issues with shell quoting and escaping.
208
+ def sftp_connect
209
+ # Connect to SFTP and yield the SFTP object
210
+ connect do |connection|
211
+ return yield connection.sftp
212
+ end
213
+ end
214
+
215
+ protected
216
+
217
+ # The WinSSH communicator connection provides isolated modification
218
+ # to the generated connection instances. This modification forces
219
+ # all provided commands to run within powershell
220
+ def connect(**opts)
221
+ connection = nil
222
+ super { |c| connection = c }
223
+
224
+ if !connection.instance_variable_get(:@winssh_patched)
225
+ open_chan = connection.method(:open_channel)
226
+ connection.define_singleton_method(:open_channel) do |*args, &chan_block|
227
+ open_chan.call(*args) do |ch|
228
+ exec = ch.method(:exec)
229
+ ch.define_singleton_method(:exec) do |command, &block|
230
+ command = Base64.strict_encode64(command.encode("UTF-16LE", "UTF-8"))
231
+ command = "powershell -NoLogo -NonInteractive -ExecutionPolicy Bypass " \
232
+ "-NoProfile -EncodedCommand #{command}"
233
+ exec.call(command, &block)
234
+ end
235
+ chan_block.call(ch)
236
+ end
237
+ end
238
+ connection.instance_variable_set(:@winssh_patched, true)
239
+ end
240
+
241
+ if block_given?
242
+ yield connection
243
+ else
244
+ connection
245
+ end
246
+ end
159
247
  end
160
248
  end
161
249
  end
@@ -12,15 +12,11 @@ module VagrantPlugins
12
12
  end
13
13
 
14
14
  def finalize!
15
- @shell = "cmd" if @shell == UNSET_VALUE
15
+ @shell = "powershell" if @shell == UNSET_VALUE
16
16
  @sudo_command = "%c" if @sudo_command == UNSET_VALUE
17
- @upload_directory = "C:\\Windows\\Temp" if @upload_directory == UNSET_VALUE
17
+ @upload_directory = "C:/Windows/Temp" if @upload_directory == UNSET_VALUE
18
18
  if @export_command_template == UNSET_VALUE
19
- if @shell == "cmd"
20
- @export_command_template = 'set %ENV_KEY%="%ENV_VALUE%"'
21
- else
22
- @export_command_template = '$env:%ENV_KEY%="%ENV_VALUE%"'
23
- end
19
+ @export_command_template = '$env:%ENV_KEY%="%ENV_VALUE%"'
24
20
  end
25
21
  super
26
22
  end
@@ -1,7 +1,11 @@
1
+ require 'vagrant/util/guest_hosts'
2
+
1
3
  module VagrantPlugins
2
4
  module GuestAlpine
3
5
  module Cap
4
6
  class ChangeHostName
7
+ include Vagrant::Util::GuestHosts::Linux
8
+
5
9
  def self.change_host_name(machine, name)
6
10
  new(machine, name).change!
7
11
  end
@@ -14,10 +18,10 @@ module VagrantPlugins
14
18
  end
15
19
 
16
20
  def change!
21
+ update_etc_hosts
17
22
  return unless should_change?
18
23
 
19
24
  update_etc_hostname
20
- update_etc_hosts
21
25
  refresh_hostname_service
22
26
  update_mailname
23
27
  renew_dhcp
@@ -48,17 +52,12 @@ module VagrantPlugins
48
52
  # 127.0.0.1 localhost
49
53
  # 127.0.1.1 host.fqdn.com host.fqdn host
50
54
  def update_etc_hosts
51
- if machine.communicate.test("grep '#{current_hostname}' /etc/hosts")
52
- # Current hostname entry is in /etc/hosts
53
- ip_address = '([0-9]{1,3}\.){3}[0-9]{1,3}'
54
- search = "^(#{ip_address})\\s+#{Regexp.escape(current_hostname)}(\\s.*)?$"
55
- replace = "\\1 #{new_hostname} #{short_hostname}"
56
- expression = ['s', search, replace, 'g'].join('@')
57
-
58
- machine.communicate.sudo("sed -ri '#{expression}' /etc/hosts")
55
+ comm = machine.communicate
56
+ network_with_hostname = machine.config.vm.networks.map {|_, c| c if c[:hostname] }.compact[0]
57
+ if network_with_hostname
58
+ replace_host(comm, new_hostname, network_with_hostname[:ip])
59
59
  else
60
- # Current hostname entry isn't in /etc/hosts, just append it
61
- machine.communicate.sudo("echo '127.0.1.1 #{new_hostname} #{short_hostname}' >>/etc/hosts")
60
+ add_hostname_to_loopback_interface(comm, new_hostname)
62
61
  end
63
62
  end
64
63
 
@@ -8,7 +8,7 @@ module VagrantPlugins
8
8
 
9
9
  def self.rsync_install(machine)
10
10
  machine.communicate.tap do |comm|
11
- comm.sudo('apk add rsync')
11
+ comm.sudo('apk add --update-cache rsync')
12
12
  end
13
13
  end
14
14
  end
@@ -45,6 +45,22 @@ module VagrantPlugins
45
45
  require_relative 'cap/smb'
46
46
  Cap::SMB
47
47
  end
48
+
49
+ def self.check_community_plugin
50
+ plugins = Vagrant::Plugin::Manager.instance.installed_plugins
51
+ if plugins.keys.include?("vagrant-alpine")
52
+ $stderr.puts <<-EOF
53
+ WARNING: Vagrant has detected the `vagrant-alpine` plugin. This plugin's
54
+ functionality has been merged into the main Vagrant project and should be
55
+ considered deprecated. To uninstall the plugin, run the command shown below:
56
+
57
+ vagrant plugin uninstall vagrant-alpine
58
+
59
+ EOF
60
+ end
61
+ end
62
+
63
+ self.check_community_plugin
48
64
  end
49
65
  end
50
66
  end
@@ -1,63 +1,50 @@
1
+ require_relative '../../linux/cap/change_host_name'
2
+
1
3
  module VagrantPlugins
2
4
  module GuestALT
3
5
  module Cap
4
6
  class ChangeHostName
5
- def self.change_host_name(machine, name)
6
- comm = machine.communicate
7
-
8
- if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
9
- basename = name.split('.', 2)[0]
10
- comm.sudo <<-EOH.gsub(/^ {14}/, '')
11
- # Save current hostname saved in /etc/hosts
12
- CURRENT_HOSTNAME_FULL="$(hostname -f)"
13
- CURRENT_HOSTNAME_SHORT="$(hostname -s)"
14
-
15
- # New hostname to be saved in /etc/hosts
16
- NEW_HOSTNAME_FULL='#{name}'
17
- NEW_HOSTNAME_SHORT="${NEW_HOSTNAME_FULL%%.*}"
18
-
19
- # Set the hostname - use hostnamectl if available
20
- if command -v hostnamectl; then
21
- hostnamectl set-hostname --static '#{name}'
22
- hostnamectl set-hostname --transient '#{name}'
23
- else
24
- hostname '#{name}'
25
- fi
26
-
27
- # Update ourselves in /etc/hosts
28
- if grep -w "$CURRENT_HOSTNAME_FULL" /etc/hosts; then
29
- sed -i -e "s/\(\s\)$CURRENT_HOSTNAME_FULL\(\s\)/\1$NEW_HOSTNAME_FULL\2/g" -e "s/\(\s\)$CURRENT_HOSTNAME_FULL$/\1$NEW_HOSTNAME_FULL/g" /etc/hosts
30
- fi
31
- if grep -w "$CURRENT_HOSTNAME_SHORT" /etc/hosts; then
32
- sed -i -e "s/\(\s\)$CURRENT_HOSTNAME_SHORT\(\s\)/\1$NEW_HOSTNAME_SHORT\2/g" -e "s/\(\s\)$CURRENT_HOSTNAME_SHORT$/\1$NEW_HOSTNAME_SHORT/g" /etc/hosts
33
- fi
7
+ extend VagrantPlugins::GuestLinux::Cap::ChangeHostName
8
+
9
+ def self.change_name_command(name)
10
+ basename = name.split(".", 2)[0]
11
+ return <<-EOH.gsub(/^ {14}/, '')
12
+ # Save current hostname saved in /etc/hosts
13
+ CURRENT_HOSTNAME_FULL="$(hostname -f)"
14
+ CURRENT_HOSTNAME_SHORT="$(hostname -s)"
34
15
 
35
- # Persist hostname change across reboots
36
- if [ -f /etc/sysconfig/network ]; then
37
- sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network
38
- elif [ -f /etc/hostname ]; then
39
- sed -i 's/.*/#{name}/' /etc/hostname
40
- else
41
- echo 'Unrecognized system. Hostname change may not persist across reboots.'
42
- exit 0
43
- fi
16
+ # Set the hostname - use hostnamectl if available
17
+ if command -v hostnamectl; then
18
+ hostnamectl set-hostname --static '#{name}'
19
+ hostnamectl set-hostname --transient '#{name}'
20
+ else
21
+ hostname '#{name}'
22
+ fi
44
23
 
45
- # Restart the network if we find a recognized SYS V init script
46
- if command -v service; then
47
- if [ -f /etc/init.d/network ]; then
48
- service network restart
49
- elif [ -f /etc/init.d/networking ]; then
50
- service networking restart
51
- elif [ -f /etc/init.d/NetworkManager ]; then
52
- service NetworkManager restart
53
- else
54
- echo 'Unrecognized system. Networking was not restarted following hostname change.'
55
- exit 0
56
- fi
57
- fi
24
+ # Persist hostname change across reboots
25
+ if [ -f /etc/sysconfig/network ]; then
26
+ sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network
27
+ elif [ -f /etc/hostname ]; then
28
+ sed -i 's/.*/#{name}/' /etc/hostname
29
+ else
30
+ echo 'Unrecognized system. Hostname change may not persist across reboots.'
31
+ exit 0
32
+ fi
58
33
 
59
- EOH
60
- end
34
+ # Restart the network if we find a recognized SYS V init script
35
+ if command -v service; then
36
+ if [ -f /etc/init.d/network ]; then
37
+ service network restart
38
+ elif [ -f /etc/init.d/networking ]; then
39
+ service networking restart
40
+ elif [ -f /etc/init.d/NetworkManager ]; then
41
+ service NetworkManager restart
42
+ else
43
+ echo 'Unrecognized system. Networking was not restarted following hostname change.'
44
+ exit 0
45
+ fi
46
+ fi
47
+ EOH
61
48
  end
62
49
  end
63
50
  end
@@ -1,22 +1,13 @@
1
+ require_relative '../../linux/cap/change_host_name'
2
+
1
3
  module VagrantPlugins
2
4
  module GuestArch
3
5
  module Cap
4
6
  class ChangeHostName
5
- def self.change_host_name(machine, name)
6
- comm = machine.communicate
7
-
8
- if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
9
- basename = name.split(".", 2)[0]
10
- comm.sudo <<-EOH.gsub(/^ {14}/, "")
11
- # Set hostname
12
- hostnamectl set-hostname '#{basename}'
7
+ extend VagrantPlugins::GuestLinux::Cap::ChangeHostName
13
8
 
14
- # Prepend ourselves to /etc/hosts
15
- test $? -eq 0 && (grep -w '#{name}' /etc/hosts || {
16
- sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
17
- })
18
- EOH
19
- end
9
+ def self.change_name_command(name)
10
+ "hostnamectl set-hostname '#{name.split(".", 2).first}'"
20
11
  end
21
12
  end
22
13
  end