vagrant-unbundled 2.2.9.0 → 2.2.10.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/CHANGELOG.md +60 -0
  3. data/README.md +5 -5
  4. data/contrib/README.md +1 -0
  5. data/contrib/sudoers/linux-suse +2 -2
  6. data/contrib/zsh/_vagrant +736 -0
  7. data/contrib/zsh/generate_zsh_completion.rb +166 -0
  8. data/lib/vagrant/action.rb +3 -0
  9. data/lib/vagrant/action/builder.rb +52 -18
  10. data/lib/vagrant/action/builtin/box_add.rb +6 -5
  11. data/lib/vagrant/action/builtin/cloud_init_setup.rb +127 -0
  12. data/lib/vagrant/action/builtin/cloud_init_wait.rb +30 -0
  13. data/lib/vagrant/action/builtin/handle_box.rb +1 -1
  14. data/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb +13 -13
  15. data/lib/vagrant/action/builtin/has_provisioner.rb +36 -0
  16. data/lib/vagrant/action/builtin/mixin_provisioners.rb +1 -0
  17. data/lib/vagrant/action/builtin/mixin_synced_folders.rb +20 -21
  18. data/lib/vagrant/action/builtin/set_hostname.rb +5 -1
  19. data/lib/vagrant/action/builtin/synced_folders.rb +10 -0
  20. data/lib/vagrant/action/builtin/trigger.rb +3 -2
  21. data/lib/vagrant/action/hook.rb +59 -24
  22. data/lib/vagrant/action/warden.rb +25 -5
  23. data/lib/vagrant/box.rb +5 -4
  24. data/lib/vagrant/bundler.rb +6 -1
  25. data/lib/vagrant/errors.rb +37 -1
  26. data/lib/vagrant/machine.rb +47 -0
  27. data/lib/vagrant/machine_index.rb +27 -1
  28. data/lib/vagrant/plugin/v2/command.rb +5 -1
  29. data/lib/vagrant/plugin/v2/components.rb +6 -0
  30. data/lib/vagrant/plugin/v2/manager.rb +14 -0
  31. data/lib/vagrant/plugin/v2/plugin.rb +12 -0
  32. data/lib/vagrant/plugin/v2/synced_folder.rb +50 -0
  33. data/lib/vagrant/plugin/v2/trigger.rb +6 -5
  34. data/lib/vagrant/ui.rb +1 -1
  35. data/lib/vagrant/util/ansi_escape_code_remover.rb +1 -1
  36. data/lib/vagrant/util/caps.rb +48 -0
  37. data/lib/vagrant/util/credential_scrubber.rb +1 -1
  38. data/lib/vagrant/util/directory.rb +19 -0
  39. data/lib/vagrant/util/downloader.rb +3 -3
  40. data/lib/vagrant/util/guest_hosts.rb +68 -0
  41. data/lib/vagrant/util/install_cli_autocomplete.rb +118 -0
  42. data/lib/vagrant/util/ipv4_interfaces.rb +15 -0
  43. data/lib/vagrant/util/is_port_open.rb +8 -19
  44. data/lib/vagrant/util/network_ip.rb +11 -1
  45. data/lib/vagrant/util/powershell.rb +1 -1
  46. data/lib/vagrant/util/subprocess.rb +9 -1
  47. data/lib/vagrant/vagrantfile.rb +1 -1
  48. data/plugins/commands/autocomplete/command/install.rb +49 -0
  49. data/plugins/commands/autocomplete/command/root.rb +64 -0
  50. data/plugins/commands/autocomplete/plugin.rb +18 -0
  51. data/plugins/commands/destroy/command.rb +6 -2
  52. data/plugins/communicators/ssh/communicator.rb +7 -1
  53. data/plugins/communicators/winrm/helper.rb +1 -1
  54. data/plugins/communicators/winssh/communicator.rb +1 -1
  55. data/plugins/guests/alpine/cap/change_host_name.rb +10 -11
  56. data/plugins/guests/alt/cap/change_host_name.rb +40 -53
  57. data/plugins/guests/arch/cap/change_host_name.rb +5 -14
  58. data/plugins/guests/arch/cap/configure_networks.rb +27 -10
  59. data/plugins/guests/atomic/cap/change_host_name.rb +5 -14
  60. data/plugins/guests/darwin/cap/change_host_name.rb +10 -6
  61. data/plugins/guests/debian/cap/change_host_name.rb +11 -11
  62. data/plugins/guests/esxi/cap/public_key.rb +3 -1
  63. data/plugins/guests/freebsd/cap/change_host_name.rb +10 -6
  64. data/plugins/guests/gentoo/cap/change_host_name.rb +14 -22
  65. data/plugins/guests/haiku/cap/rsync.rb +19 -0
  66. data/plugins/guests/haiku/plugin.rb +15 -0
  67. data/plugins/guests/linux/cap/change_host_name.rb +46 -0
  68. data/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb +4 -11
  69. data/plugins/guests/linux/cap/persist_mount_shared_folder.rb +62 -0
  70. data/plugins/guests/linux/plugin.rb +10 -0
  71. data/plugins/guests/omnios/cap/change_host_name.rb +10 -16
  72. data/plugins/guests/openbsd/cap/change_host_name.rb +10 -6
  73. data/plugins/guests/photon/cap/change_host_name.rb +9 -15
  74. data/plugins/guests/pld/cap/change_host_name.rb +11 -17
  75. data/plugins/guests/redhat/cap/change_host_name.rb +10 -5
  76. data/plugins/guests/slackware/cap/change_host_name.rb +11 -17
  77. data/plugins/guests/solaris11/plugin.rb +5 -0
  78. data/plugins/guests/suse/cap/change_host_name.rb +12 -11
  79. data/plugins/hosts/darwin/cap/fs_iso.rb +49 -0
  80. data/plugins/hosts/darwin/plugin.rb +10 -0
  81. data/plugins/hosts/linux/cap/fs_iso.rb +49 -0
  82. data/plugins/hosts/linux/cap/rdp.rb +1 -1
  83. data/plugins/hosts/linux/plugin.rb +10 -0
  84. data/plugins/hosts/windows/cap/fs_iso.rb +48 -0
  85. data/plugins/hosts/windows/cap/rdp.rb +1 -1
  86. data/plugins/hosts/windows/plugin.rb +15 -0
  87. data/plugins/kernel_v2/config/cloud_init.rb +126 -0
  88. data/plugins/kernel_v2/config/disk.rb +40 -18
  89. data/plugins/kernel_v2/config/vm.rb +122 -13
  90. data/plugins/kernel_v2/config/vm_provisioner.rb +13 -2
  91. data/plugins/kernel_v2/config/vm_trigger.rb +5 -1
  92. data/plugins/providers/docker/action.rb +8 -17
  93. data/plugins/providers/docker/action/forwarded_ports.rb +2 -0
  94. data/plugins/providers/docker/action/prepare_forwarded_port_collision_params.rb +61 -0
  95. data/plugins/providers/docker/cap/has_communicator.rb +11 -0
  96. data/plugins/providers/docker/communicator.rb +1 -1
  97. data/plugins/providers/docker/driver.rb +35 -0
  98. data/plugins/providers/docker/plugin.rb +5 -0
  99. data/plugins/providers/hyperv/action.rb +2 -0
  100. data/plugins/providers/hyperv/action/configure.rb +8 -0
  101. data/plugins/providers/hyperv/cap/cleanup_disks.rb +54 -0
  102. data/plugins/providers/hyperv/cap/configure_disks.rb +200 -0
  103. data/plugins/providers/hyperv/cap/validate_disk_ext.rb +34 -0
  104. data/plugins/providers/hyperv/config.rb +5 -0
  105. data/plugins/providers/hyperv/driver.rb +80 -0
  106. data/plugins/providers/hyperv/plugin.rb +25 -0
  107. data/plugins/providers/hyperv/scripts/attach_disk_drive.ps1 +28 -0
  108. data/plugins/providers/hyperv/scripts/dismount_vhd.ps1 +13 -0
  109. data/plugins/providers/hyperv/scripts/get_vhd.ps1 +16 -0
  110. data/plugins/providers/hyperv/scripts/get_vm_status.ps1 +1 -1
  111. data/plugins/providers/hyperv/scripts/list_hdds.ps1 +17 -0
  112. data/plugins/providers/hyperv/scripts/new_vhd.ps1 +31 -0
  113. data/plugins/providers/hyperv/scripts/remove_disk_drive.ps1 +25 -0
  114. data/plugins/providers/hyperv/scripts/resize_disk_drive.ps1 +18 -0
  115. data/plugins/providers/hyperv/scripts/set_enhanced_session_transport_type.ps1 +24 -0
  116. data/plugins/providers/hyperv/scripts/utils/VagrantVM/VagrantVM.psm1 +8 -0
  117. data/plugins/providers/virtualbox/action.rb +12 -1
  118. data/plugins/providers/virtualbox/action/forward_ports.rb +2 -2
  119. data/plugins/providers/virtualbox/cap/cleanup_disks.rb +40 -9
  120. data/plugins/providers/virtualbox/cap/configure_disks.rb +230 -77
  121. data/plugins/providers/virtualbox/cap/mount_options.rb +35 -0
  122. data/plugins/providers/virtualbox/cap/validate_disk_ext.rb +10 -3
  123. data/plugins/providers/virtualbox/driver/meta.rb +3 -0
  124. data/plugins/providers/virtualbox/driver/version_5_0.rb +96 -21
  125. data/plugins/providers/virtualbox/model/storage_controller.rb +135 -0
  126. data/plugins/providers/virtualbox/model/storage_controller_array.rb +100 -0
  127. data/plugins/providers/virtualbox/plugin.rb +18 -1
  128. data/plugins/providers/virtualbox/synced_folder.rb +1 -0
  129. data/plugins/provisioners/container/client.rb +1 -1
  130. data/plugins/provisioners/shell/provisioner.rb +15 -9
  131. data/plugins/synced_folders/nfs/synced_folder.rb +3 -1
  132. data/plugins/synced_folders/smb/cap/default_fstab_modification.rb +11 -0
  133. data/plugins/synced_folders/smb/cap/mount_options.rb +36 -0
  134. data/plugins/synced_folders/smb/plugin.rb +10 -0
  135. data/plugins/synced_folders/smb/synced_folder.rb +1 -1
  136. data/plugins/synced_folders/unix_mount_helpers.rb +14 -0
  137. data/templates/guests/arch/{network_dhcp.erb → default_network/network_dhcp.erb} +0 -0
  138. data/templates/guests/arch/{network_static.erb → default_network/network_static.erb} +0 -0
  139. data/templates/guests/arch/{network_static6.erb → default_network/network_static6.erb} +0 -0
  140. data/templates/guests/arch/systemd_networkd/network_dhcp.erb +6 -0
  141. data/templates/guests/arch/systemd_networkd/network_static.erb +9 -0
  142. data/templates/guests/arch/systemd_networkd/network_static6.erb +9 -0
  143. data/templates/guests/linux/etc_fstab.erb +6 -0
  144. data/templates/locales/en.yml +121 -11
  145. data/templates/locales/providers_docker.yml +4 -0
  146. data/vagrant.gemspec +8 -7
  147. data/version.txt +1 -1
  148. metadata +1492 -1309
