protected override void Run() { Description = Messages.ACTION_VIF_DELETING; if (VM.power_state == vm_power_state.Running && VIF.get_allowed_operations(Session, _vif.opaque_ref).Contains(vif_operations.unplug)) { try { VIF.unplug(Session, _vif.opaque_ref); } catch (Failure exn) { // Ignore the failure if it's already detached -- throw everything else. if (exn.ErrorDescription[0] != Failure.DEVICE_ALREADY_DETACHED) { throw; } } } VIF.destroy(Session, _vif.opaque_ref); Description = Messages.ACTION_VIF_DELETED; }
private void Unplug(VIF v) { if (!v.currently_attached) { // We will try and unplug the VIF even if it seems to be already unplugged (CA-75969) log.DebugFormat("Unplugging VIF '{0}': this VIF is not currently attached. Will try to unplug anyway", v.uuid); } VM vm = v.Connection.Resolve(v.VM); if (vm == null || vm.power_state != vm_power_state.Running) { log.DebugFormat("Ignoring VIF '{0}' for unplug as its VM is not running", v.uuid); return; } VIF.unplug(Session, v.opaque_ref); }
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); }