guests/alt: Update network configuration

Fix network mask to CIDR notation and network configure stop and
restart commands with NetworkManager
This commit is contained in:
Evgeny Sinelnikov 2017-07-08 21:27:19 +03:00
parent 3dd90aa955
commit 88c0cb855f
1 changed files with 11 additions and 3 deletions

View File

@ -47,6 +47,14 @@ module VagrantPlugins
# Render a new configuration # Render a new configuration
template_options = network.merge(extra_opts) 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) options_entry = TemplateRenderer.render("guests/alt/network_#{network[:type]}", options: template_options)
# Upload the new configuration # Upload the new configuration
@ -89,7 +97,7 @@ module VagrantPlugins
end end
end end
if nm_controlled if nm_controlled and extra_opts[:nm_controlled] == "yes"
commands[:start] << "nmcli d disconnect iface '#{network[:device]}'" commands[:start] << "nmcli d disconnect iface '#{network[:device]}'"
else else
commands[:start] << "/sbin/ifdown '#{network[:device]}'" commands[:start] << "/sbin/ifdown '#{network[:device]}'"
@ -105,8 +113,8 @@ module VagrantPlugins
end end
end end
if nmcli_installed if nmcli_installed
commands[:middle] << "(test -f /etc/init.d/NetworkManager && /etc/init.d/NetworkManager restart) || " \ commands[:middle] << "((systemctl | grep NetworkManager.service) && systemctl restart NetworkManager) || " \
"((systemctl | grep NetworkManager.service) && systemctl restart NetworkManager)" "(test -f /etc/init.d/NetworkManager && /etc/init.d/NetworkManager restart)"
end end
commands = commands[:start] + commands[:middle] + commands[:end] commands = commands[:start] + commands[:middle] + commands[:end]
comm.sudo(commands.join("\n")) comm.sudo(commands.join("\n"))