Compare commits

...
Sign in to create a new pull request.

5 commits

Author SHA1 Message Date
Pavel Valena
06f6a69988 Add rspec to Gemfile
Remove unnecessary Require
2016-01-19 16:58:34 +01:00
Pavel Valena
a85d6e2bf3 Handle private networks with type DHCP
Resolves rhbz#1299829
2016-01-19 16:58:34 +01:00
Dan Williams
aa4489a1c5 Fix parsing of DHCP leases and pass MAC addresses to vagrant 2015-07-10 17:15:10 -05:00
Josef Stribny
d825d2d2ad Fix: Wait for libvirt to shutdown the domain 2015-04-21 14:55:42 +02:00
Josef Stribny
2455dd1288 Update to 0.0.26 2015-04-20 11:18:13 +02:00
7 changed files with 257 additions and 4 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/vagrant-libvirt-0.0.24.gem
/vagrant-libvirt-0.0.25.gem
/vagrant-libvirt-0.0.26.gem

View file

@ -1 +1 @@
d4c2d6cce19f73ef2c2773a99d7ec984 vagrant-libvirt-0.0.25.gem
011bd6709c3d80a50951347877da94e6 vagrant-libvirt-0.0.26.gem

View file

@ -0,0 +1,44 @@
From 6fb57de11e316cfac44c175b7f5ac23c637e1413 Mon Sep 17 00:00:00 2001
From: Dan Williams <dcbw@redhat.com>
Date: Fri, 1 May 2015 09:42:44 -0500
Subject: [PATCH] Fix retrieving VM IP address if there are multiple leases for
the same VM
If DHCP is used as the addressing mode of the VM it may receive various IP
addresses over time. Thus dnsmasq can report all these addresses for a single
machine, which gives us:
addresses {:public=>["192.168.121.180\n192.168.121.184\n192.168.121.183\n192.168.121.182"],
:private=>["192.168.121.180\n192.168.121.184\n192.168.121.183\n192.168.121.182"]}
This causes the most problems when NFS is used as the shared folder mechanism,
as the IP addresses pile up and a malformed /etc/exports is written. This in
turn causes sequences of vagrant halt / vagrant up to receive read-only NFS
exports due to the bad format:
# VAGRANT-BEGIN: 1000 d943c68a-330b-4cb8-8711-53506a6c176e
"/home/user/folder" 192.168.121.52
192.168.121.51(rw,no_subtree_check,all_squash,anonuid=1000,anongid=1000,fsid=3414715164)
# VAGRANT-END: 1000 d943c68a-330b-4cb8-8711-53506a6c176e
It appears that Vagrant expects that the value returned by read_ssh_info is
just a single IP address, so pick the first IP address reported by dnsmasq.
---
lib/vagrant-libvirt/action/read_ssh_info.rb | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/vagrant-libvirt/action/read_ssh_info.rb b/lib/vagrant-libvirt/action/read_ssh_info.rb
index 01e32a7..0bee747 100644
--- a/lib/vagrant-libvirt/action/read_ssh_info.rb
+++ b/lib/vagrant-libvirt/action/read_ssh_info.rb
@@ -34,7 +34,9 @@ def read_ssh_info(libvirt, machine)
ip_address = nil
domain.wait_for(2) {
addresses.each_pair do |type, ip|
- ip_address = ip[0] if ip[0] != nil
+ # Multiple leases are separated with a newline, return only
+ # the most recent address
+ ip_address = ip[0].split("\n").first if ip[0] != nil
end
ip_address != nil
}

View file

@ -0,0 +1,37 @@
From cc8aadc9de397441b7e2a10eecc76feb6143b4c7 Mon Sep 17 00:00:00 2001
From: Josef Stribny <jstribny@redhat.com>
Date: Tue, 21 Apr 2015 09:04:53 +0200
Subject: [PATCH] Wait for libvirt to shutdown the domain
Fixes #293
---
lib/vagrant-libvirt/action/read_state.rb | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/lib/vagrant-libvirt/action/read_state.rb b/lib/vagrant-libvirt/action/read_state.rb
index ad552a1..1848de4 100644
--- a/lib/vagrant-libvirt/action/read_state.rb
+++ b/lib/vagrant-libvirt/action/read_state.rb
@@ -27,10 +27,17 @@ module VagrantPlugins
end
# Find the machine
begin
+ # Wait for libvirt to shutdown the domain
+ while libvirt.servers.get(machine.id).state.to_sym == :'shutting-down' do
+ @logger.info('Waiting on the machine to shut down...')
+ sleep 1
+ end
+
server = libvirt.servers.get(machine.id)
- if server.nil? || [:'shutting-down', :terminated].include?(server.state.to_sym)
+
+ if server.nil? || server.state.to_sym == :terminated
# The machine can't be found
- @logger.info('Machine shutting down or terminated, assuming it got destroyed.')
+ @logger.info('Machine terminated, assuming it got destroyed.')
machine.id = nil
return :not_created
end
--
2.1.0

View file

@ -0,0 +1,70 @@
From 6c2bd8d897056b50f838dd85ad37d7de8a7821e5 Mon Sep 17 00:00:00 2001
From: Pavel Valena <pvalena@redhat.com>
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

View file

