From 76b3c05b9af83a094bcb25db89dd4c7c6e4f5523 Mon Sep 17 00:00:00 2001 From: Mihaela Stoica Date: Thu, 27 Apr 2017 15:19:35 +0100 Subject: [PATCH] CA-250145: XenCenter cannot shutdown VM as VmPowerAdmin user if HA is enabled The error was happening because of the Pool.sync_database call (when HA is enabled and the VM has a saved restart priority other than DoNotRestart) which requires pool admin or pool operator roles. This call is not needed, so removing it. Signed-off-by: Mihaela Stoica --- XenModel/Actions/VM/VMShutdownAction.cs | 40 +++---------------------- XenModel/Actions/VM/VMSuspendAction.cs | 12 ++------ 2 files changed, 6 insertions(+), 46 deletions(-) diff --git a/XenModel/Actions/VM/VMShutdownAction.cs b/XenModel/Actions/VM/VMShutdownAction.cs index be5b2754c..8ed7f509a 100644 --- a/XenModel/Actions/VM/VMShutdownAction.cs +++ b/XenModel/Actions/VM/VMShutdownAction.cs @@ -45,25 +45,6 @@ namespace XenAdmin.Actions.VMActions this.Host = vm.Home(); this.Pool = Core.Helpers.GetPool(vm.Connection); } - - /// - /// Enables or disables HA protection for a VM (VM.ha_always_run). Also does a pool.sync_database afterwards. - /// May throw a XenAPI.Failure. - /// - /// - /// - /// - /// - /// - /// - protected static void SetHaProtection(bool protect, AsyncAction action, VM vm, int start, int end) - { - // Do database sync. Helps to ensure that the change persists over master failover. - action.RelatedTask = XenAPI.Pool.async_sync_database(action.Session); - action.PollToCompletion(start, end); - } - - } public class VMCleanShutdown : VMShutdownAction @@ -75,17 +56,10 @@ namespace XenAdmin.Actions.VMActions protected override void Run() { - bool vmHasSavedRestartPriority = VM.HasSavedRestartPriority; this.Description = Messages.ACTION_VM_SHUTTING_DOWN; - if (vmHasSavedRestartPriority) - { - // Disable HA protection - SetHaProtection(false, this, VM, 0, 50); - } - - RelatedTask = XenAPI.VM.async_clean_shutdown(Session, VM.opaque_ref); - PollToCompletion(vmHasSavedRestartPriority ? 50 : 0, 100); + RelatedTask = VM.async_clean_shutdown(Session, VM.opaque_ref); + PollToCompletion(0, 100); this.Description = Messages.ACTION_VM_SHUT_DOWN; } } @@ -99,16 +73,10 @@ namespace XenAdmin.Actions.VMActions protected override void Run() { - bool vmHasSavedRestartPriority =VM.HasSavedRestartPriority; this.Description = Messages.ACTION_VM_SHUTTING_DOWN; - if (vmHasSavedRestartPriority) - { - // Disable HA protection - SetHaProtection(false, this, VM, 0, 70); - } - RelatedTask = XenAPI.VM.async_hard_shutdown(Session, VM.opaque_ref); - PollToCompletion(vmHasSavedRestartPriority ? 70 : 0, 100); + RelatedTask = VM.async_hard_shutdown(Session, VM.opaque_ref); + PollToCompletion(0, 100); this.Description = Messages.ACTION_VM_SHUT_DOWN; } diff --git a/XenModel/Actions/VM/VMSuspendAction.cs b/XenModel/Actions/VM/VMSuspendAction.cs index a2185eba0..5eec89aa7 100644 --- a/XenModel/Actions/VM/VMSuspendAction.cs +++ b/XenModel/Actions/VM/VMSuspendAction.cs @@ -42,19 +42,11 @@ namespace XenAdmin.Actions.VMActions VM = vm; } - - protected override void Run() { - var vmHasSavedRestartPriority = VM.HasSavedRestartPriority; this.Description = Messages.ACTION_VM_SUSPENDING; - if (vmHasSavedRestartPriority) - { - // Disable HA protection - SetHaProtection(false, this, VM, 0, 50); - } - RelatedTask = XenAPI.VM.async_suspend(Session, VM.opaque_ref); - PollToCompletion(vmHasSavedRestartPriority ? 50 : 0, 100); + RelatedTask = VM.async_suspend(Session, VM.opaque_ref); + PollToCompletion(0, 100); this.Description = Messages.ACTION_VM_SUSPENDED; } }