From 72a997950651dfdbad4f41171a05d6b622101656 Mon Sep 17 00:00:00 2001 From: Danilo Del Busso Date: Tue, 10 Aug 2021 12:37:37 +0100 Subject: [PATCH] CA-339273: Mention source and destination Hosts in VM move action Also removed unused `this` calls, and updated one constructor override. Signed-off-by: Danilo Del Busso --- XenAdmin/Dialogs/VMDialogs/MoveVMDialog.cs | 2 +- XenModel/Actions/VM/VMMoveAction.cs | 36 ++++++++++------------ XenModel/Messages.Designer.cs | 11 +------ XenModel/Messages.resx | 5 +-- 4 files changed, 20 insertions(+), 34 deletions(-) diff --git a/XenAdmin/Dialogs/VMDialogs/MoveVMDialog.cs b/XenAdmin/Dialogs/VMDialogs/MoveVMDialog.cs index 491644534..27c0daebe 100644 --- a/XenAdmin/Dialogs/VMDialogs/MoveVMDialog.cs +++ b/XenAdmin/Dialogs/VMDialogs/MoveVMDialog.cs @@ -78,7 +78,7 @@ namespace XenAdmin.Dialogs.VMDialogs private void buttonMove_Click(object sender, EventArgs e) { - var action = new VMMoveAction(vm, srPicker1.SR, vm.GetStorageHost(false), vm.Name()); + var action = new VMMoveAction(vm, srPicker1.SR, vm.GetStorageHost(false)); action.RunAsync(); Close(); } diff --git a/XenModel/Actions/VM/VMMoveAction.cs b/XenModel/Actions/VM/VMMoveAction.cs index c63e38ca1..8598c520b 100644 --- a/XenModel/Actions/VM/VMMoveAction.cs +++ b/XenModel/Actions/VM/VMMoveAction.cs @@ -45,13 +45,13 @@ namespace XenAdmin.Actions.VMActions private Dictionary _storageMapping; public VMMoveAction(VM vm, Dictionary storageMapping, Host host) - : base(vm.Connection, string.Format(Messages.ACTION_VM_MOVING, vm.Name())) + : base(vm.Connection, string.Format(Messages.ACTION_VM_MOVING, vm.Name(), vm.Connection.Name, host.Name())) { - this.VM = vm; - this.Host = host; - this.Pool = Helpers.GetPool(vm.Connection); + VM = vm; + Host = host; + Pool = Helpers.GetPool(vm.Connection); if (vm.is_a_template) - this.Template = vm; + Template = vm; _storageMapping = storageMapping; SR = _storageMapping.Values.FirstOrDefault(); @@ -59,26 +59,22 @@ namespace XenAdmin.Actions.VMActions PopulateApiMethodsToRoleCheck(); } - public VMMoveAction(VM vm, SR sr, Host host, string namelabel) - : base(vm.Connection, string.Format(Messages.ACTION_VM_MOVING_TITLE, vm.Name(), namelabel, sr.NameWithoutHost())) + public VMMoveAction(VM vm, SR sr, Host host) + : this(vm, GetStorageMapping(vm, sr), host) { - this.VM = vm; - this.Host = host; - this.Pool = Helpers.GetPool(vm.Connection); - this.SR = sr; - if (vm.is_a_template) - this.Template = vm; + } - // create a storage map where all VDIs are mapped to the same SR - _storageMapping = new Dictionary(); + private static Dictionary GetStorageMapping(VM vm, SR sr) + { + var storageMapping = new Dictionary(); foreach (var vbdRef in vm.VBDs) { var vbd = vm.Connection.Resolve(vbdRef); if (vbd != null) - _storageMapping.Add(vbd.VDI.opaque_ref, sr); + storageMapping.Add(vbd.VDI.opaque_ref, sr); } + return storageMapping; - PopulateApiMethodsToRoleCheck(); } #region RBAC Dependencies @@ -96,7 +92,7 @@ namespace XenAdmin.Actions.VMActions protected override void Run() { - Description = Messages.ACTION_PREPARING; + Description = Messages.MOVING; // move the progress bar above 0, it's more reassuring to see than a blank bar as we copy the first disk PercentComplete += 10; @@ -160,11 +156,13 @@ namespace XenAdmin.Actions.VMActions PercentComplete += halfstep; } + Description = Messages.MOVING; + if (SR != null) VM.set_suspend_SR(Session, VM.opaque_ref, SR.opaque_ref); if (exceptions.Count > 0) - throw new Exception(Messages.ACTION_VM_MOVING_VDI_DESTROY_FAILURE); + throw new Exception(string.Format(Messages.ACTION_VM_MOVING_VDI_DESTROY_FAILURE, VM.NameWithLocation())); Description = Messages.MOVED; } diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index ee2b553e4..83bcb7b50 100755 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -3175,7 +3175,7 @@ namespace XenAdmin { } /// - /// Looks up a localized string similar to Moving VM '{0}' to new storage. + /// Looks up a localized string similar to Moving VM '{0}' from Host '{1}' to Host '{2}'. /// public static string ACTION_VM_MOVING { get { @@ -3183,15 +3183,6 @@ namespace XenAdmin { } } - /// - /// Looks up a localized string similar to Moving VM '{0}' to '{1}' on SR '{2}'. - /// - public static string ACTION_VM_MOVING_TITLE { - get { - return ResourceManager.GetString("ACTION_VM_MOVING_TITLE", resourceCulture); - } - } - /// /// Looks up a localized string similar to Failed to finalize moving VM '{0}' to new storage. Please see logs for details.. /// diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index 92fda7da1..5fe154775 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -1177,10 +1177,7 @@ Migrating VM '{0}' - Moving VM '{0}' to new storage - - - Moving VM '{0}' to '{1}' on SR '{2}' + Moving VM '{0}' from Host '{1}' to Host '{2}' Failed to finalize moving VM '{0}' to new storage. Please see logs for details.