From a07c68a345cbc122142cbdee6de577e69950a544 Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Fri, 28 Feb 2020 16:49:23 +0000 Subject: [PATCH] CA-334756: Allow detaching and reattaching all types of SRs. Signed-off-by: Konstantina Chremmou --- XenAdmin/Commands/DetachSRCommand.cs | 55 ++++++-------------------- XenAdmin/Commands/ReattachSRCommand.cs | 20 ++-------- XenModel/Messages.Designer.cs | 9 ----- XenModel/Messages.resx | 3 -- XenModel/XenAPI-Extensions/SR.cs | 5 --- 5 files changed, 14 insertions(+), 78 deletions(-) diff --git a/XenAdmin/Commands/DetachSRCommand.cs b/XenAdmin/Commands/DetachSRCommand.cs index 2b2747041..0dc5d49f5 100644 --- a/XenAdmin/Commands/DetachSRCommand.cs +++ b/XenAdmin/Commands/DetachSRCommand.cs @@ -78,51 +78,22 @@ namespace XenAdmin.Commands private static bool CanExecute(SR sr) { - return sr != null && sr.IsDetachable() && !HelpersGUI.GetActionInProgress(sr); + return sr != null && !sr.IsDetached() && !sr.HasRunningVMs() && !HelpersGUI.GetActionInProgress(sr); } - public override string MenuText - { - get - { - return Messages.MAINWINDOW_DETACH_SR; - } - } + public override string MenuText => Messages.MAINWINDOW_DETACH_SR; - protected override bool ConfirmationRequired - { - get - { - return true; - } - } + protected override bool ConfirmationRequired => true; - protected override string ConfirmationDialogText - { - get - { - SelectedItemCollection selection = GetSelection(); + protected override string ConfirmationDialogText => + GetSelection().Count == 1 + ? Messages.MESSAGEBOX_DETACH_SR_CONTINUE + : Messages.MESSAGEBOX_DETACH_SRS_CONTINUE; - if (selection.Count == 1) - { - return Messages.MESSAGEBOX_DETACH_SR_CONTINUE; - } - return Messages.MESSAGEBOX_DETACH_SRS_CONTINUE; - } - } - - protected override string ConfirmationDialogTitle - { - get - { - if (GetSelection().Count == 1) - { - return Messages.MESSAGEBOX_DETACH_SR_CONTINUE_TITLE; - } - - return Messages.MESSAGEBOX_DETACH_SRS_CONTINUE_TITLE; - } - } + protected override string ConfirmationDialogTitle => + GetSelection().Count == 1 + ? Messages.MESSAGEBOX_DETACH_SR_CONTINUE_TITLE + : Messages.MESSAGEBOX_DETACH_SRS_CONTINUE_TITLE; protected override CommandErrorDialog GetErrorDialogCore(IDictionary cantExecuteReasons) { @@ -144,10 +115,6 @@ namespace XenAdmin.Commands { return Messages.SR_HAS_RUNNING_VMS; } - if (!sr.CanCreateWithXenCenter()) - { - return Messages.SR_CANNOT_BE_DETACHED_WITH_XC; - } if (HelpersGUI.GetActionInProgress(sr)) { return Messages.SR_ACTION_IN_PROGRESS; diff --git a/XenAdmin/Commands/ReattachSRCommand.cs b/XenAdmin/Commands/ReattachSRCommand.cs index c813af65f..7e1400842 100644 --- a/XenAdmin/Commands/ReattachSRCommand.cs +++ b/XenAdmin/Commands/ReattachSRCommand.cs @@ -31,10 +31,9 @@ using System; using System.Collections.Generic; -using System.Text; using XenAdmin.Core; -using XenAPI; using XenAdmin.Wizards; +using XenAPI; namespace XenAdmin.Commands @@ -65,9 +64,7 @@ namespace XenAdmin.Commands private void Execute(SR sr) { if (CanReattachSR(sr)) - { MainWindowCommandInterface.ShowPerConnectionWizard(sr.Connection, new NewSRWizard(sr.Connection, sr)); - } } protected override void ExecuteCore(SelectedItemCollection selection) @@ -77,29 +74,18 @@ namespace XenAdmin.Commands protected override bool CanExecuteCore(SelectedItemCollection selection) { - if (selection.Count == 1) - { - return CanReattachSR(selection[0].XenObject as SR); - } - return false; + return selection.Count == 1 && CanReattachSR(selection[0].XenObject as SR); } private static bool CanReattachSR(SR sr) { return sr != null && !sr.HasPBDs() - && sr.CanCreateWithXenCenter() && !HelpersGUI.GetActionInProgress(sr) && !(sr.type == "cslg" && Helpers.FeatureForbidden(sr.Connection, Host.RestrictStorageChoices)) && (SM.GetByType(sr.Connection, sr.type) != null); } - public override string MenuText - { - get - { - return Messages.MAINWINDOW_REATTACH_SR; - } - } + public override string MenuText => Messages.MAINWINDOW_REATTACH_SR; } } diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index b9294005a..6102b5760 100755 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -33894,15 +33894,6 @@ namespace XenAdmin { } } - /// - /// Looks up a localized string similar to This SR cannot be detached with [XenCenter].. - /// - public static string SR_CANNOT_BE_DETACHED_WITH_XC { - get { - return ResourceManager.GetString("SR_CANNOT_BE_DETACHED_WITH_XC", resourceCulture); - } - } - /// /// Looks up a localized string similar to This SR cannot be forgotten with [XenCenter].. /// diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index 19ca172b1..e487f1d80 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -11800,9 +11800,6 @@ You may need to reboot your server(s) to enable SR-IOV network. This SR cannot be destroyed with [XenCenter]. - - This SR cannot be detached with [XenCenter]. - This SR cannot be forgotten with [XenCenter]. diff --git a/XenModel/XenAPI-Extensions/SR.cs b/XenModel/XenAPI-Extensions/SR.cs index 3ed8b390b..ebe29ca22 100644 --- a/XenModel/XenAPI-Extensions/SR.cs +++ b/XenModel/XenAPI-Extensions/SR.cs @@ -218,11 +218,6 @@ namespace XenAPI return null; } - public bool IsDetachable() - { - return !IsDetached() && !HasRunningVMs() && CanCreateWithXenCenter(); - } - /// /// Can create with XC, or is citrix storage link gateway. Special case alert! ///