diff --git a/README.md b/README.md index ad83e54..7f8f13e 100644 --- a/README.md +++ b/README.md @@ -240,8 +240,14 @@ starts with 'libvirt__' string. Here is a list of those options: network 'default' is used. * `:libvirt__netmask` - Used only together with `:ip` option. Default is '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 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. Used only when dhcp is enabled. * `:libvirt__dhcp_bootp_server` - The server that runs the DHCP server. diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb index 9df39db..90dd48e 100644 --- a/lib/vagrant-libvirt/action/create_networks.rb +++ b/lib/vagrant-libvirt/action/create_networks.rb @@ -121,7 +121,12 @@ module VagrantPlugins # Set IP address of network (actually bridge). It will be used as # gateway address for machines connected to this network. 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 # address? @@ -235,14 +240,13 @@ module VagrantPlugins network_address << "#{@interface_network[:netmask]}" net = IPAddr.new(network_address) - # First is address of network, second is gateway. - # Start the range two - # addresses after network address. + # First is address of network, second is gateway (by default). + # So start the range two addresses after network address by default. # 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. - stop_address = net.to_range.end & IPAddr.new('255.255.255.254') + # Default to last possible address. (Stop address must not be broadcast address.) + stop_address = @options[:dhcp_stop] || (net.to_range.end & IPAddr.new('255.255.255.254')) @network_dhcp_enabled = true @network_dhcp_bootp_file = @options[:dhcp_bootp_file]