diff --git a/.rubocop.yml b/.rubocop.yml index 50cf087..050ba09 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -21,3 +21,7 @@ SignalException: Metrics/ClassLength: Enabled: false + +Metrics/BlockLength: + Exclude: + - tests/**/*.rb diff --git a/lib/fog/libvirt/models/compute/server.rb b/lib/fog/libvirt/models/compute/server.rb index 55241f2..a83bdc0 100644 --- a/lib/fog/libvirt/models/compute/server.rb +++ b/lib/fog/libvirt/models/compute/server.rb @@ -13,7 +13,9 @@ class Server < Fog::Compute::Server attribute :cpus attribute :cputime + attribute :os_firmware attribute :os_type + attribute :os_loader attribute :memory_size attribute :max_memory_size attribute :name @@ -281,10 +283,28 @@ def to_xml end xml.vcpu(cpus) - xml.os do + + os_tags = {} + + # Secure boot and stateless UEFI both imply an EFI firmware + if ["secure", "stateless"].include?(os_loader) + os_tags[:firmware] = "efi" + elsif os_firmware + os_tags[:firmware] = os_firmware + end + + xml.os(**os_tags) do type = xml.type(os_type, :arch => arch) type[:machine] = "q35" if ["i686", "x86_64"].include?(arch) + # TODO: can you use both secure and stateless at the same time? + case attributes[:os_loader] + when "secure" + xml.loader(:secure => "yes") + when "stateless" + xml.loader(:stateless => "yes") + end + boot_order.each do |dev| xml.boot(:dev => dev) end diff --git a/tests/libvirt/models/compute/server_tests.rb b/tests/libvirt/models/compute/server_tests.rb index 6983cbb..1450125 100644 --- a/tests/libvirt/models/compute/server_tests.rb +++ b/tests/libvirt/models/compute/server_tests.rb @@ -30,6 +30,8 @@ attributes = [ :id, :cpus, :cputime, + :os_firmware, + :os_loader, :os_type, :memory_size, :max_memory_size, @@ -60,6 +62,7 @@ end test('be a kind of Fog::Libvirt::Compute::Server') { server.kind_of? Fog::Libvirt::Compute::Server } tests("serializes to xml") do + test("without firmware") { server.to_xml.include?("") } test("with memory") { server.to_xml.match?(%r{\d+}) } test("with disk of type file") do xml = server.to_xml @@ -78,6 +81,27 @@ xml.match?(//) && xml.match?(%r{}) end test("with q35 machine type on x86_64") { server.to_xml.match?(%r{hvm}) } + test("with efi firmware") do + server = Fog::Libvirt::Compute::Server.new( + { + :os_firmware => "efi", + :nics => [], + :volumes => [] + } + ) + server.to_xml.include?('') + end + test("with secure boot") do + server = Fog::Libvirt::Compute::Server.new( + { + :os_loader => "secure", + :nics => [], + :volumes => [] + } + ) + xml = server.to_xml + xml.include?('') && xml.include?('') + end end end end