Corrections as per code review.

Signed-off-by: Konstantina Chremmou <Konstantina.Chremmou@cloud.com>
This commit is contained in:
Konstantina Chremmou 2023-01-26 00:15:57 +00:00
parent d46722c6eb
commit 34ca86fed7
8 changed files with 64 additions and 35 deletions

View File

@ -38,7 +38,6 @@ namespace XenAdmin.Actions
public DestroyPoolAction(Pool pool)
: base(pool.Connection, string.Format(Messages.DESTROYING_POOL, pool.Name()))
{
System.Diagnostics.Trace.Assert(pool != null);
Pool = pool;
Description = Messages.WAITING;

View File

@ -57,10 +57,15 @@ namespace XenAdmin.Actions
this.heartbeatSRs = heartbeatSRs.ToArray();
this.failuresToTolerate = failuresToTolerate;
if (startupOptions != null)
{
ApiMethodsToRoleCheck.AddRange(
"VM.set_ha_restart_priority",
"VM.set_order",
"VM.set_start_delay");
}
ApiMethodsToRoleCheck.AddRange(
"VM.set_ha_restart_priority",
"VM.set_order",
"VM.set_start_delay",
"pool.set_ha_host_failures_to_tolerate",
"pool.async_enable_ha");
}

View File

@ -41,10 +41,15 @@ namespace XenAdmin.Actions
: base(vusb.Connection, string.Format(Messages.ACTION_VUSB_DELETING, vusb.Name(), vm.Name()))
{
_vusb = vusb;
ApiMethodsToRoleCheck.AddRange(
"VUSB.get_allowed_operations",
"VUSB.async_unplug",
"VUSB.async_destroy");
if (_vusb != null && _vusb.currently_attached)
{
ApiMethodsToRoleCheck.AddRange(
"VBD.get_allowed_operations",
"VBD.async_unplug");
}
ApiMethodsToRoleCheck.Add("VUSB.async_destroy");
}
protected override void Run()

View File

@ -68,10 +68,14 @@ namespace XenAdmin.Actions
}
}
ApiMethodsToRoleCheck.AddRange(
"VBD.get_allowed_operations",
"VBD.async_unplug",
"VBD.async_destroy");
if (vbd != null && vbd.currently_attached)
{
ApiMethodsToRoleCheck.AddRange(
"VBD.get_allowed_operations",
"VBD.async_unplug");
}
ApiMethodsToRoleCheck.Add("VBD.async_destroy");
}
protected override void Run()

View File

@ -47,8 +47,14 @@ namespace XenAdmin.Actions
m_VCPUs_at_startup = VCPUs_at_startup;
if (VM.power_state == vm_power_state.Running)
ApiMethodsToRoleCheck.Add("VM.set_VCPUs_number_live");
ApiMethodsToRoleCheck.AddRange("VM.set_VCPUs_at_startup", "VM.set_VCPUs_max");
{
if (VM.VCPUs_at_startup <= m_VCPUs_at_startup)
ApiMethodsToRoleCheck.Add("VM.set_VCPUs_number_live");
}
else
{
ApiMethodsToRoleCheck.AddRange("VM.set_VCPUs_at_startup", "VM.set_VCPUs_max");
}
}
protected override void Run()

View File

@ -58,6 +58,8 @@ namespace XenAdmin.Actions.VMActions
vm.Name(),
vm.Home() == null ? Helpers.GetName(vm.Connection) : Helpers.GetName(vm.Home()));
Description = Messages.ACTION_VM_DESTROYING;
ApiMethodsToRoleCheck.AddRange("VM.destroy", "VDI.destroy");
if (_snapshotsToDelete.Any(s => s.power_state == vm_power_state.Suspended))
@ -67,7 +69,6 @@ namespace XenAdmin.Actions.VMActions
protected override void Run()
{
Description = Messages.ACTION_VM_DESTROYING;
DestroyVM(Session, VM, _disksToDelete, _snapshotsToDelete);
Description = Messages.ACTION_VM_DESTROYED;
}

View File

@ -29,35 +29,46 @@
* SUCH DAMAGE.
*/
using System.Collections.Generic;
using System.Linq;
using XenAdmin.Actions.VMActions;
using XenAPI;
namespace XenAdmin.Actions
{
public class VMSnapshotDeleteAction : AsyncAction
public class VMSnapshotDeleteAction : VMDestroyAction
{
private VM m_Snapshot;
public VMSnapshotDeleteAction(VM snapshot)
: base(snapshot.Connection, string.Format(Messages.ACTION_VM_DELETE_SNAPSHOT_TITLE, snapshot.Name()))
: base(snapshot, GetDisksToDelete(snapshot), new List<VM>())
{
VM = Connection.Resolve(snapshot.snapshot_of);
m_Snapshot = snapshot;
// the value of VM should be the snapshot and not the parent VM;
// first, because it makes sense to set VM to the actual object
// handled by the action; second and more important, because Run()
// calls base.Run() which would result to deleting the parent VM;
// note that the VM setter has already code that set AppliesTo to
// the parent VM for snapshots
VM = snapshot;
if (m_Snapshot.power_state == vm_power_state.Suspended)
Title = string.Format(Messages.ACTION_VM_DELETE_SNAPSHOT_TITLE, VM.Name());
Description = string.Format(Messages.ACTION_VM_DELETE_SNAPSHOT_TITLE, VM.Name());
if (VM.power_state == vm_power_state.Suspended)
ApiMethodsToRoleCheck.Add("VM.hard_shutdown");
}
private static List<VBD> GetDisksToDelete(VM snapshot)
{
return snapshot.Connection.ResolveAll(snapshot.VBDs).FindAll(x => x.GetIsOwner()).ToList();
}
protected override void Run()
{
Description = string.Format(Messages.ACTION_VM_DELETE_SNAPSHOT_TITLE, m_Snapshot.Name());
if (m_Snapshot.power_state == vm_power_state.Suspended)
{
VM.hard_shutdown(Session, m_Snapshot.opaque_ref);
}
VMDestroyAction.DestroyVM(Session, m_Snapshot, true);
Description = string.Format(Messages.SNAPSHOT_DELETED, m_Snapshot.Name());
if (VM.power_state == vm_power_state.Suspended)
VM.hard_shutdown(Session, VM.opaque_ref);
base.Run();
Description = string.Format(Messages.SNAPSHOT_DELETED, VM.Name());
}
}
}

View File

@ -76,18 +76,16 @@ namespace XenAdmin.Actions
public class RemoveVMsFromPolicyAction : AsyncAction
{
private readonly List<XenRef<VM>> _selectedVMs;
private readonly VMSS _policy;
public RemoveVMsFromPolicyAction(VMSS policy, List<XenRef<VM>> selectedVMs)
: base(policy.Connection,
selectedVMs.Count == 1 ?
string.Format(Messages.REMOVE_VM_FROM_VMSS, policy.Connection.Resolve(selectedVMs[0]), policy.Name()) :
string.Format(Messages.REMOVE_VMS_FROM_VMSS, policy.Name()))
: base(policy.Connection, "")
{
_policy = policy;
_selectedVMs = selectedVMs;
Pool = Helpers.GetPool(policy.Connection);
ApiMethodsToRoleCheck.Add("VM.set_snapshot_schedule");
Title = selectedVMs.Count == 1
? string.Format(Messages.REMOVE_VM_FROM_VMSS, policy.Connection.Resolve(selectedVMs[0]), policy.Name())
: string.Format(Messages.REMOVE_VMS_FROM_VMSS, policy.Name());
}
protected override void Run()