mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-25 06:16:37 +01:00
CA-339685: Corrected calculation of completion percentage and added checks for division by zero.
Also, some simplifications and removal of unused variables and fields. Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
parent
64aa4e730b
commit
4f4217a2b1
@ -31,12 +31,12 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Net;
|
||||||
using XenAPI;
|
using XenAPI;
|
||||||
using XenAdmin.Core;
|
using XenAdmin.Core;
|
||||||
|
|
||||||
using XenAdmin.Network;
|
using XenAdmin.Network;
|
||||||
|
|
||||||
|
|
||||||
namespace XenAdmin.Actions
|
namespace XenAdmin.Actions
|
||||||
{
|
{
|
||||||
public class DestroyBondAction : AsyncAction
|
public class DestroyBondAction : AsyncAction
|
||||||
@ -53,11 +53,6 @@ namespace XenAdmin.Actions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly List<PIF> Masters = new List<PIF>();
|
private readonly List<PIF> Masters = new List<PIF>();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Masters that held secondary management interfaces. These are discovered when bringing masters down.
|
|
||||||
/// </summary>
|
|
||||||
private readonly List<PIF> Secondaries = new List<PIF>();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All slaves under each bond in Bonds. These will be plugged at the end, in order to
|
/// All slaves under each bond in Bonds. These will be plugged at the end, in order to
|
||||||
/// get metrics like the carrier flag, if they haven't already been brought up as a
|
/// get metrics like the carrier flag, if they haven't already been brought up as a
|
||||||
@ -70,11 +65,6 @@ namespace XenAdmin.Actions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly Dictionary<PIF, PIF> FirstSlaves = new Dictionary<PIF, PIF>();
|
private readonly Dictionary<PIF, PIF> FirstSlaves = new Dictionary<PIF, PIF>();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A dictionary of copies of the equivalent entries in FirstSlaves, but with the IP details that we're carrying across.
|
|
||||||
/// </summary>
|
|
||||||
private readonly Dictionary<PIF, PIF> NewFirstSlaves = new Dictionary<PIF, PIF>();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The network that we're either going to destroy or rename.
|
/// The network that we're either going to destroy or rename.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -152,39 +142,51 @@ namespace XenAdmin.Actions
|
|||||||
|
|
||||||
protected override void Run()
|
protected override void Run()
|
||||||
{
|
{
|
||||||
|
PercentComplete = 0;
|
||||||
Connection.ExpectDisruption = true;
|
Connection.ExpectDisruption = true;
|
||||||
List<VIF> unplugged_vifs = new List<VIF>();
|
|
||||||
string old_network_name = Network == null ? "" : Network.Name();
|
|
||||||
Exception e = null;
|
|
||||||
|
|
||||||
BestEffort(ref e, ReconfigureManagementInterfaces);
|
int incr = Masters.Count > 0 ? 50 / Masters.Count : 0;
|
||||||
|
|
||||||
if (e != null)
|
try
|
||||||
throw e;
|
{
|
||||||
|
foreach (PIF master in Masters)
|
||||||
|
{
|
||||||
|
NetworkingActionHelpers.MoveManagementInterfaceName(this, master, FirstSlaves[master]);
|
||||||
|
PercentComplete += incr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (WebException we)
|
||||||
|
{
|
||||||
|
//ignore keep-alive failure since disruption is expected
|
||||||
|
if (we.Status != WebExceptionStatus.KeepAliveFailure)
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
PercentComplete = 50;
|
PercentComplete = 50;
|
||||||
|
|
||||||
int inc = 40 / Bonds.Count;
|
Exception e = null;
|
||||||
|
|
||||||
|
int inc = Bonds.Count > 0 ? 40 / Bonds.Count : 0;
|
||||||
|
|
||||||
int lo = PercentComplete;
|
|
||||||
foreach (Bond bond in Bonds)
|
foreach (Bond bond in Bonds)
|
||||||
{
|
{
|
||||||
Bond bond1 = bond;
|
Bond bond1 = bond;
|
||||||
int lo1 = lo;
|
|
||||||
BestEffort(ref e, delegate() { RelatedTask = Bond.async_destroy(Session, bond1.opaque_ref);});
|
BestEffort(ref e, delegate() { RelatedTask = Bond.async_destroy(Session, bond1.opaque_ref);});
|
||||||
PollToCompletion(lo1, lo1 + inc);
|
PollToCompletion(PercentComplete, PercentComplete + inc);
|
||||||
|
|
||||||
lo += inc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PercentComplete = 90;
|
||||||
|
|
||||||
if (Network != null)
|
if (Network != null)
|
||||||
{
|
{
|
||||||
|
string oldNetworkName = Network.Name();
|
||||||
|
|
||||||
// Destroy the old network
|
// Destroy the old network
|
||||||
log.DebugFormat("Destroying network {0} ({1})...", old_network_name, Network.uuid);
|
log.DebugFormat("Destroying network {0} ({1})...", oldNetworkName, Network.uuid);
|
||||||
BestEffort(ref e, delegate()
|
BestEffort(ref e, delegate()
|
||||||
{
|
{
|
||||||
XenAPI.Network.destroy(Session, Network.opaque_ref);
|
XenAPI.Network.destroy(Session, Network.opaque_ref);
|
||||||
log.DebugFormat("Network {0} ({1}) destroyed.", old_network_name, Network.uuid);
|
log.DebugFormat("Network {0} ({1}) destroyed.", oldNetworkName, Network.uuid);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,18 +196,6 @@ namespace XenAdmin.Actions
|
|||||||
Description = string.Format(Messages.ACTION_DESTROY_BOND_DONE, Name);
|
Description = string.Format(Messages.ACTION_DESTROY_BOND_DONE, Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReconfigureManagementInterfaces()
|
|
||||||
{
|
|
||||||
int progress = 0;
|
|
||||||
int inc = 50 / Masters.Count;
|
|
||||||
|
|
||||||
foreach (PIF master in Masters)
|
|
||||||
{
|
|
||||||
progress += inc;
|
|
||||||
NetworkingActionHelpers.MoveManagementInterfaceName(this, master, FirstSlaves[master]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UnlockAll()
|
private void UnlockAll()
|
||||||
{
|
{
|
||||||
foreach (Bond bond in Bonds)
|
foreach (Bond bond in Bonds)
|
||||||
|
Loading…
Reference in New Issue
Block a user