guests/arch: compute netmask
Arch expects /24 for netmask, but users usually specify as a netmask block like 255.255.255.0. This automatically converts it.
This commit is contained in:
parent
627091de35
commit
ccc40eb19d
|
@ -1,3 +1,5 @@
|
|||
require "ipaddr"
|
||||
require "socket"
|
||||
require "tempfile"
|
||||
|
||||
require_relative "../../../../lib/vagrant/util/template_renderer"
|
||||
|
@ -17,6 +19,13 @@ module VagrantPlugins
|
|||
networks.each.with_index do |network, i|
|
||||
network[:device] = interfaces[network[:interface]]
|
||||
|
||||
# Arch expects netmasks to be in the "24" or "64", but users may
|
||||
# specify IPV4 netmasks like "255.255.255.0". This magic converts
|
||||
# the netmask to the proper value.
|
||||
if network[:netmask] && network[:netmask].to_s.include?(".")
|
||||
network[:netmask] = (32-Math.log2((IPAddr.new(network[:netmask], Socket::AF_INET).to_i^0xffffffff)+1)).to_i
|
||||
end
|
||||
|
||||
entry = TemplateRenderer.render("guests/arch/network_#{network[:type]}",
|
||||
options: network,
|
||||
)
|
||||
|
|
|
@ -2,7 +2,7 @@ Connection=ethernet
|
|||
Description='A basic static ethernet connection'
|
||||
Interface=<%= options[:device] %>
|
||||
IP=static
|
||||
Address=('<%= options[:ip]%>/24')
|
||||
<% if options[:gateway] %>
|
||||
Address=('<%= options[:ip]%>/<%= options[:netmask] %>')
|
||||
<% if options[:gateway] -%>
|
||||
Gateway='<%= options[:gateway] %>'
|
||||
<% end %>
|
||||
<% end -%>
|
||||
|
|
|
@ -2,7 +2,7 @@ Connection=ethernet
|
|||
Description='A basic IPv6 ethernet connection'
|
||||
Interface=<%= options[:device] %>
|
||||
IP6=static
|
||||
Address=('<%= options[:ip]%>/<%= options[:netmask] %>')
|
||||
<% if options[:gateway] %>
|
||||
Gateway='<%= options[:gateway] %>'
|
||||
<% end %>
|
||||
Address6=('<%= options[:ip]%>/<%= options[:netmask] %>')
|
||||
<% if options[:gateway] -%>
|
||||
Gateway6='<%= options[:gateway] %>'
|
||||
<% end -%>
|
||||
|
|
Loading…
Reference in New Issue