From b3e445a8b08760379efd89db05623ca78f35b341 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Fri, 8 Oct 2021 18:00:01 +0100 Subject: [PATCH] Add aliases for devices (#1374) It is more reliable to identify disk and network devices by use of aliases, in addition to being able to establish in the absence of information the purpose of such devices. There is a possibility that in some cases this will also resolve issues where the same device attach issued twice with the same details will fail due to the second request not appearing to be honoured. Additionally when destroying domains, may not have the relevant details on how many disks are provided by the box, for those that support multiple disks. Being able to traverse the domain XML and destroy the appropriate volumes based on aliases names will remove the need to have predictable device identifiers during the destroy and allow for an improved resolver. Relates: #1342 --- lib/vagrant-libvirt/action/create_network_interfaces.rb | 1 + lib/vagrant-libvirt/templates/domain.xml.erb | 6 ++++-- lib/vagrant-libvirt/templates/public_interface.xml.erb | 1 + .../action/create_domain_spec/additional_disks_domain.xml | 2 ++ spec/unit/action/create_domain_spec/default_domain.xml | 1 + spec/unit/templates/domain_all_settings.xml | 4 ++++ 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_network_interfaces.rb b/lib/vagrant-libvirt/action/create_network_interfaces.rb index 4c96352..98bb20e 100644 --- a/lib/vagrant-libvirt/action/create_network_interfaces.rb +++ b/lib/vagrant-libvirt/action/create_network_interfaces.rb @@ -251,6 +251,7 @@ module VagrantPlugins udp_tunnel={}, pci_bus, pci_slot) Nokogiri::XML::Builder.new do |xml| xml.interface(type: type || 'network') do + xml.alias(name: "ua-net-#{iface_number}") xml.source(source_options) do xml.local(udp_tunnel) if type == 'udp' end diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 6ea1fcd..7a67fff 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -113,8 +113,9 @@ <% if @emulator_path %> <%= @emulator_path %> <% end %> -<% @domain_volumes.each do |volume| -%> +<% @domain_volumes.each_with_index do |volume, index| -%> + <% end -%> <%# additional disks -%> -<% @disks.each do |d| -%> +<% @disks.each_with_index do |d, index| -%> + trustGuestRxFilters='yes'<% end %>> + <% if @mac %> <% end %> diff --git a/spec/unit/action/create_domain_spec/additional_disks_domain.xml b/spec/unit/action/create_domain_spec/additional_disks_domain.xml index b15fb74..e737861 100644 --- a/spec/unit/action/create_domain_spec/additional_disks_domain.xml +++ b/spec/unit/action/create_domain_spec/additional_disks_domain.xml @@ -27,11 +27,13 @@ + + diff --git a/spec/unit/action/create_domain_spec/default_domain.xml b/spec/unit/action/create_domain_spec/default_domain.xml index e661447..6f09729 100644 --- a/spec/unit/action/create_domain_spec/default_domain.xml +++ b/spec/unit/action/create_domain_spec/default_domain.xml @@ -27,6 +27,7 @@ + diff --git a/spec/unit/templates/domain_all_settings.xml b/spec/unit/templates/domain_all_settings.xml index 05f048c..66a29c7 100644 --- a/spec/unit/templates/domain_all_settings.xml +++ b/spec/unit/templates/domain_all_settings.xml @@ -44,21 +44,25 @@ /usr/bin/kvm-spice + + + +