/// <summary> /// Configure an IP address, management purpose, and set the disallow_unplug flag on the given existing_pif. /// </summary> /// <param name="new_pif">The source of the new IP details</param> /// <param name="existing_pif">The PIF to configure</param> internal static void BringUp(AsyncAction action, PIF new_pif, string new_ip, PIF existing_pif, int hi) { bool primary = string.IsNullOrEmpty(new_pif.GetManagementPurpose()); int lo = action.PercentComplete; int inc = (hi - lo) / (primary ? 2 : 3); log.DebugFormat("Bringing PIF {0} {1} up as {2}/{3}, {4}, {5}...", existing_pif.Name(), existing_pif.uuid, new_ip, new_pif.netmask, new_pif.gateway, new_pif.DNS); action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_BRINGING_UP, existing_pif.Name()); PIF p = (PIF)existing_pif.Clone(); p.disallow_unplug = !primary; p.SetManagementPurpose(new_pif.GetManagementPurpose()); p.SaveChanges(action.Session); action.PercentComplete = lo + inc; ReconfigureIP(action, new_pif, existing_pif, new_ip, action.PercentComplete + inc); if (!primary) { Plug(action, existing_pif, hi); } action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_BRINGING_UP_DONE, existing_pif.Name()); log.DebugFormat("Brought PIF {0} {1} up.", existing_pif.Name(), existing_pif.uuid); }
/// <summary> /// Clear the disallow_unplug and ManagementPurpose on the given NIC. /// </summary> private static void Depurpose(AsyncAction action, PIF pif, int hi) { log.DebugFormat("Depurposing PIF {0} {1}...", pif.Name(), pif.uuid); action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_DEPURPOSING, pif.Name()); PIF p = (PIF)pif.Clone(); p.disallow_unplug = false; p.SetManagementPurpose(null); p.SaveChanges(action.Session); action.PercentComplete = hi; log.DebugFormat("Depurposed PIF {0} {1}.", pif.Name(), pif.uuid); action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_DEPURPOSED, pif.Name()); }
/// <summary> /// Switch the host's management interface from its current setting over to the given PIF. /// </summary> private static void ReconfigureManagement_(AsyncAction action, PIF pif, int hi) { log.DebugFormat("Switching to PIF {0} {1} for management...", pif.Name(), pif.uuid); action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_MANAGEMENT_RECONFIGURING, pif.Name()); int mid = (hi + action.PercentComplete) / 2; PIF p = (PIF)pif.Clone(); p.disallow_unplug = false; p.SetManagementPurpose(null); p.SaveChanges(action.Session); action.PercentComplete = mid; action.RelatedTask = XenAPI.Host.async_management_reconfigure(action.Session, pif.opaque_ref); action.PollToCompletion(mid, hi); log.DebugFormat("Switched to PIF {0} {1} for management.", pif.Name(), pif.uuid); action.Description = string.Format(Messages.ACTION_CHANGE_NETWORKING_MANAGEMENT_RECONFIGURED, pif.Name()); }
/// <summary> /// If the "from" PIF is a secondary management interface, /// move the management interface name to the "to" PIF instead. /// </summary> internal static void MoveManagementInterfaceName(AsyncAction action, PIF from, PIF to) { string managementPurpose = from.GetManagementPurpose(); if (string.IsNullOrEmpty(managementPurpose)) { return; } log.DebugFormat("Moving management interface name from {0} to {1}...", from.uuid, to.uuid); PIF to_clone = (PIF)to.Clone(); to_clone.SetManagementPurpose(from.GetManagementPurpose()); to_clone.SaveChanges(action.Session); PIF from_clone = (PIF)from.Clone(); from_clone.SetManagementPurpose(null); from_clone.SaveChanges(action.Session); log.DebugFormat("Moving management interface name from {0} to {1} done.", from.uuid, to.uuid); }