Add :libvirt_host_ip and :libvirt_dhcp_start/stop

This allows networks with gateways on addresses other
than .1 (.254 is a popular choice).

Resolves #357.
This commit is contained in:
Felix Kaiser 2015-05-06 19:51:26 +02:00
parent 3e79a37ad2
commit ae37f17de8
2 changed files with 17 additions and 7 deletions

View File

@ -240,8 +240,14 @@ starts with 'libvirt__' string. Here is a list of those options:
network 'default' is used. network 'default' is used.
* `:libvirt__netmask` - Used only together with `:ip` option. Default is * `:libvirt__netmask` - Used only together with `:ip` option. Default is
'255.255.255.0'. '255.255.255.0'.
* `:libvirt__host_ip` - Adress to use for the host (not guest).
Default is first possible address (after network address).
* `:libvirt__dhcp_enabled` - If DHCP will offer addresses, or not. Used only * `:libvirt__dhcp_enabled` - If DHCP will offer addresses, or not. Used only
when creating new network. Default is true. when creating new network. Default is true.
* `:libvirt__dhcp_start` - First address given out via DHCP.
Default is third address in range (after network name and gateway).
* `:libvirt__dhcp_stop` - Last address given out via DHCP.
Default is last possible address in range (before broadcast address).
* `:libvirt__dhcp_bootp_file` - The file to be used for the boot image. * `:libvirt__dhcp_bootp_file` - The file to be used for the boot image.
Used only when dhcp is enabled. Used only when dhcp is enabled.
* `:libvirt__dhcp_bootp_server` - The server that runs the DHCP server. * `:libvirt__dhcp_bootp_server` - The server that runs the DHCP server.

View File

@ -121,7 +121,12 @@ module VagrantPlugins
# Set IP address of network (actually bridge). It will be used as # Set IP address of network (actually bridge). It will be used as
# gateway address for machines connected to this network. # gateway address for machines connected to this network.
net = IPAddr.new(net_address) net = IPAddr.new(net_address)
@interface_network[:ip_address] = net.to_range.begin.succ if @options[:host_ip].nil?
# Default to first address (after network name)
@interface_network[:ip_address] = net.to_range.begin.succ
else
@interface_network[:ip_address] = IPAddr.new @options[:host_ip]
end
# Is there an available network matching to configured ip # Is there an available network matching to configured ip
# address? # address?
@ -235,14 +240,13 @@ module VagrantPlugins
network_address << "#{@interface_network[:netmask]}" network_address << "#{@interface_network[:netmask]}"
net = IPAddr.new(network_address) net = IPAddr.new(network_address)
# First is address of network, second is gateway. # First is address of network, second is gateway (by default).
# Start the range two # So start the range two addresses after network address by default.
# addresses after network address.
# TODO: Detect if this IP is not set on the interface. # TODO: Detect if this IP is not set on the interface.
start_address = net.to_range.begin.succ.succ start_address = @options[:dhcp_start] || net.to_range.begin.succ
# Stop address must not be broadcast. # Default to last possible address. (Stop address must not be broadcast address.)
stop_address = net.to_range.end & IPAddr.new('255.255.255.254') stop_address = @options[:dhcp_stop] || (net.to_range.end & IPAddr.new('255.255.255.254'))
@network_dhcp_enabled = true @network_dhcp_enabled = true
@network_dhcp_bootp_file = @options[:dhcp_bootp_file] @network_dhcp_bootp_file = @options[:dhcp_bootp_file]