protected override void Run() { log.Debug("Running SR Reconfigure Action"); log.DebugFormat("SR uuid = '{0}'", sr.uuid); log.DebugFormat("name = '{0}'", name); log.DebugFormat("description = '{0}'", description); Description = Messages.ACTION_SR_ATTACHING; // Repair the SR with new PBDs for each host in the pool PBD pbdTemplate = new PBD(); pbdTemplate.currently_attached = false; pbdTemplate.device_config = dconf; pbdTemplate.SR = new XenRef <SR>(sr.opaque_ref); int delta = 100 / (Connection.Cache.HostCount * 2); List <Host> _listHost = new List <Host>(Connection.Cache.Hosts); Util.masterFirst(_listHost); foreach (Host host in _listHost) { // Create the PBD log.DebugFormat("Creating PBD for host {0}", host.Name); this.Description = String.Format(Messages.ACTION_SR_REPAIR_CREATE_PBD, Helpers.GetName(host)); pbdTemplate.host = new XenRef <Host>(host.opaque_ref); RelatedTask = PBD.async_create(this.Session, pbdTemplate); PollToCompletion(PercentComplete, PercentComplete + delta); XenRef <PBD> pbdRef = new XenRef <PBD>(this.Result); // Now plug the PBD log.DebugFormat("Plugging PBD for host {0}", host.Name); this.Description = String.Format(Messages.ACTION_SR_REPAIR_PLUGGING_PBD, Helpers.GetName(host)); RelatedTask = PBD.async_plug(this.Session, pbdRef); PollToCompletion(PercentComplete, PercentComplete + delta); } // Update the name and description of the SR XenAPI.SR.set_name_label(Session, sr.opaque_ref, name); XenAPI.SR.set_name_description(Session, sr.opaque_ref, description); Description = Messages.ACTION_SR_ATTACH_SUCCESSFUL; }
protected override void Run() { foreach (XenRef <PBD> pbd in sr.PBDs) { RelatedTask = PBD.async_destroy(Session, pbd.opaque_ref); PollToCompletion(); } Description = Messages.ACTION_SR_ATTACHING; // Now repair the SR with new PBDs for each host in the pool PBD pbdTemplate = new PBD(); pbdTemplate.currently_attached = false; pbdTemplate.device_config = dconf; pbdTemplate.SR = new XenRef <SR>(sr.opaque_ref); int delta = 100 / (Connection.Cache.HostCount * 2); List <Host> _listHost = new List <Host>(Connection.Cache.Hosts); masterFirst(_listHost); foreach (Host host in _listHost) { // Create the PBD log.DebugFormat("Creating PBD for host {0}", host.Name); this.Description = String.Format(Messages.ACTION_SR_REPAIR_CREATE_PBD, Helpers.GetName(host)); pbdTemplate.host = new XenRef <Host>(host.opaque_ref); RelatedTask = PBD.async_create(this.Session, pbdTemplate); PollToCompletion(PercentComplete, PercentComplete + delta); XenRef <PBD> pbdRef = new XenRef <PBD>(this.Result); // Now plug the PBD log.DebugFormat("Plugging PBD for host {0}", host.Name); this.Description = String.Format(Messages.ACTION_SR_REPAIR_PLUGGING_PBD, Helpers.GetName(host)); RelatedTask = PBD.async_plug(this.Session, pbdRef); PollToCompletion(PercentComplete, PercentComplete + delta); } Description = Messages.ACTION_SR_ATTACH_SUCCESSFUL; }
protected override void Run() { log.Debug("Running SR.Introduce"); log.DebugFormat("SR uuid='{0}'", _srUuid); log.DebugFormat("name='{0}'", _srName); log.DebugFormat("description='{0}'", _srDescription); log.DebugFormat("type='{0}'", _srType); log.DebugFormat("content type='{0}'", _srContentType); log.DebugFormat("is shared='{0}'", _srIsShared); Description = Messages.ACTION_SR_ATTACHING; // If SR is already attached, forget it (it may be in a broken invisible state with no PBDs) try { log.Debug("Performing preemptive SR.forget()"); RelatedTask = XenAPI.SR.async_forget(this.Session, XenAPI.SR.get_by_uuid(this.Session, _srUuid).opaque_ref); PollToCompletion(0, 5); } catch (Failure) { // Allow failure } // Introduce the existing SR RelatedTask = XenAPI.SR.async_introduce(this.Session, _srUuid, _srName, _srDescription, _srType.ToString(), _srContentType, _srIsShared, new Dictionary <string, string>()); PollToCompletion(5, 10); // cache result, in order to reassign it later string introducedSr = Result; // Now repair the SR with new PBDs for each host in the pool XenAPI.PBD pbdTemplate = new PBD(); pbdTemplate.currently_attached = false; pbdTemplate.device_config = _dconf; pbdTemplate.SR = new XenRef <SR>(Result); int delta = 90 / Connection.Cache.HostCount / 2; foreach (Host host in Connection.Cache.Hosts) { // Create the PBD log.DebugFormat("Creating PBD for host {0}", host.Name()); this.Description = string.Format(Messages.ACTION_SR_REPAIR_CREATE_PBD, Helpers.GetName(host)); pbdTemplate.host = new XenRef <Host>(host.opaque_ref); RelatedTask = PBD.async_create(this.Session, pbdTemplate); PollToCompletion(PercentComplete, PercentComplete + delta); XenRef <PBD> pbdRef = new XenRef <PBD>(this.Result); // Now plug the PBD log.DebugFormat("Plugging PBD for host {0}", host.Name()); this.Description = string.Format(Messages.ACTION_SR_REPAIR_PLUGGING_PBD, Helpers.GetName(host)); RelatedTask = XenAPI.PBD.async_plug(this.Session, pbdRef); PollToCompletion(PercentComplete, PercentComplete + delta); } // reassign result Result = introducedSr; if (isFirstSharedNonISOSR()) { SR new_sr = Connection.WaitForCache(new XenRef <SR>(Result), GetCancelling); if (Cancelling) { throw new CancelledException(); } if (new_sr == null) { throw new Failure(Failure.HANDLE_INVALID, "SR", Result); } // Set this SR to be the default new SrAction(SrActionKind.SetAsDefault, new_sr).RunExternal(Session); } Description = Messages.ACTION_SR_ATTACH_SUCCESSFUL; }