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 <Danilo.Del.Busso@citrix.com>
This commit is contained in:
Danilo Del Busso 2021-08-10 12:37:37 +01:00
parent a78b1541e7
commit 72a9979506
4 changed files with 20 additions and 34 deletions

View File

@ -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();
}

View File

@ -45,13 +45,13 @@ namespace XenAdmin.Actions.VMActions
private Dictionary<string, SR> _storageMapping;
public VMMoveAction(VM vm, Dictionary<string, SR> 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<string, SR>();
private static Dictionary<string, SR> GetStorageMapping(VM vm, SR sr)
{
var storageMapping = new Dictionary<string, SR>();
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;
}

View File

@ -3175,7 +3175,7 @@ namespace XenAdmin {
}
/// <summary>
/// Looks up a localized string similar to Moving VM &apos;{0}&apos; to new storage.
/// Looks up a localized string similar to Moving VM &apos;{0}&apos; from Host &apos;{1}&apos; to Host &apos;{2}&apos;.
/// </summary>
public static string ACTION_VM_MOVING {
get {
@ -3183,15 +3183,6 @@ namespace XenAdmin {
}
}
/// <summary>
/// Looks up a localized string similar to Moving VM &apos;{0}&apos; to &apos;{1}&apos; on SR &apos;{2}&apos;.
/// </summary>
public static string ACTION_VM_MOVING_TITLE {
get {
return ResourceManager.GetString("ACTION_VM_MOVING_TITLE", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Failed to finalize moving VM &apos;{0}&apos; to new storage. Please see logs for details..
/// </summary>

View File

@ -1177,10 +1177,7 @@
<value>Migrating VM '{0}'</value>
</data>
<data name="ACTION_VM_MOVING" xml:space="preserve">
<value>Moving VM '{0}' to new storage</value>
</data>
<data name="ACTION_VM_MOVING_TITLE" xml:space="preserve">
<value>Moving VM '{0}' to '{1}' on SR '{2}'</value>
<value>Moving VM '{0}' from Host '{1}' to Host '{2}'</value>
</data>
<data name="ACTION_VM_MOVING_VDI_DESTROY_FAILURE" xml:space="preserve">
<value>Failed to finalize moving VM '{0}' to new storage. Please see logs for details.</value>