From 989b0552e4cd6efa1bba9fc7e9aad20abd6d6546 Mon Sep 17 00:00:00 2001 From: Martin Betak Date: Fri, 23 Jun 2017 20:49:50 +0200 Subject: [PATCH] Implement :reboot_guest for VM Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1462803 --- .../redhat/infra_manager/ovirt_services/strategies/v3.rb | 5 +++++ .../redhat/infra_manager/ovirt_services/strategies/v4.rb | 5 +++++ .../redhat/infra_manager/vm/operations/guest.rb | 9 +++++++++ .../manageiq/providers/redhat/infra_manager/vm_spec.rb | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/models/manageiq/providers/redhat/infra_manager/ovirt_services/strategies/v3.rb b/app/models/manageiq/providers/redhat/infra_manager/ovirt_services/strategies/v3.rb index 63b272773..18fb4cc93 100644 --- a/app/models/manageiq/providers/redhat/infra_manager/ovirt_services/strategies/v3.rb +++ b/app/models/manageiq/providers/redhat/infra_manager/ovirt_services/strategies/v3.rb @@ -149,6 +149,11 @@ def shutdown_guest(operation) rescue Ovirt::VmIsNotRunning end + def reboot_guest(operation) + operation.with_provider_object(&:reboot) + rescue Ovirt::VmIsNotRunning + end + def start_clone(source, clone_options, phase_context) source.with_provider_object do |rhevm_template| vm = rhevm_template.create_vm(clone_options) diff --git a/app/models/manageiq/providers/redhat/infra_manager/ovirt_services/strategies/v4.rb b/app/models/manageiq/providers/redhat/infra_manager/ovirt_services/strategies/v4.rb index 103476360..7984590fb 100644 --- a/app/models/manageiq/providers/redhat/infra_manager/ovirt_services/strategies/v4.rb +++ b/app/models/manageiq/providers/redhat/infra_manager/ovirt_services/strategies/v4.rb @@ -183,6 +183,11 @@ def shutdown_guest(operation) rescue OvirtSDK4::Error end + def reboot_guest(operation) + operation.with_provider_object(VERSION_HASH, &:reboot) + rescue OvirtSDK4::Error + end + def start_clone(source, clone_options, phase_context) source.with_provider_object(VERSION_HASH) do |rhevm_template| vm = rhevm_template.create_vm(clone_options) diff --git a/app/models/manageiq/providers/redhat/infra_manager/vm/operations/guest.rb b/app/models/manageiq/providers/redhat/infra_manager/vm/operations/guest.rb index f2f31c80c..166b737dc 100644 --- a/app/models/manageiq/providers/redhat/infra_manager/vm/operations/guest.rb +++ b/app/models/manageiq/providers/redhat/infra_manager/vm/operations/guest.rb @@ -6,9 +6,18 @@ module ManageIQ::Providers::Redhat::InfraManager::Vm::Operations::Guest unsupported_reason_add(:shutdown_guest, unsupported_reason(:control)) unless supports_control? unsupported_reason_add(:shutdown_guest, _("The VM is not powered on")) unless current_state == "on" end + + supports :reboot_guest do + unsupported_reason_add(:reboot_guest, unsupported_reason(:control)) unless supports_control? + unsupported_reason_add(:reboot_guest, _("The VM is not powered on")) unless current_state == "on" + end end def raw_shutdown_guest ext_management_system.ovirt_services.shutdown_guest(self) end + + def raw_reboot_guest + ext_management_system.ovirt_services.reboot_guest(self) + end end diff --git a/spec/models/manageiq/providers/redhat/infra_manager/vm_spec.rb b/spec/models/manageiq/providers/redhat/infra_manager/vm_spec.rb index dce35e013..f8be76e1c 100644 --- a/spec/models/manageiq/providers/redhat/infra_manager/vm_spec.rb +++ b/spec/models/manageiq/providers/redhat/infra_manager/vm_spec.rb @@ -40,7 +40,7 @@ context("with :reboot_guest") do let(:state) { :reboot_guest } - include_examples "Vm operation is not available" + include_examples 'Vm operation is available when powered on' end context("with :reset") do