Skip to content

Commit

Permalink
Merge pull request xenserver#2854 from danilo-delbusso/CA-339273
Browse files Browse the repository at this point in the history
CA-339273: Add source server/pool info to descriptions of actions that move/copy/import resources
  • Loading branch information
kc284 committed Dec 2, 2021
2 parents 2af5758 + e9fa567 commit cace303
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 128 deletions.
5 changes: 4 additions & 1 deletion XenAdmin/Core/ActionBaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ internal static Image GetImage(this ActionBase action)
internal static string GetDetails(this ActionBase action)
{
var sb = new StringBuilder(GetTitle(action));
sb.Append("\n").Append(GetDescription(action));

var description = GetDescription(action);
if (!string.IsNullOrEmpty(description))
sb.Append("\n").Append(description);

string timeString = GetTimeElapsed(action);
if (!string.IsNullOrEmpty(timeString))
Expand Down
2 changes: 1 addition & 1 deletion XenAdmin/Dialogs/VMDialogs/MoveVMDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void srPicker1_DoubleClickOnRow(object sender, EventArgs e)

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();
}
Expand Down
4 changes: 1 addition & 3 deletions XenModel/Actions/VDI/MigrateVirtualDiskAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,14 @@ public class MigrateVirtualDiskAction : PureAsyncAction
private readonly VDI vdi;

public MigrateVirtualDiskAction(IXenConnection connection, VDI vdi, SR sr)
: base(connection, string.Format(Messages.ACTION_MOVING_VDI_TO_SR, Helpers.GetName(vdi), Helpers.GetName(sr)))
: base(connection, string.Format(Messages.ACTION_MOVING_VDI_TO_SR, Helpers.GetName(vdi), Helpers.GetName(connection.Resolve(vdi.SR)), Helpers.GetName(sr)))
{
Description = Messages.ACTION_PREPARING;
this.vdi = vdi;
SR = sr;
}

