From f221daaaaf538ca973888da5c921a357c761218a Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Mon, 22 Nov 2021 17:29:11 +0000 Subject: [PATCH] Tidy up XML generated (#1407) To make it easier to see when the XML generated has deviated from expected, tidy up the emitted XML to use a more consistent formatting that would be inline with what would be expected to be output by virsh directly. --- lib/vagrant-libvirt/action/create_domain.rb | 8 +- lib/vagrant-libvirt/templates/domain.xml.erb | 447 +++++++++--------- .../additional_disks_domain.xml | 24 +- .../custom_disk_settings.xml | 24 +- .../create_domain_spec/default_domain.xml | 24 +- .../create_domain_spec/two_disk_settings.xml | 24 +- .../start_domain_spec/clock_timer_rtc.xml | 24 +- .../unit/action/start_domain_spec/default.xml | 24 +- .../default_added_tpm_path.xml | 24 +- .../default_added_tpm_version.xml | 24 +- spec/unit/templates/domain_all_settings.xml | 127 ++--- .../templates/domain_custom_cpu_model.xml | 24 +- spec/unit/templates/domain_defaults.xml | 24 +- spec/unit/templates/tpm/version_1.2.xml | 24 +- spec/unit/templates/tpm/version_2.0.xml | 24 +- 15 files changed, 345 insertions(+), 525 deletions(-) diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index b0bb3b4..738ad01 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -75,11 +75,7 @@ module VagrantPlugins @graphics_autoport = config.graphics_autoport @graphics_port = config.graphics_port @graphics_ip = config.graphics_ip - @graphics_passwd = if config.graphics_passwd.to_s.empty? - '' - else - "passwd='#{config.graphics_passwd}'" - end + @graphics_passwd = config.graphics_passwd @graphics_gl = config.graphics_gl @video_type = config.video_type @sound_type = config.sound_type @@ -312,7 +308,7 @@ module VagrantPlugins env[:ui].info(" -- Graphics Type: #{@graphics_type}") env[:ui].info(" -- Graphics Port: #{@graphics_port}") env[:ui].info(" -- Graphics IP: #{@graphics_ip}") - env[:ui].info(" -- Graphics Password: #{@graphics_passwd.empty? ? 'Not defined' : 'Defined'}") + env[:ui].info(" -- Graphics Password: #{@graphics_passwd.nil? ? 'Not defined' : 'Defined'}") env[:ui].info(" -- Video Type: #{@video_type}") env[:ui].info(" -- Video VRAM: #{@video_vram}") env[:ui].info(" -- Video 3D accel: #{@video_accel3d}") diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index c0d17a1..8bab907 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -5,115 +5,111 @@ <%= @uuid %> <%= @memory_size %> cpuset='<%= @cpuset %>'<% end %>><%= @cpus %> - - - <% if @cpu_mode != 'host-passthrough' %> - <% if @cpu_mode == 'custom' %><%= @cpu_model %><% end %> - <% if @nested %> - <% if @cpu_features.select{|x| x[:name] == 'vmx'}.empty? %> - - <% end %> - <% if @cpu_features.select{|x| x[:name] == 'svm'}.empty? %> - - <% end %> - <% end %> - <% @cpu_features.each do |cpu_feature| %> - - <% end %> - <% unless @cpu_topology.empty? %> - <%# CPU topology -%> - - <% end %> - <% end %> - <% if @numa_nodes %> - - <% @numa_nodes.each_with_index do |node, index| %> - - <% end %> - - <% end %> +<%- if @cpu_mode != 'host-passthrough' -%> + <% if @cpu_mode == 'custom' %><%= @cpu_model %><% end %> + <%- if @nested -%> + <%- if @cpu_features.select{|x| x[:name] == 'vmx'}.empty? -%> + + <%- end -%> + <%- if @cpu_features.select{|x| x[:name] == 'svm'}.empty? -%> + + <%- end -%> + <%- end -%> + <%- @cpu_features.each do |cpu_feature| -%> + + <%- end -%> + <%- unless @cpu_topology.empty? -%> + <%# CPU topology -%> + + <%- end -%> + <%- end -%> + <%- if @numa_nodes -%> + + <%- @numa_nodes.each_with_index do |node, index| -%> + + <%- end -%> + + <%- end -%> - <%- if @nodeset -%> <%- end -%> -<% unless @memory_backing.empty? %> +<%- unless @memory_backing.empty? -%> - <% @memory_backing.each do |backing| %> + <%- @memory_backing.each do |backing| -%> <<%= backing[:name] %> <%= backing[:config].map { |k,v| "#{k}='#{v}'"}.join(' ') %>/> - <% end %> + <%- end -%> -<% end%> -<% if @shares %> +<%- end%> +<%- if @shares -%> <%= @shares %> -<% end %> - +<%- end -%> - <% if @machine_type %> - <% if @machine_arch %> - hvm - <% else %> - hvm - <% end %> - <% else %> - <% if @machine_arch %> - hvm - <% else %> - hvm - <% end %> - <% end %> - <% if @loader %> - <% if @nvram %> - <%= @loader %> - <% else %> - <%= @loader %> - <% end %> - <% end %> - <% if @nvram %> - <%= @nvram %> - <% end %> - <% if @boot_order.count >= 1 %> - - <% end %> +<%- if @machine_type -%> + <%- if @machine_arch -%> + hvm + <%- else -%> + hvm + <%- end -%> +<%- else -%> + <%- if @machine_arch -%> + hvm + <%- else -%> + hvm + <%- end -%> +<%- end -%> +<%- if @loader -%> + <%- if @nvram -%> + <%= @loader %> + <%- else -%> + <%= @loader %> + <%- end -%> +<%- end -%> +<%- if @nvram -%> + <%= @nvram %> +<%- end -%> +<%- if @boot_order.count >= 1 -%> + +<%- end -%> <%= @kernel %> <%= @initrd %> <%= @cmd_line %> - <% if @dtb %> - <%= @dtb %> - <% end %> +<%- if @dtb -%> + <%= @dtb %> +<% end -%> - <% @features.each do |feature| %> +<%- @features.each do |feature| -%> <<%= feature %>/> - <% end %> - <% if @kvm_hidden %> - - - - <% end %> - <% if !@features_hyperv.empty? %> +<%- end -%> +<%- if @kvm_hidden -%> + + + +<%- end -%> +<%- if !@features_hyperv.empty? -%> - <% @features_hyperv.each do |feature| %> + <%- @features_hyperv.each do |feature| -%> <<%= feature[:name] %> state='<%= feature[:state] %>'<% if feature[:name] == 'spinlocks' %> retries='<%= feature[:retries] %>'<% end %> /> - <% end %> + <%- end -%> - <% end %> +<%- end -%> - <% @clock_timers.each do |clock_timer| %> +<%- @clock_timers.each do |clock_timer| -%> <%= attr %>='<%= value %>'<% end %>/> - <% end %> +<%- end -%> - <% if @emulator_path %> +<%- if @emulator_path -%> <%= @emulator_path %> - <% end %> -<% @domain_volumes.each_with_index do |volume, index| -%> +<%- end -%> +<%- @domain_volumes.each_with_index do |volume, index| -%> -<% end -%> +<%- end -%> <%# additional disks -%> -<% @disks.each_with_index do |d, index| -%> +<%- @disks.each_with_index do |d, index| -%> /> - <% if d[:shareable] %> - - <% end %> - <% if d[:serial] %> - <%= d[:serial] %> - <% end %> - <% if d[:wwn] %> - <%= d[:wwn] %> - <% end %> + <%- if d[:shareable] -%> + + <%- end -%> + <%- if d[:serial] -%> + <%= d[:serial] %> + <%- end -%> + <%- if d[:wwn] -%> + <%= d[:wwn] %> + <%- end -%> <%# this will get auto generated by Libvirt
-%> <% end -%> - -<% @cdroms.each do |c| %> +<%- @cdroms.each do |c| -%> -<% end %> - -<% @serials.each_with_index do |serial, port| %> +<%- end -%> +<%- @serials.each_with_index do |serial, port| -%> - <% unless serial[:source].nil? %> + <%- unless serial[:source].nil? -%> - <% end %> + <%- end -%> - <% end %> - <% console_log = @serials.first %> + <%- end -%> + <%- console_log = @serials.first -%> - <% unless console_log[:source].nil? %> + <%- unless console_log[:source].nil? -%> -<% end %> +<%- end -%> - -<% @channels.each do |channel| %> - - <%if channel[:source_mode] or channel[:source_path] %> - - mode='<%= channel[:source_mode] %>' - <% end %> - <% if channel[:source_path] %> - path="<%= channel[:source_path] %>" - <% end %> - /> - <% end %> - - name="<%= channel[:target_name] %>" - <% end %> - <% if channel[:target_address] %> - address="<%= channel[:target_address] %>" - <% end %> - <% if channel[:target_port] %> - port="<%= channel[:target_port] %>" - <% end %> - /> - -<% end %> - -<% @inputs.each do |input| %> +<%- @channels.each do |channel| -%> + + <%-if channel[:source_mode] or channel[:source_path] -%> + /> + <%- end -%> + /> + +<%- end -%> +<%- @inputs.each do |input| -%> -<% end %> - - <% if !@sound_type.nil? %> - <%# Sound device-%> - - - <%# End Sound%> - <% end %> - <% if @graphics_type != 'none' %> - <%# Video device -%> - <% if not @graphics_gl %>/><% else %>> - - <% end %> - - <%#End Video -%> - <% end %> - <% if @rng[:model] == "random"%> - - /dev/random - - <% end %> - <% @pcis.each do |pci| %> - - -
- - - <% end %> - <% @usbs.each do |usb| %> - - - <% if usb[:vendor] %> - - <% end %> - <% if usb[:product] %> - - <% end %> - <% if usb[:bus] && usb[:device] %> -
- <% end %> - - - <% end %> - <% unless @redirdevs.empty? %> - <% @redirdevs.each do |redirdev| %> - - - <% end %> - <% unless @redirfilters.empty? %> - - <% @redirfilters.each do |usbdev| %> - - <% end %> - - <% end %> - <% end %> - <% unless @watchdog_dev.empty? %> +<%- end -%> +<%- if !@sound_type.nil? -%> + <%# Sound device-%> + + + <%# End Sound%> +<%- end -%> +<%- if @graphics_type != 'none' + graphics = { + 'type' => @graphics_type, + 'port' => @graphics_port, + 'autoport' => @graphics_autoport, + 'listen' => @graphics_ip, + 'keymap' => @keymap, + 'passwd' => @graphics_passwd, + } +-%> + <%# Video device -%> + <%- if not @graphics_gl %>/><% else %>> + + <% end -%> + + <%#End Video -%> +<%- end -%> +<%- if @rng[:model] == "random"%> + + /dev/random + +<%- end -%> +<%- @pcis.each do |pci| -%> + + +
/> + + +<%- end -%> +<%- @usbs.each do |usb| -%> + + + <%- if usb[:vendor] -%> + + <%- end -%> + <%- if usb[:product] -%> + + <%- end -%> + <%- if usb[:bus] && usb[:device] -%> +
+ <%- end -%> + + +<%- end -%> +<%- unless @redirdevs.empty? -%> + <%- @redirdevs.each do |redirdev| -%> + + + <%- end -%> + <%- unless @redirfilters.empty? -%> + + <%- @redirfilters.each do |usbdev| -%> + + <%- end -%> + + <%- end -%> +<%- end -%> +<%- unless @watchdog_dev.empty? -%> <%# Watchdog Device -%> - <% end %> - - <% unless @smartcard_dev.empty? -%> - <% if @smartcard_dev[:mode] == 'passthrough' %> - <% if @smartcard_dev[:type] == 'tcp' %> - - - - <% else %> - - <% end %> - <% end %> - <% end -%> - - <% if @tpm_path || @tpm_version -%> +<%- end -%> +<%- unless @smartcard_dev.empty? -%> + <%- if @smartcard_dev[:mode] == 'passthrough' -%> + <%- if @smartcard_dev[:type] == 'tcp' -%> + + + + <%- else -%> + + <%- end -%> + <%- end -%> +<%- end -%> +<%- if @tpm_path || @tpm_version -%> <%# TPM Device -%> version='<%= @tpm_version %>'<% end %>> - <% if @tpm_path -%> + <%- if @tpm_path -%> - <% end -%> + <%- end -%> - <% end -%> - <% if not @usbctl_dev.empty? %> +<%- end -%> +<%- if not @usbctl_dev.empty? -%> <%# USB Controller -%> /> - <% end %> - <% unless @memballoon_enabled.nil? %> - <% if @memballoon_enabled %> +<%- end -%> +<%- unless @memballoon_enabled.nil? -%> + <%- if @memballoon_enabled -%>
- <% else %> + <%- else -%> - <% end %> - <% end %> + <%- end -%> +<%- end -%> - - <% if not @qemu_args.empty? or not @qemu_env.empty? %> +<%- if not @qemu_args.empty? or not @qemu_env.empty? -%> - <% @qemu_args.each do |arg| %> + <%- @qemu_args.each do |arg| -%> - <% end %> - <% @qemu_env.each do |env_var, env_value| %> + <%- end -%> + <%- @qemu_env.each do |env_var, env_value| -%> - <% end %> + <%- end -%> - <% end %> +<%- 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 e737861..d671572 100644 --- a/spec/unit/action/create_domain_spec/additional_disks_domain.xml +++ b/spec/unit/action/create_domain_spec/additional_disks_domain.xml @@ -5,15 +5,11 @@ 524288 1 - - - + - - - hvm + hvm @@ -38,24 +34,16 @@ - - - - - - - - - + + - diff --git a/spec/unit/action/create_domain_spec/custom_disk_settings.xml b/spec/unit/action/create_domain_spec/custom_disk_settings.xml index 1970b50..37d9a5e 100644 --- a/spec/unit/action/create_domain_spec/custom_disk_settings.xml +++ b/spec/unit/action/create_domain_spec/custom_disk_settings.xml @@ -5,15 +5,11 @@ 524288 1 - - - + - - - hvm + hvm @@ -32,24 +28,16 @@ - - - - - - - - - + + - diff --git a/spec/unit/action/create_domain_spec/default_domain.xml b/spec/unit/action/create_domain_spec/default_domain.xml index 6f09729..70ece4d 100644 --- a/spec/unit/action/create_domain_spec/default_domain.xml +++ b/spec/unit/action/create_domain_spec/default_domain.xml @@ -5,15 +5,11 @@ 524288 1 - - - + - - - hvm + hvm @@ -32,24 +28,16 @@ - - - - - - - - - + + - diff --git a/spec/unit/action/create_domain_spec/two_disk_settings.xml b/spec/unit/action/create_domain_spec/two_disk_settings.xml index e1804f7..b975c2c 100644 --- a/spec/unit/action/create_domain_spec/two_disk_settings.xml +++ b/spec/unit/action/create_domain_spec/two_disk_settings.xml @@ -5,15 +5,11 @@ 524288 1 - - - + - - - hvm + hvm @@ -38,24 +34,16 @@ - - - - - - - - - + + - diff --git a/spec/unit/action/start_domain_spec/clock_timer_rtc.xml b/spec/unit/action/start_domain_spec/clock_timer_rtc.xml index fe1f199..7bb1403 100644 --- a/spec/unit/action/start_domain_spec/clock_timer_rtc.xml +++ b/spec/unit/action/start_domain_spec/clock_timer_rtc.xml @@ -5,15 +5,11 @@ 1 - - - + - - - hvm + hvm @@ -27,24 +23,16 @@ - - - - - - - - - + + - diff --git a/spec/unit/action/start_domain_spec/default.xml b/spec/unit/action/start_domain_spec/default.xml index 4be9d05..fe3b573 100644 --- a/spec/unit/action/start_domain_spec/default.xml +++ b/spec/unit/action/start_domain_spec/default.xml @@ -5,15 +5,11 @@ 1 - - - + - - - hvm + hvm @@ -25,24 +21,16 @@ - - - - - - - - - + + - diff --git a/spec/unit/action/start_domain_spec/default_added_tpm_path.xml b/spec/unit/action/start_domain_spec/default_added_tpm_path.xml index 3d09012..71f792b 100644 --- a/spec/unit/action/start_domain_spec/default_added_tpm_path.xml +++ b/spec/unit/action/start_domain_spec/default_added_tpm_path.xml @@ -5,15 +5,11 @@ 1 - - - + - - - hvm + hvm @@ -25,24 +21,16 @@ - - - - - - - - - + + - diff --git a/spec/unit/action/start_domain_spec/default_added_tpm_version.xml b/spec/unit/action/start_domain_spec/default_added_tpm_version.xml index beaba37..5129226 100644 --- a/spec/unit/action/start_domain_spec/default_added_tpm_version.xml +++ b/spec/unit/action/start_domain_spec/default_added_tpm_version.xml @@ -5,15 +5,11 @@ 1 - - - + - - - hvm + hvm @@ -25,24 +21,16 @@ - - - - - - - - - + + - diff --git a/spec/unit/templates/domain_all_settings.xml b/spec/unit/templates/domain_all_settings.xml index e1a00ee..9bfd25d 100644 --- a/spec/unit/templates/domain_all_settings.xml +++ b/spec/unit/templates/domain_all_settings.xml @@ -5,25 +5,21 @@ 1 - - - qemu64 - - + qemu64 + + - 1024 - - hvm - /efi/loader - + hvm + /efi/loader + @@ -67,7 +63,6 @@ - @@ -80,7 +75,6 @@ - @@ -89,72 +83,52 @@ - - - - - - - - - - - - + + + + + + + + + + - - - - - - - /dev/random - - - -
- - - - -
- - - - - - -
- - - - - - - + + + + + + /dev/random + + + +
+ + + + +
+ + + + + + +
+ + + + + + + - - - + @@ -162,7 +136,6 @@ - diff --git a/spec/unit/templates/domain_custom_cpu_model.xml b/spec/unit/templates/domain_custom_cpu_model.xml index 0558bca..74b8f0f 100644 --- a/spec/unit/templates/domain_custom_cpu_model.xml +++ b/spec/unit/templates/domain_custom_cpu_model.xml @@ -5,15 +5,11 @@ 1 - - - SandyBridge + SandyBridge - - - hvm + hvm @@ -26,24 +22,16 @@ - - - - - - - - - + + - diff --git a/spec/unit/templates/domain_defaults.xml b/spec/unit/templates/domain_defaults.xml index e4748cc..5fabfd9 100644 --- a/spec/unit/templates/domain_defaults.xml +++ b/spec/unit/templates/domain_defaults.xml @@ -5,15 +5,11 @@ 1 - - - + - - - hvm + hvm @@ -26,24 +22,16 @@ - - - - - - - - - + + - diff --git a/spec/unit/templates/tpm/version_1.2.xml b/spec/unit/templates/tpm/version_1.2.xml index f281d28..4db1209 100644 --- a/spec/unit/templates/tpm/version_1.2.xml +++ b/spec/unit/templates/tpm/version_1.2.xml @@ -5,15 +5,11 @@ 1 - - - + - - - hvm + hvm @@ -26,29 +22,21 @@ - - - - - - - - - + + - diff --git a/spec/unit/templates/tpm/version_2.0.xml b/spec/unit/templates/tpm/version_2.0.xml index f2c7435..5e11f20 100644 --- a/spec/unit/templates/tpm/version_2.0.xml +++ b/spec/unit/templates/tpm/version_2.0.xml @@ -5,15 +5,11 @@ 1 - - - + - - - hvm + hvm @@ -26,28 +22,20 @@ - - - - - - - - - + + -