@@ -0,0 +1,64 @@
1
+ require "optparse"
2
+ require 'vagrant/util/install_cli_autocomplete'
3
+
4
+ module VagrantPlugins
5
+ module CommandAutocomplete
6
+ module Command
7
+ class Root < Vagrant.plugin("2", :command)
8
+ def self.synopsis
9
+ "manages autocomplete installation on host"
10
+ end
11
+
12
+ def initialize(argv, env)
13
+ super
14
+
15
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
16
+
17
+ @subcommands = Vagrant::Registry.new
18
+ @subcommands.register(:install) do
19
+ require File.expand_path("../install", __FILE__)
20
+ Install
21
+ end
22
+ end
23
+
24
+ def execute
25
+ if @main_args.include?("-h") || @main_args.include?("--help")
26
+ # Print the help for all the box commands.
27
+ return help
28
+ end
29
+
30
+ # If we reached this far then we must have a subcommand. If not,
31
+ # then we also just print the help and exit.
32
+ command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
33
+ return help if !command_class || !@sub_command
34
+ @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
35
+
36
+ # Initialize and execute the command class
37
+ command_class.new(@sub_args, @env).execute
38
+ end
39
+
40
+ def help
41
+ opts = OptionParser.new do |opts|
42
+ opts.banner = "Usage: vagrant autocomplete <subcommand>"
43
+ opts.separator ""
44
+ opts.separator "Available subcommands:"
45
+
46
+ # Add the available subcommands as separators in order to print them
47
+ # out as well.
48
+ keys = []
49
+ keys = @subcommands.keys.map(&:to_s)
50
+
51
+ keys.sort.each do |key|
52
+ opts.separator " #{key}"
53
+ end
54
+
55
+ opts.separator ""
56
+ opts.separator "For help on any individual subcommand run `vagrant autocomplete <subcommand> -h`"
57
+ end
58
+
59
+ @env.ui.info(opts.help, prefix: false)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,18 @@
1
+ require "vagrant"
2
+
3
+
4
+ module VagrantPlugins
5
+ module CommandAutocomplete
6
+ class Plugin < Vagrant.plugin("2")
7
+ name "autocomplete command"
8
+ description <<-DESC
9
+ The `autocomplete` manipulates Vagrant the autocomplete feature.
10
+ DESC
11
+
12
+ command("autocomplete") do
13
+ require File.expand_path("../command/root", __FILE__)
14
+ Command::Root
15
+ end
16
+ end
17
+ end
18
+ end
@@ -8,6 +8,7 @@ module VagrantPlugins
8
8
  def execute