protected override void Run()
{
Description = string.Format(Messages.ACTION_MOVING_VDI, Helpers.GetName(vdi));
RelatedTask = VDI.async_pool_migrate(Session, vdi.opaque_ref, SR.opaque_ref, new Dictionary<string, string>());
PollToCompletion();
Description = Messages.MOVED;
Expand Down
5 changes: 2 additions & 3 deletions XenModel/Actions/VDI/MoveVirtualDiskAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public class MoveVirtualDiskAction : AsyncAction

private VDI vdi;

public MoveVirtualDiskAction(IXenConnection connection, XenAPI.VDI vdi, SR sr)
: base(connection, string.Format(Messages.ACTION_MOVING_VDI_TO_SR, Helpers.GetName(vdi), Helpers.GetName(sr)))
public MoveVirtualDiskAction(IXenConnection connection, VDI vdi, SR sr)
: base(connection, string.Format(Messages.ACTION_MOVING_VDI_TO_SR, Helpers.GetName(vdi), Helpers.GetName(connection.Resolve(vdi.SR)), Helpers.GetName(sr)))
{
this.vdi = vdi;
SR = sr;
Expand All @@ -61,7 +61,6 @@ public MoveVirtualDiskAction(IXenConnection connection, XenAPI.VDI vdi, SR sr)

protected override void Run()
{
Description = string.Format(Messages.ACTION_MOVING_VDI, Helpers.GetName(vdi));
PercentComplete = 10;
log.DebugFormat("Moving VDI '{0}'", Helpers.GetName(vdi));
RelatedTask = VDI.async_copy(Session, vdi.opaque_ref, SR.opaque_ref);
Expand Down
11 changes: 7 additions & 4 deletions XenModel/Actions/VM/ImportVmAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ public class ImportVmAction : AsyncAction

public ImportVmAction(IXenConnection connection, Host affinity, string filename, SR sr,
Action<VM, bool> warningDelegate, Action<VMStartAbstractAction, Failure> failureDiagnosisDelegate)
: base(connection, string.Format(Messages.IMPORTVM_TITLE, filename, Helpers.GetName(connection)), Messages.IMPORTVM_PREP)
{
Pool = Helpers.GetPoolOfOne(connection);
: base(connection, "")
{
Description = Messages.IMPORTVM_PREP;
Pool = Helpers.GetPoolOfOne(connection);
m_affinity = affinity;
Host = affinity ?? connection.Resolve(Pool.master);
SR = sr;
Expand All @@ -94,7 +95,9 @@ public class ImportVmAction : AsyncAction
ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList);

#endregion
}

Title = string.Format(Messages.IMPORTVM_TITLE, filename, Host.NameWithLocation());
}

protected override void Run()
{
Expand Down
33 changes: 15 additions & 18 deletions XenModel/Actions/VM/VMCloneAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@
* SUCH DAMAGE.
*/

using XenAdmin.Core;
using XenAPI;


namespace XenAdmin.Actions.VMActions
{
public class VMCloneAction : AsyncAction
{
private readonly string _cloneName;
private readonly string _cloneDescription;

protected string _cloneName;
protected string _cloneDescription;
public VMCloneAction(VM vm, string name, string description)
: base(vm.Connection, string.Format(Messages.CREATEVM_CLONE, name, vm.Name()))
: base(vm.Connection, string.Format(Messages.CREATEVM_CLONE, name, vm.NameWithLocation()))
{
this.Description = Messages.ACTION_PREPARING;
this.VM = vm;
this.Host = vm.Home();
this.Pool = Core.Helpers.GetPool(vm.Connection);
VM = vm;
Host = vm.Home();
Pool = Helpers.GetPool(vm.Connection);
if (vm.is_a_template)
this.Template = vm;
Template = vm;
_cloneName = name;
_cloneDescription = description;
ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList);
Expand All @@ -58,17 +58,14 @@ public VMCloneAction(VM vm, string name, string description)

protected override void Run()
{
this.Description = Messages.ACTION_TEMPLATE_CLONING;
RelatedTask = XenAPI.VM.async_clone(Session, VM.opaque_ref, _cloneName);
RelatedTask = VM.async_clone(Session, VM.opaque_ref, _cloneName);
PollToCompletion();
{
VM created = Connection.WaitForCache(new XenRef<VM>(Result));
XenAPI.VM.set_name_description(Session, created.opaque_ref, _cloneDescription);
Result = created.opaque_ref;
}
this.Description = Messages.ACTION_TEMPLATE_CLONED;
}
}

VM created = Connection.WaitForCache(new XenRef<VM>(Result));
VM.set_name_description(Session, created.opaque_ref, _cloneDescription);
Result = created.opaque_ref;

Description = Messages.ACTION_TEMPLATE_CLONED;
}
}
}
26 changes: 10 additions & 16 deletions XenModel/Actions/VM/VMCopyAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,17 @@ public class VMCopyAction : AsyncAction
private string _namedescription;

public VMCopyAction(VM vm, Host host, SR sr, string nameLabel, string description)
: base(vm.Connection, string.Format(Messages.ACTION_VM_COPYING_TITLE, vm.Name(), nameLabel, sr.NameWithoutHost()))
: base(vm.Connection, string.Format(Messages.ACTION_VM_COPYING_TITLE, vm.NameWithLocation(), nameLabel, sr.NameWithLocation()))
{
this.Description = Messages.ACTION_PREPARING;
this.VM = vm;
this.Host = host;
this.Pool = Core.Helpers.GetPool(vm.Connection);
this.SR = sr;
VM = vm;
Host = host;
Pool = Core.Helpers.GetPool(vm.Connection);
SR = sr;
_nameLabel = nameLabel;
if (vm.is_a_template)
this.Template = vm;
Template = vm;
_namedescription = description;
SetRBACPermissions();

}

private void SetRBACPermissions()
Expand All @@ -67,25 +65,21 @@ private void SetRBACPermissions()

protected override void Run()
{

this.Description = Messages.ACTION_VM_COPYING;
RelatedTask = XenAPI.VM.async_copy(Session, VM.opaque_ref, _nameLabel, this.SR.opaque_ref);
RelatedTask = VM.async_copy(Session, VM.opaque_ref, _nameLabel, SR.opaque_ref);
try
{
PollToCompletion();
}
catch (CancelledException)
{
this.Description = string.Format(Messages.COPY_TO_SHARED_CANCELLED, VM.Name());
Description = string.Format(Messages.COPY_TO_SHARED_CANCELLED, VM.NameWithLocation());
throw;
}
{
VM created = Connection.WaitForCache(new XenRef<VM>(Result));
XenAPI.VM.set_name_description(Session, created.opaque_ref, _namedescription);
VM.set_name_description(Session, created.opaque_ref, _namedescription);
}
this.Description = Messages.ACTION_VM_COPIED;


Description = Messages.ACTION_VM_COPIED;
}
}
}
15 changes: 8 additions & 7 deletions XenModel/Actions/VM/VMCrossPoolMigrateAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public VMCrossPoolMigrateAction(VM vm, Host destinationHost, XenAPI.Network tran
: base(vm.Connection, GetTitle(vm, destinationHost, copy))
{
Session = vm.Connection.Session;
Description = Messages.ACTION_PREPARING;
VM = vm;
Host = destinationHost;
Pool = Helpers.GetPool(vm.Connection);
Expand All @@ -80,18 +79,20 @@ public static RbacMethodList StaticRBACDependencies
public static string GetTitle(VM vm, Host toHost, bool copy)
{
if (copy)
return string.Format(Messages.ACTION_VM_CROSS_POOL_COPY_TITLE, vm.Name(), toHost.Name());
return string.Format(Messages.ACTION_VM_CROSS_POOL_COPY_TITLE,
vm.NameWithLocation(),
Helpers.GetPool(vm.Connection)?.Name() ?? vm.Connection.Name,
toHost.NameWithLocation());

Host residentOn = vm.Connection.Resolve(vm.resident_on);

return residentOn == null
? string.Format(Messages.ACTION_VM_MIGRATING_NON_RESIDENT, vm.Name(), toHost.Name())
: string.Format(Messages.ACTION_VM_MIGRATING_RESIDENT, vm.Name(), Helpers.GetName(residentOn), toHost.Name());
? string.Format(Messages.ACTION_VM_MIGRATING_NON_RESIDENT, vm.NameWithLocation(), toHost.NameWithLocation())
: string.Format(Messages.ACTION_VM_MIGRATING_RESIDENT, vm.Name(), residentOn.NameWithLocation(), toHost.NameWithLocation());
}

protected override void Run()
{
Description = copy ? Messages.ACTION_VM_COPYING: Messages.ACTION_VM_MIGRATING;
try
{
PercentComplete = 0;
Expand All @@ -114,7 +115,7 @@ protected override void Run()
Description = string.Format(copy
? Messages.ACTION_VM_CROSS_POOL_COPY_CANCELLED
: Messages.ACTION_VM_MIGRATE_CANCELLED,
VM.Name());
VM.NameWithLocation());
throw;
}
catch (Failure ex)
Expand Down
35 changes: 14 additions & 21 deletions XenModel/Actions/VM/VMMigrateAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,45 +40,38 @@ public class VMMigrateAction : PureAsyncAction
{

public VMMigrateAction(VM vm, Host destinationHost)
: base(vm.Connection, GetTitle(vm, destinationHost))
: base(vm.Connection, "")
{
this.Description = Messages.ACTION_PREPARING;
this.VM = vm;
this.Host = destinationHost;
this.Pool = Core.Helpers.GetPool(vm.Connection);
}
VM = vm;
Host = destinationHost;
Pool = Helpers.GetPool(vm.Connection);

private static string GetTitle(VM vm, Host toHost)
{
Host residentOn = vm.Connection.Resolve(vm.resident_on);

return residentOn == null
? string.Format(Messages.ACTION_VM_MIGRATING_NON_RESIDENT, vm.Name(), toHost.Name())
: string.Format(Messages.ACTION_VM_MIGRATING_RESIDENT, vm.Name(), Helpers.GetName(residentOn), toHost.Name());
var residentOn = vm.Connection.Resolve(vm.resident_on);

Title = residentOn == null
? string.Format(Messages.ACTION_VM_MIGRATING_NON_RESIDENT, vm.NameWithLocation(), Host.NameWithLocation())
: string.Format(Messages.ACTION_VM_MIGRATING_RESIDENT, vm.Name(), residentOn.NameWithLocation(), Host.NameWithLocation());
}

protected override void Run()
{
this.Description = Messages.ACTION_VM_MIGRATING;
RelatedTask = XenAPI.VM.async_live_migrate(Session, VM.opaque_ref, Host.opaque_ref);
RelatedTask = VM.async_live_migrate(Session, VM.opaque_ref, Host.opaque_ref);
try
{
PollToCompletion();
}
catch (Failure f)
{
if (f.ErrorDescription.Count >= 5 && f.ErrorDescription[0] == "VM_MIGRATE_FAILED"
&& f.ErrorDescription[4].Contains("VDI_MISSING"))
&& f.ErrorDescription[4].Contains("VDI_MISSING"))
{
throw new Exception(Messages.MIGRATE_EJECT_TOOLS_ON_UPGRADE);
}
else
{
throw;
}

throw;
}

this.Description = Messages.ACTION_VM_MIGRATED;
Description = Messages.ACTION_VM_MIGRATED;
}
}
}
46 changes: 25 additions & 21 deletions XenModel/Actions/VM/VMMoveAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,40 +45,44 @@ public class VMMoveAction : AsyncAction
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, "")
{
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();

PopulateApiMethodsToRoleCheck();

var sourceHost = vm.Home();
if (sourceHost != null && !sourceHost.Equals(host))
Title = string.Format(Messages.ACTION_VM_MOVING_HOST, vm.Name(), sourceHost, host.Name());
else if (storageMapping.Count == 1)
Title = string.Format(Messages.ACTION_VM_MOVING_SR, vm.Name(), storageMapping.Values.ElementAt(0).Name());
else
Title = string.Format(Messages.ACTION_VM_MOVING, vm.Name());
}

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
Expand All @@ -96,8 +100,6 @@ private void PopulateApiMethodsToRoleCheck()

protected override void Run()
{
Description = Messages.ACTION_PREPARING;

// move the progress bar above 0, it's more reassuring to see than a blank bar as we copy the first disk
PercentComplete += 10;
int halfstep = 90 / (VM.VBDs.Count * 2);
Expand Down Expand Up @@ -126,7 +128,7 @@ protected override void Run()
continue;

Description = string.Format(Messages.ACTION_MOVING_VDI_TO_SR,
Helpers.GetName(curVdi), Helpers.GetName(sr));
Helpers.GetName(curVdi), Helpers.GetName(Connection.Resolve(curVdi.SR)), Helpers.GetName(sr));

RelatedTask = VDI.async_copy(Session, oldVBD.VDI.opaque_ref, sr.opaque_ref);
PollToCompletion(PercentComplete, PercentComplete + halfstep);
Expand Down Expand Up @@ -160,11 +162,13 @@ protected override void Run()
PercentComplete += halfstep;
}

Description = string.Empty;

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;
}
Expand Down
Loading

0 comments on commit cace303

Please sign in to comment.