diff --git a/plugins/guests/fedora/cap/change_host_name.rb b/plugins/guests/fedora/cap/change_host_name.rb deleted file mode 100644 index 0914dfa46..000000000 --- a/plugins/guests/fedora/cap/change_host_name.rb +++ /dev/null @@ -1,29 +0,0 @@ -module VagrantPlugins - module GuestFedora - module Cap - class ChangeHostName - def self.change_host_name(machine, name) - comm = machine.communicate - - if !comm.test("hostname -f | grep '^#{name}$'", sudo: false) - basename = name.split(".", 2)[0] - comm.sudo <<-EOH.gsub(/^ {14}/, "") - echo '#{name}' > /etc/hostname - hostname -F /etc/hostname - hostnamectl set-hostname --static '#{name}' - hostnamectl set-hostname --transient '#{name}' - - # Remove comments and blank lines from /etc/hosts - sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts - - # Prepend ourselves to /etc/hosts - grep -w '#{name}' /etc/hosts || { - sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts - } - EOH - end - end - end - end - end -end diff --git a/plugins/guests/fedora/cap/configure_networks.rb b/plugins/guests/fedora/cap/configure_networks.rb deleted file mode 100644 index cb54306fe..000000000 --- a/plugins/guests/fedora/cap/configure_networks.rb +++ /dev/null @@ -1,60 +0,0 @@ -require "tempfile" - -require_relative "../../../../lib/vagrant/util/retryable" -require_relative "../../../../lib/vagrant/util/template_renderer" - -module VagrantPlugins - module GuestFedora - module Cap - class ConfigureNetworks - extend Vagrant::Util::Retryable - include Vagrant::Util - - def self.configure_networks(machine, networks) - comm = machine.communicate - - network_scripts_dir = machine.guest.capability(:network_scripts_dir) - interfaces = machine.guest.capability(:network_interface) - - commands = [] - - networks.each.with_index do |network, i| - network[:device] = interfaces[network[:interface]] - - # Render a new configuration - entry = TemplateRenderer.render("guests/fedora/network_#{network[:type]}", - options: network, - ) - - # Upload the new configuration - remote_path = "/tmp/vagrant-network-entry-#{network[:device]}-#{Time.now.to_i}-#{i}" - Tempfile.open("vagrant-fedora-configure-networks") do |f| - f.binmode - f.write(entry) - f.fsync - f.close - machine.communicate.upload(f.path, remote_path) - end - - # Add the new interface and bring it back up - final_path = "#{network_scripts_dir}/ifcfg-#{network[:device]}" - commands << <<-EOH.gsub(/^ {14}/, '') - # Down the interface before munging the config file. This might - # fail if the interface is not actually set up yet so ignore - # errors. - /sbin/ifdown '#{network[:device]}' || true - - # Move new config into place - mv '#{remote_path}' '#{final_path}' - - # Bring the interface up - ARPCHECK=no /sbin/ifup '#{network[:device]}' - EOH - end - - comm.sudo(commands.join("\n")) - end - end - end - end -end diff --git a/plugins/guests/fedora/cap/flavor.rb b/plugins/guests/fedora/cap/flavor.rb index 2a29f50b5..fa5bf2463 100644 --- a/plugins/guests/fedora/cap/flavor.rb +++ b/plugins/guests/fedora/cap/flavor.rb @@ -14,7 +14,7 @@ module VagrantPlugins if version.nil? return :fedora else - return "fedora_#{version}".to_sym + return :"fedora_#{version}" end end end diff --git a/plugins/guests/fedora/cap/network_scripts_dir.rb b/plugins/guests/fedora/cap/network_scripts_dir.rb deleted file mode 100644 index 82a4abad7..000000000 --- a/plugins/guests/fedora/cap/network_scripts_dir.rb +++ /dev/null @@ -1,15 +0,0 @@ -module VagrantPlugins - module GuestFedora - module Cap - class NetworkScriptsDir - # The path to the directory with the network configuration scripts. - # This is pulled out into its own directory since there are other - # operating systems (SUSE) which behave similarly but with a different - # path to the network scripts. - def self.network_scripts_dir(machine) - "/etc/sysconfig/network-scripts" - end - end - end - end -end diff --git a/plugins/guests/fedora/plugin.rb b/plugins/guests/fedora/plugin.rb index acb39548d..9a9241b0c 100644 --- a/plugins/guests/fedora/plugin.rb +++ b/plugins/guests/fedora/plugin.rb @@ -11,21 +11,6 @@ module VagrantPlugins Guest end - guest_capability(:fedora, :change_host_name) do - require_relative "cap/change_host_name" - Cap::ChangeHostName - end - - guest_capability(:fedora, :configure_networks) do - require_relative "cap/configure_networks" - Cap::ConfigureNetworks - end - - guest_capability(:fedora, :network_scripts_dir) do - require_relative "cap/network_scripts_dir" - Cap::NetworkScriptsDir - end - guest_capability(:fedora, :flavor) do require_relative "cap/flavor" Cap::Flavor diff --git a/plugins/guests/redhat/cap/change_host_name.rb b/plugins/guests/redhat/cap/change_host_name.rb index 816ecda21..afe461d4f 100644 --- a/plugins/guests/redhat/cap/change_host_name.rb +++ b/plugins/guests/redhat/cap/change_host_name.rb @@ -17,9 +17,10 @@ module VagrantPlugins # Set the hostname - use hostnamectl if available echo '#{name}' > /etc/hostname if command -v hostnamectl; then - hostnamectl set-hostname '#{name}' + hostnamectl set-hostname --static '#{name}' + hostnamectl set-hostname --transient '#{name}' else - hostname '#{name}' + hostname -F /etc/hostname fi # Remove comments and blank lines from /etc/hosts diff --git a/plugins/guests/redhat/cap/configure_networks.rb b/plugins/guests/redhat/cap/configure_networks.rb index fa817594f..6cbc9ec17 100644 --- a/plugins/guests/redhat/cap/configure_networks.rb +++ b/plugins/guests/redhat/cap/configure_networks.rb @@ -1,33 +1,14 @@ require "tempfile" -require_relative "../../../../lib/vagrant/util/retryable" require_relative "../../../../lib/vagrant/util/template_renderer" module VagrantPlugins module GuestRedHat module Cap class ConfigureNetworks - extend Vagrant::Util::Retryable include Vagrant::Util def self.configure_networks(machine, networks) - case machine.guest.capability(:flavor) - when :rhel_7 - configure_networks_rhel7(machine, networks) - else - configure_networks_default(machine, networks) - end - end - - def self.configure_networks_rhel7(machine, networks) - # This is kind of jank but the configure networks is the same as - # Fedora at this point. - require_relative "../../fedora/cap/configure_networks" - ::VagrantPlugins::GuestFedora::Cap::ConfigureNetworks - .configure_networks(machine, networks) - end - - def self.configure_networks_default(machine, networks) comm = machine.communicate network_scripts_dir = machine.guest.capability(:network_scripts_dir) diff --git a/templates/guests/fedora/network_dhcp.erb b/templates/guests/fedora/network_dhcp.erb deleted file mode 100644 index b15250cc2..000000000 --- a/templates/guests/fedora/network_dhcp.erb +++ /dev/null @@ -1,6 +0,0 @@ -#VAGRANT-BEGIN -# The contents below are automatically generated by Vagrant. Do not modify. -BOOTPROTO=dhcp -ONBOOT=yes -DEVICE=<%= options[:device] %> -#VAGRANT-END diff --git a/templates/guests/fedora/network_static.erb b/templates/guests/fedora/network_static.erb deleted file mode 100644 index 000ea6150..000000000 --- a/templates/guests/fedora/network_static.erb +++ /dev/null @@ -1,16 +0,0 @@ -#VAGRANT-BEGIN -# The contents below are automatically generated by Vagrant. Do not modify. -NM_CONTROLLED=no -BOOTPROTO=none -ONBOOT=yes -IPADDR=<%= options[:ip] %> -NETMASK=<%= options[:netmask] %> -DEVICE=<%= options[:device] %> -<% if options[:gateway] %> -GATEWAY=<%= options[:gateway] %> -<% end %> -<% if options[:mac_address] %> -HWADDR=<%= options[:mac_address] %> -<% end %> -PEERDNS=no -#VAGRANT-END diff --git a/templates/guests/fedora/network_static6.erb b/templates/guests/fedora/network_static6.erb deleted file mode 100644 index 9ca7821d8..000000000 --- a/templates/guests/fedora/network_static6.erb +++ /dev/null @@ -1,9 +0,0 @@ -#VAGRANT-BEGIN -# The contents below are automatically generated by Vagrant. Do not modify. -NM_CONTROLLED=no -BOOTPROTO=static -ONBOOT=yes -IPV6INIT=yes -IPV6ADDR=<%= options[:ip] %> -DEVICE=<%= options[:device] %> -#VAGRANT-END diff --git a/templates/guests/redhat/network_static.erb b/templates/guests/redhat/network_static.erb index b144c6cf4..000ea6150 100644 --- a/templates/guests/redhat/network_static.erb +++ b/templates/guests/redhat/network_static.erb @@ -9,5 +9,8 @@ DEVICE=<%= options[:device] %> <% if options[:gateway] %> GATEWAY=<%= options[:gateway] %> <% end %> +<% if options[:mac_address] %> +HWADDR=<%= options[:mac_address] %> +<% end %> PEERDNS=no #VAGRANT-END diff --git a/templates/guests/redhat/network_static6.erb b/templates/guests/redhat/network_static6.erb index 288da4396..275c97508 100644 --- a/templates/guests/redhat/network_static6.erb +++ b/templates/guests/redhat/network_static6.erb @@ -1,10 +1,12 @@ #VAGRANT-BEGIN # The contents below are automatically generated by Vagrant. Do not modify. -auto <%= options[:device] %> -iface <%= options[:device] %> inet6 static - address <%= options[:ip] %> - netmask <%= options[:netmask] %> -<% if options[:gateway] %> - gateway <%= options[:gateway] %> +NM_CONTROLLED=no +BOOTPROTO=static +ONBOOT=yes +DEVICE=<%= options[:device] %> +IPV6INIT=yes +IPV6ADDR=<%= options[:ip] %>/<%= options[:netmask] %> +<% if options[:gateway] -%> +IPV6_DEFAULTGW=<%= options[:gateway] %> <% end %> #VAGRANT-END