9
9
  options = {}
10
10
  options[:force] = false
11
+ options[:force_halt] = true
11
12
 
12
13
  opts = OptionParser.new do |o|
13
14
  o.banner = "Usage: vagrant destroy [options] [name|id]"
@@ -23,6 +24,10 @@ module VagrantPlugins
23
24
  "Enable or disable parallelism if provider supports it (automatically enables force)") do |p|
24
25
  options[:parallel] = p
25
26
  end
27
+
28
+ o.on("-g", "--graceful", "Gracefully poweroff of VM") do |f|
29
+ options[:force_halt] = false
30
+ end
26
31
  end
27
32
 
28
33
  # Parse the options
@@ -46,8 +51,7 @@ module VagrantPlugins
46
51
  # gather states to be checked after destroy
47
52
  init_states[vm.name] = vm.state.id
48
53
  machines << vm
49
-
50
- batch.action(vm, :destroy, force_confirm_destroy: options[:force])
54
+ batch.action(vm, :destroy, force_confirm_destroy: options[:force], force_halt: options[:force_halt])
51
55
  end
52
56
  end
53
57
 
@@ -307,10 +307,11 @@ module VagrantPlugins
307
307
  scp_connect do |scp|
308
308
  uploader = lambda do |path, remote_dest=nil|
