From 88c0cb855f33c605503a004f9ff3a2ed7dff2518 Mon Sep 17 00:00:00 2001 From: Evgeny Sinelnikov Date: Sat, 8 Jul 2017 21:27:19 +0300 Subject: [PATCH] guests/alt: Update network configuration Fix network mask to CIDR notation and network configure stop and restart commands with NetworkManager --- plugins/guests/alt/cap/configure_networks.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/guests/alt/cap/configure_networks.rb b/plugins/guests/alt/cap/configure_networks.rb index acca141db..851849700 100644 --- a/plugins/guests/alt/cap/configure_networks.rb +++ b/plugins/guests/alt/cap/configure_networks.rb @@ -47,6 +47,14 @@ module VagrantPlugins # Render a new configuration template_options = network.merge(extra_opts) + + # ALT expects netmasks to be in the CIDR notation, but users may + # specify IPV4 netmasks like "255.255.255.0". This magic converts + # the netmask to the proper value. + if template_options[:netmask] && template_options[:netmask].to_s.include?(".") + template_options[:netmask] = (32-Math.log2((IPAddr.new(template_options[:netmask], Socket::AF_INET).to_i^0xffffffff)+1)).to_i + end + options_entry = TemplateRenderer.render("guests/alt/network_#{network[:type]}", options: template_options) # Upload the new configuration @@ -89,7 +97,7 @@ module VagrantPlugins end end - if nm_controlled + if nm_controlled and extra_opts[:nm_controlled] == "yes" commands[:start] << "nmcli d disconnect iface '#{network[:device]}'" else commands[:start] << "/sbin/ifdown '#{network[:device]}'" @@ -105,8 +113,8 @@ module VagrantPlugins end end if nmcli_installed - commands[:middle] << "(test -f /etc/init.d/NetworkManager && /etc/init.d/NetworkManager restart) || " \ - "((systemctl | grep NetworkManager.service) && systemctl restart NetworkManager)" + commands[:middle] << "((systemctl | grep NetworkManager.service) && systemctl restart NetworkManager) || " \ + "(test -f /etc/init.d/NetworkManager && /etc/init.d/NetworkManager restart)" end commands = commands[:start] + commands[:middle] + commands[:end] comm.sudo(commands.join("\n"))