@ -0,0 +1,69 @@
From ee7afab369dc7e80128ff35a2ff11f6eab23d368 Mon Sep 17 00:00:00 2001
From: Dan Williams <dcbw@redhat.com>
Date: Tue, 30 Jun 2015 16:24:30 -0500
Subject: [PATCH] Read MAC address from libvirt and pass up to Vagrant
Configuring networks based solely on slot numbers doesn't work very
well, since there's no way to guarantee that the interface Vagrant
finds is the same one that vagrant-libvirt created at that index.
For example, Vagrant's Fedora configure_networks action does this:
machine.communicate.sudo("ls /sys/class/net | grep -v lo") do |_, result|
interface_names = result.split("\n")
end
interface_names = networks.map do |network|
"#{interface_names[network[:interface]]}"
end
which means that if your image has 'docker' pre-installed, then
interface_names[0] = "docker0" and hilarity ensues, with the first
non-management network being assigned to the vagrant-libvirt
management interface.
Since interface names are very unreliable (they can be renamed by
udev at will or when hardware changes) the only way to ensure that
the interface vagrant-libvirt attaches to the domain maps to the
correct one inside the VM is by MAC address. Pull the MAC address
out of the libvirt config once the interface has been attached and
pass that up to Vagrant so we have a chance of doing the right thing.
---
lib/vagrant-libvirt/action/create_network_interfaces.rb | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/lib/vagrant-libvirt/action/create_network_interfaces.rb b/lib/vagrant-libvirt/action/create_network_interfaces.rb
index 35886ad..cbe7562 100644
--- a/lib/vagrant-libvirt/action/create_network_interfaces.rb
+++ b/lib/vagrant-libvirt/action/create_network_interfaces.rb
@@ -96,6 +96,21 @@ def call(env)
raise Errors::AttachDeviceError,
:error_message => e.message
end
+
+ # Re-read the network configuration and grab the MAC address
+ if !@mac
+ xml = Nokogiri::XML(domain.xml_desc)
+ if iface_configuration[:iface_type] == :public_network
+ if @type == 'direct'
+ @mac = xml.xpath("/domain/devices/interface[source[@dev='#{@device}']]/mac/@address")
+ else
+ @mac = xml.xpath("/domain/devices/interface[source[@bridge='#{@device}']]/mac/@address")
+ end
+ else
+ @mac = xml.xpath("/domain/devices/interface[source[@network='#{@network_name}']]/mac/@address")
+ end
+ iface_configuration[:mac] = @mac.to_s
+ end
end
# Continue the middleware chain.
@@ -116,7 +131,7 @@ def call(env)
network = {
:interface => slot_number,
:use_dhcp_assigned_default_route => options[:use_dhcp_assigned_default_route],
- #:mac => ...,
+ :mac_address => options[:mac],
}
if options[:ip]

View file

@ -1,8 +1,8 @@
%global vagrant_plugin_name vagrant-libvirt
Name: %{vagrant_plugin_name}
Version: 0.0.25
Release: 1%{?dist}
Version: 0.0.26
Release: 4%{?dist}
Summary: libvirt provider for Vagrant
Group: Development/Languages
License: MIT
@ -11,6 +11,18 @@ Source0: https://rubygems.org/gems/%{vagrant_plugin_name}-%{version}.gem
Source1: 10-vagrant-libvirt.rules
# Adjust Vagrant's dependencies.
Patch0: vagrant-libvirt-fix-dependencies.patch
# Wait for libvirt to shutdown the domain
# https://github.com/pradels/vagrant-libvirt/pull/347
Patch1: vagrant-libvirt-fix-halting.patch
# Fix parsing leases when 'vagrant halt; vagrant up' is called
# https://github.com/pradels/vagrant-libvirt/pull/356
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
@ -27,7 +39,6 @@ Requires: rubygem(multi_json)
Requires: libvirt
# vagrant-libvirt supports only kvm and qemu for now.
# https://github.com/pradels/vagrant-libvirt#provider-options
Requires: libvirt-daemon-kvm
Requires: polkit
Requires: vagrant
BuildRequires: vagrant
@ -57,6 +68,10 @@ gem unpack %{SOURCE0}
gem spec %{SOURCE0} -l --ruby > %{vagrant_plugin_name}.gemspec
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%build
gem build %{vagrant_plugin_name}.gemspec
@ -76,6 +91,8 @@ install -m 0644 %{SOURCE1} %{buildroot}%{vagrant_plugin_docdir}/polkit
%check
pushd .%{vagrant_plugin_instdir}
sed -i '/:git/ s|:git.*$|:path => "%{vagrant_dir}"|' Gemfile
sed -i '/pry/d' Gemfile
sed -i '10igem "rspec", "~> 2.0"' Gemfile
sed -i '/rspec/ s|\[\".*\"]|["~> 2.0"]|' vagrant-libvirt.gemspec
bundle exec rspec2 spec
@ -115,6 +132,21 @@ getent group vagrant >/dev/null || groupadd -r vagrant
%changelog
* Tue Jan 19 2016 Pavel Valena <pvalena@redhat.com> - 0.0.26-4
- Fix: Handle private networks with type DHCP (rhbz#1299829)
- Add rspec dependency to Gemfile
- Remove unnecessary libvirt-daemon-kvm from Reqires
* Fri Jul 10 2015 Dan Williams <dcbw@redhat.com> - 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
* Tue Apr 21 2015 Josef Stribny <jstribny@redhat.com> - 0.0.26-2
- Fix: Wait for libvirt to shutdown the domain
* Mon Apr 20 2015 Josef Stribny <jstribny@redhat.com> - 0.0.26-1
- Update to 0.0.26
* Tue Mar 10 2015 Josef Stribny <jstribny@redhat.com> - 0.0.25-1
- Update to 0.0.25