309
309
  if File.directory?(path)
310
+ dest = File.join(to, path.sub(/^#{Regexp.escape(from)}/, ""))
311
+ create_remote_directory(dest)
310
312
  Dir.new(path).each do |entry|
311
313
  next if entry == "." || entry == ".."
312
314
  full_path = File.join(path, entry)
313
- dest = File.join(to, path.sub(/^#{Regexp.escape(from)}/, ""))
314
315
  create_remote_directory(dest)
315
316
  uploader.call(full_path, dest)
316
317
  end
@@ -729,6 +730,11 @@ module VagrantPlugins
729
730
  yield :stdout, data if block_given?
730
731
  end
731
732
 
733
+ if !exit_status
734
+ @logger.debug("Exit status: #{exit_status.inspect}")
735
+ raise Vagrant::Errors::SSHNoExitStatus
736
+ end
737
+
732
738
  # Return the final exit status
733
739
  return exit_status
734
740
  end
@@ -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
@@ -217,7 +217,7 @@ module VagrantPlugins
217
217
  # The WinSSH communicator connection provides isolated modification
218
218
  # to the generated connection instances. This modification forces
219
219
  # all provided commands to run within powershell
220
- def connect(*args)
220
+ def connect(**opts)
221
221
  connection = nil
222
222
  super { |c| connection = c }
223
223
 
@@ -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
 
@@ -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
@@ -9,10 +9,12 @@ module VagrantPlugins
9
9
  module Cap
10
10
  class ConfigureNetworks
11
11
  include Vagrant::Util
12
+ extend Vagrant::Util::GuestInspection::Linux
12
13
 
13
14
  def self.configure_networks(machine, networks)
14
15
  comm = machine.communicate
15
16
  commands = []
17
+ uses_systemd_networkd = systemd_networkd?(comm)
16
18
 
17
19
  interfaces = machine.guest.capability(:network_interfaces)
18
20
  networks.each.with_index do |network, i|
@@ -25,9 +27,15 @@ module VagrantPlugins
25
27
  network[:netmask] = (32-Math.log2((IPAddr.new(network[:netmask], Socket::AF_INET).to_i^0xffffffff)+1)).to_i
26
28
  end
27
29
 
28
- entry = TemplateRenderer.render("guests/arch/network_#{network[:type]}",
29
- options: network,
30
- )
30
+ if uses_systemd_networkd
31
+ entry = TemplateRenderer.render("guests/arch/systemd_networkd/network_#{network[:type]}",
32
+ options: network,
33
+ )
34
+ else
35
+ entry = TemplateRenderer.render("guests/arch/default_network/network_#{network[:type]}",
36
+ options: network,
37
+ )
38
+ end
31
39
 
32
40
  remote_path = "/tmp/vagrant-network-#{network[:device]}-#{Time.now.to_i}-#{i}"
33
41
 
@@ -39,13 +47,22 @@ module VagrantPlugins
39
47
  comm.upload(f.path, remote_path)
40
48
  end
41
49
 
42
- commands << <<-EOH.gsub(/^ {14}/, '').rstrip
43
- # Configure #{network[:device]}
44
- mv '#{remote_path}' '/etc/netctl/#{network[:device]}' &&
45
- ip link set '#{network[:device]}' down &&
46
- netctl restart '#{network[:device]}' &&
47
- netctl enable '#{network[:device]}'
48
- EOH
50
+ if uses_systemd_networkd
51
+ commands << <<-EOH.gsub(/^ {16}/, '').rstrip
52
+ # Configure #{network[:device]}
53
+ chmod 0644 '#{remote_path}' &&
54
+ mv '#{remote_path}' '/etc/systemd/network/#{network[:device]}.network' &&
55
+ networkctl reload
56
+ EOH
57
+ else
58
+ commands << <<-EOH.gsub(/^ {16}/, '').rstrip
59
+ # Configure #{network[:device]}
60
+ mv '#{remote_path}' '/etc/netctl/#{network[:device]}' &&
61
+ ip link set '#{network[:device]}' down &&
62
+ netctl restart '#{network[:device]}' &&
63
+ netctl enable '#{network[:device]}'
64
+ EOH
65
+ end
49
66
  end
50
67
 
51
68
  # Run all the network modification commands in one communicator call.
@@ -1,22 +1,13 @@
1
+ require_relative '../../linux/cap/change_host_name'
2
+
1
3
  module VagrantPlugins
2
4
  module GuestAtomic
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
@@ -1,7 +1,11 @@
1
+ require 'vagrant/util/guest_hosts'
2
+
1
3
  module VagrantPlugins
2
4
  module GuestDarwin
3
5
  module Cap
4
6
  class ChangeHostName
7
+ extend Vagrant::Util::GuestHosts::BSD
8
+
5
9
  def self.change_host_name(machine, name)
6
10
  comm = machine.communicate
7
11
 
@@ -21,14 +25,14 @@ module VagrantPlugins
21
25
  fi
22
26
 
23
27
  hostname '#{name}'
24
-
25
- # Prepend ourselves to /etc/hosts - sed on bsd is sad
26
- grep -w '#{name}' /etc/hosts || {
27
- echo -e '127.0.0.1\\t#{name}\\t#{basename}' | cat - /etc/hosts > /tmp/tmp-hosts &&
28
- mv /tmp/tmp-hosts /etc/hosts
29
- }
30
28
  EOH
31
29
  end
30
+ network_with_hostname = machine.config.vm.networks.map {|_, c| c if c[:hostname] }.compact[0]
31
+ if network_with_hostname
32
+ replace_host(comm, name, network_with_hostname[:ip])
33
+ else
34
+ add_hostname_to_loopback_interface(comm, name)
35
+ end
32
36
  end
33
37
  end
34
38
  end