diff --git a/vagrant-libvirt-handle-private-networks-with-type-dhcp.patch b/vagrant-libvirt-handle-private-networks-with-type-dhcp.patch new file mode 100644 index 0000000..b82b1f2 --- /dev/null +++ b/vagrant-libvirt-handle-private-networks-with-type-dhcp.patch @@ -0,0 +1,70 @@ +From 6c2bd8d897056b50f838dd85ad37d7de8a7821e5 Mon Sep 17 00:00:00 2001 +From: Pavel Valena +Date: Tue, 19 Jan 2016 14:29:30 +0100 +Subject: [PATCH] Handle private networks with type DHCP Resolves rhbz#1299829 + +--- + lib/vagrant-libvirt/action/create_networks.rb | 40 +++++++++++++++++++++++++++ + 1 file changed, 40 insertions(+) + +diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb +index 7ef4643..9ffe191 100644 +--- a/lib/vagrant-libvirt/action/create_networks.rb ++++ b/lib/vagrant-libvirt/action/create_networks.rb +@@ -61,6 +61,8 @@ module VagrantPlugins + + if @options[:ip] + handle_ip_option(env) ++ elsif @options[:type].to_s == 'dhcp' ++ handle_dhcp_private_network(env) + # in vagrant 1.2.3 and later it is not possible to take this branch + # because cannot have name without ip + # https://github.com/mitchellh/vagrant/commit/cf2f6da4dbcb4f57c9cdb3b94dcd0bba62c5f5fd +@@ -218,6 +220,44 @@ module VagrantPlugins + end + end + ++ def handle_dhcp_private_network(env) ++ net_address = '172.28.128.0' ++ network = lookup_network_by_ip(net_address) ++ @interface_network = network if network ++ ++ # Do we need to create new network? ++ unless @interface_network[:created] ++ @interface_network[:name] = 'vagrant-private-dhcp' ++ @interface_network[:network_address] = net_address ++ ++ # Set IP address of network (actually bridge). It will be used as ++ # gateway address for machines connected to this network. ++ @interface_network[:ip_address] = get_host_ip_addr(net_address) ++ ++ # Generate a unique name for network bridge. ++ @interface_network[:bridge_name] = generate_bridge_name ++ ++ # Create a private network. ++ create_private_network(env) ++ end ++ end ++ ++ # Return provided address or first address of network otherwise ++ def get_host_ip_addr(network) ++ @options[:host_ip] ? IPAddr.new(@options[:host_ip]) : IPAddr.new(network).s$ ++ end ++ ++ # Return the first available virbr interface name ++ def generate_bridge_name ++ @logger.debug "generating name for bridge" ++ count = 0 ++ while lookup_bridge_by_name(bridge_name = "virbr#{count}") ++ count += 1 ++ end ++ @logger.debug "found available bridge name #{bridge_name}" ++ bridge_name ++ end ++ + def create_private_network(env) + @network_name = @interface_network[:name] + @network_bridge_name = @interface_network[:bridge_name] +-- +2.5.0 + diff --git a/vagrant-libvirt.spec b/vagrant-libvirt.spec index 7cbcd9b..cfa37e3 100644 --- a/vagrant-libvirt.spec +++ b/vagrant-libvirt.spec @@ -2,7 +2,7 @@ Name: %{vagrant_plugin_name} Version: 0.0.26 -Release: 3%{?dist} +Release: 4%{?dist} Summary: libvirt provider for Vagrant Group: Development/Languages License: MIT @@ -20,6 +20,9 @@ Patch2: vagrant-libvirt-fix-dhcp-lease-parsing.patch # Pass MAC addresses up to vagrant to ensure interfaces are configured correctly # https://github.com/pradels/vagrant-libvirt/pull/408 Patch3: vagrant-libvirt-match-interface-by-mac.patch +# Handle private networks with type DHCP +# Resolves rhbz#1299829 +Patch4: vagrant-libvirt-handle-private-networks-with-type-dhcp.patch Requires(pre): shadow-utils Requires(posttrans): vagrant Requires(preun): vagrant @@ -69,6 +72,7 @@ gem spec %{SOURCE0} -l --ruby > %{vagrant_plugin_name}.gemspec %patch1 -p1 %patch2 -p1 %patch3 -p1 +%patch4 -p1 %build gem build %{vagrant_plugin_name}.gemspec @@ -128,6 +132,9 @@ getent group vagrant >/dev/null || groupadd -r vagrant %changelog +* Tue Jan 19 2016 Pavel Valena - 0.0.26-4 +- Fix: Handle private networks with type DHCP (rhbz#1299829) + * Fri Jul 10 2015 Dan Williams - 0.0.26-3 - Fix: parsing of DHCP leases when vagrant up/halt have been used - Fix: pass MAC addresses to vagrant to configure interfaces correctly