private void ReconfigureManagementInterfaces(List <PIF> slaves, PIF new_master, int hi) { int lo = PercentComplete; int inc = (hi - lo) / slaves.Count; foreach (PIF pif in slaves) { lo += inc; // In Boston and later, the only thing we need to do is move the ManagementPurpose // (= management interface name) to the bond (see PR-1006/CP-2059). if (bostonOrGreater) { NetworkingActionHelpers.MoveManagementInterfaceName(this, pif, new_master); } else if (pif.management) { log.DebugFormat("Moving primary management interface to {0}...", pif.uuid); NetworkingActionHelpers.ReconfigureSinglePrimaryManagement(this, pif, new_master, lo); log.DebugFormat("Moving primary management interface to {0} done.", pif.uuid); } else if (pif.IsSecondaryManagementInterface(true)) { log.DebugFormat("Moving secondary management interface to {0}...", pif.uuid); ReconfigureSecondaryManagement(pif, new_master, lo); log.DebugFormat("Moving secondary management interface to {0} done.", pif.uuid); } } }
private void DeconfigureSecondaryManagement(PIF master, int hi) { System.Diagnostics.Trace.Assert(!bostonOrGreater); NewFirstSlaves[master] = NetworkingHelper.CopyIPConfig(master, FirstSlaves[master]); NetworkingActionHelpers.BringDown(this, master, hi); Secondaries.Add(master); }
/// <summary> /// Nothrow guarantee. /// </summary> /// <param name="slaves"></param> /// <param name="master"></param> private void RevertManagementInterfaces(NewBond new_bond) { List <PIF> slaves = new_bond.slaves; PIF master = new_bond.master; Bond bond = new_bond.bond; PIF slave = Connection.Resolve(bond.primary_slave); if (slave == null) { if (slaves.Count == 0) { return; } slave = slaves[0]; } try { NetworkingActionHelpers.MoveManagementInterfaceName(this, master, slave); } catch (Exception exn) { log.Warn(exn, exn); } }
protected override void Run() { PercentComplete = 0; Connection.ExpectDisruption = true; int incr = Masters.Count > 0 ? 50 / Masters.Count : 0; try { 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; Exception e = null; int inc = Bonds.Count > 0 ? 40 / Bonds.Count : 0; foreach (Bond bond in Bonds) { Bond bond1 = bond; BestEffort(ref e, delegate() { RelatedTask = Bond.async_destroy(Session, bond1.opaque_ref); }); PollToCompletion(PercentComplete, PercentComplete + inc); } PercentComplete = 90; if (Network != null) { string oldNetworkName = Network.Name(); // Destroy the old network log.DebugFormat("Destroying network {0} ({1})...", oldNetworkName, Network.uuid); BestEffort(ref e, delegate() { XenAPI.Network.destroy(Session, Network.opaque_ref); log.DebugFormat("Network {0} ({1}) destroyed.", oldNetworkName, Network.uuid); }); } if (e != null) { throw e; } 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 ReconfigureManagementInterfaces(List <PIF> slaves, PIF new_master, int hi) { int lo = PercentComplete; int inc = (hi - lo) / slaves.Count; foreach (PIF pif in slaves) { lo += inc; NetworkingActionHelpers.MoveManagementInterfaceName(this, pif, new_master); } }
private void ReconfigureSecondaryManagement(PIF src, PIF dest, int hi) { System.Diagnostics.Trace.Assert(!bostonOrGreater); int mid = (PercentComplete + hi) / 2; PIF new_dest = NetworkingHelper.CopyIPConfig(src, dest); NetworkingActionHelpers.BringDown(this, src, mid); NetworkingActionHelpers.BringUp(this, new_dest, dest, hi); }
private void PoolReconfigureManagement(int hi) { System.Diagnostics.Trace.Assert(downManagement != null); if (newManagement == null) { return; } NetworkingActionHelpers.PoolReconfigureManagement(this, Pool, newManagement, downManagement, hi); }
private void BringUp(PIF new_pif, PIF existing_pif, int hi) { string ip = existing_pif.IP; if (new_pif.ip_configuration_mode == ip_configuration_mode.Static) { ip = Pool == null ? new_pif.IP : GetIPInRange(new_pif.IP, existing_pif); } NetworkingActionHelpers.BringUp(this, new_pif, ip, existing_pif, hi); }
private void Reconfigure(PIF pif, bool up, bool this_host, int hi) { NetworkingActionHelpers.ForSomeHosts(this, pif, this_host, true, hi, delegate(AsyncAction a, PIF p, int h) { if (up) { BringUp(pif, p, h); } else { NetworkingActionHelpers.BringDown(a, p, h); } }); }
private void Reconfigure(PIF pif, bool up, bool this_host, int hi) { NetworkingActionHelpers.ForSomeHosts(this, pif, this_host, true, hi, delegate(AsyncAction a, PIF p, int h) { List <PBD> gfs2Pbds; DisableClustering(p, out gfs2Pbds); if (up) { BringUp(pif, p, h); } else { NetworkingActionHelpers.BringDown(a, p, h); } EnableClustering(p, gfs2Pbds); }); }
protected override void Run() { PercentComplete = 0; Connection.ExpectDisruption = true; int incr = Masters.Count > 0 ? 50 / Masters.Count : 0; try { 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; var caughtExceptions = new List <Exception>(); int inc = Bonds.Count > 0 ? 40 / Bonds.Count : 0; foreach (Bond bond in Bonds) { Bond bond1 = bond; try { RelatedTask = Bond.async_destroy(Session, bond1.opaque_ref); } catch (Exception exn) { if (Connection != null && Connection.ExpectDisruption && exn is WebException webEx && webEx.Status == WebExceptionStatus.KeepAliveFailure) { //ignore }
private void ReconfigureManagement(bool this_host, int hi) { System.Diagnostics.Trace.Assert(downManagement != null); System.Diagnostics.Trace.Assert(newManagement != null); bool clearDownManagementIP = true; foreach (PIF p in newPIFs) { if (p.uuid == downManagement.uuid) { clearDownManagementIP = false; break; } } NetworkingActionHelpers.ReconfigureManagement(this, downManagement, newManagement, this_host, true, hi, clearDownManagementIP); }
/// <summary> /// Nothrow guarantee. /// </summary> /// <param name="slaves"></param> /// <param name="master"></param> private void RevertManagementInterfaces(NewBond new_bond) { List <PIF> slaves = new_bond.slaves; PIF master = new_bond.master; Bond bond = new_bond.bond; PIF slave = Connection.Resolve(bond.primary_slave); if (slave == null) { if (slaves.Count == 0) { return; } slave = slaves[0]; } try { if (bostonOrGreater) { NetworkingActionHelpers.MoveManagementInterfaceName(this, master, slave); } else if (master.management) { log.DebugFormat("Reverting primary management interface change for {0} as part of cleanup...", master.uuid); NetworkingActionHelpers.ReconfigurePrimaryManagement(this, master, slave, PercentComplete); log.DebugFormat("Reverting primary management interface change for {0} as part of cleanup done.", master.uuid); } else if (master.IsSecondaryManagementInterface(true)) { log.DebugFormat("Reverting secondary management interface change for {0} as part of cleanup...", master.uuid); ReconfigureSecondaryManagement(master, slave, PercentComplete); log.DebugFormat("Reverting secondary management interface change for {0} as part of cleanup done.", master.uuid); } } catch (Exception exn) { log.Warn(exn, exn); } }
private void ReconfigureManagementInterfaces() { int progress = 0; int inc = 50 / Masters.Count; foreach (PIF master in Masters) { progress += inc; if (bostonOrGreater) { NetworkingActionHelpers.MoveManagementInterfaceName(this, master, FirstSlaves[master]); } else if (master.management) { ReconfigurePrimaryManagement(master, progress); } else if (master.IsSecondaryManagementInterface(true)) { DeconfigureSecondaryManagement(master, progress); } } }
private void ReconfigurePrimaryManagement(PIF master, int hi) { System.Diagnostics.Trace.Assert(!bostonOrGreater); NetworkingActionHelpers.ReconfigureSinglePrimaryManagement(this, master, FirstSlaves[master], hi); }
protected override void Run() { // the network lock and the connection.expectDisruption will be cleared in clean() new_bonds = new List <NewBond>(); network = null; Connection.ExpectDisruption = true; int inc = 100 / (Connection.Cache.HostCount * 3 + 1); string network_ref = CreateNetwork(0, inc); try { network = Connection.WaitForCache(new XenRef <XenAPI.Network>(network_ref)); network.Locked = true; XenAPI.Network.remove_from_other_config(Session, network_ref, XenAPI.Network.CREATE_IN_PROGRESS); int lo = inc; foreach (Host host in GetHostsMasterLast()) { List <PIF> pifs = PIFs[host].FindAll(x => x.physical).ToList(); List <XenRef <PIF> > pif_refs = new List <XenRef <PIF> >(); foreach (PIF pif in pifs) { pif_refs.Add(new XenRef <PIF>(pif.opaque_ref)); } log.DebugFormat("Creating bond on {0} with {1} PIFs...", Helpers.GetName(host), pifs.Count); Dictionary <string, string> bondProperties = new Dictionary <string, string>(); if (bondMode == bond_mode.lacp) { bondProperties.Add("hashing_algorithm", Bond.HashingAlgoritmToString(hashingAlgoritm)); } RelatedTask = tampaOrGreater ? Bond.async_create(Session, network_ref, pif_refs, "", bondMode, bondProperties) : bostonOrGreater? Bond.async_create(Session, network_ref, pif_refs, "", bondMode) : Bond.async_create(Session, network_ref, pif_refs, ""); PollToCompletion(lo, lo + inc); lo += inc; log.DebugFormat("Creating bond on {0} done: bond is {1}.", Helpers.GetName(host), Result); Bond new_bond = Connection.WaitForCache(new XenRef <Bond>(Result)); if (new_bond == null) { throw new Failure(Failure.INTERNAL_ERROR, "Bond didn't appear in our cache!"); } PIF new_master = Connection.Resolve(new_bond.master); if (new_master == null) { throw new Failure(Failure.INTERNAL_ERROR, "Bond master didn't appear in our cache!"); } new_bonds.Add(new NewBond(new_bond, new_master, pifs)); new_bond.Locked = true; new_master.Locked = true; } foreach (NewBond new_bond in new_bonds) { lo += inc; ReconfigureManagementInterfaces(new_bond.slaves, new_bond.master, lo); } foreach (NewBond new_bond in new_bonds) { lo += inc; if (!bostonOrGreater) { NetworkingActionHelpers.Plug(this, new_bond.master, lo); } } } catch (Exception) { foreach (NewBond new_bond in new_bonds) { RevertManagementInterfaces(new_bond); DestroyBond(new_bond.bond); } DestroyNetwork(network_ref); throw; } Description = string.Format(Messages.ACTION_CREATE_BOND_DONE, name_label); }
protected override void Run() { Connection.ExpectDisruption = true; List <VIF> unplugged_vifs = new List <VIF>(); string old_network_name = Network == null ? "" : Network.Name; Exception e = null; if (!bostonOrGreater) { if (Network != null && NewNetworkName != null) { // Unplug all active VIFs, because we can't fiddle with the PIFs on the network while the // VIFs are active (xapi won't let us). foreach (VIF vif in Connection.ResolveAll(Network.VIFs)) { if (vif.currently_attached) { log.DebugFormat("Unplugging VIF {0} from network {1}...", vif.uuid, old_network_name); VIF.unplug(Session, vif.opaque_ref); unplugged_vifs.Add(vif); log.DebugFormat("VIF {0} unplugged from network {1}.", vif.uuid, old_network_name); } } } } BestEffort(ref e, ReconfigureManagementInterfaces); if (e != null) { throw e; } PercentComplete = 50; int inc = 40 / (Bonds.Count + Masters.Count + Slaves.Count); int lo = PercentComplete; foreach (Bond bond in Bonds) { Bond bond1 = bond; int lo1 = lo; BestEffort(ref e, delegate() { RelatedTask = Bond.async_destroy(Session, bond1.opaque_ref); }); PollToCompletion(lo1, lo1 + inc); lo += inc; } foreach (PIF master in Secondaries) { if (!bostonOrGreater) { ReconfigureSecondaryManagement(master, PercentComplete + inc); } PercentComplete += inc; } if (!bostonOrGreater) { foreach (PIF pif in Slaves) { NetworkingActionHelpers.Plug(this, pif, PercentComplete + inc); } } if (Network != null) { if (NewNetworkName == null) { // We can delete the whole network. log.DebugFormat("Destroying network {0} ({1})...", old_network_name, Network.uuid); BestEffort(ref e, delegate() { XenAPI.Network.destroy(Session, Network.opaque_ref); log.DebugFormat("Network {0} ({1}) destroyed.", old_network_name, Network.uuid); }); } else { // Rename the network, so that the VIFs still have somewhere to live. log.DebugFormat("Renaming network {0} ({1}) to {2}...", old_network_name, Network.uuid, NewNetworkName); XenAPI.Network n = (XenAPI.Network)Network.Clone(); n.name_label = NewNetworkName; BestEffort(ref e, delegate() { n.SaveChanges(Session); log.DebugFormat("Renaming network {0} ({1}) done.", NewNetworkName, n.uuid); }); // Replug all the VIFs that we unplugged before. if (!bostonOrGreater) { foreach (VIF vif in unplugged_vifs) { log.DebugFormat("Replugging VIF {0} into network {1}...", vif.opaque_ref, NewNetworkName); BestEffort(ref e, delegate() { VIF.plug(Session, vif.opaque_ref); log.DebugFormat("Replugging VIF {0} into network {1} done.", vif.opaque_ref, NewNetworkName); }); } } } } if (e != null) { throw e; } Description = string.Format(Messages.ACTION_DESTROY_BOND_DONE, Name); }
private void ReconfigureSecondaryManagement(PIF master, int hi) { System.Diagnostics.Trace.Assert(!bostonOrGreater); NetworkingActionHelpers.BringUp(this, NewFirstSlaves[master], FirstSlaves[master], hi); }