Esempio n. 1
0
        protected override void Run()
        {
            Exception unplugException = null;

            // Only unplug and replug already plugged pbds
            List <String> pluggedPBDrefs = new List <String>();

            try
            {
                foreach (PBD pbd in host.Connection.ResolveAll(host.PBDs))
                {
                    if (!pbd.currently_attached)
                    {
                        continue;
                    }

                    pluggedPBDrefs.Add(pbd.opaque_ref);
                    PBD.unplug(Session, pbd.opaque_ref);
                }

                // CA-19392: Multipath enablement / disablement
                if (multipath)
                {
                    Host.remove_from_other_config(Session, host.opaque_ref, Host.MULTIPATH);
                    Host.add_to_other_config(Session, host.opaque_ref, Host.MULTIPATH, "true");
                    Host.remove_from_other_config(Session, host.opaque_ref, Host.MULTIPATH_HANDLE);
                    Host.add_to_other_config(Session, host.opaque_ref, Host.MULTIPATH_HANDLE, DEFAULT_MULTIPATH_HANDLE);
                }
                else
                {
                    Host.remove_from_other_config(Session, host.opaque_ref, Host.MULTIPATH);
                    Host.add_to_other_config(Session, host.opaque_ref, Host.MULTIPATH, "false");
                    Host.remove_from_other_config(Session, host.opaque_ref, Host.MULTIPATH_HANDLE);
                }
            }
            catch (Exception e)
            {
                unplugException = e;

                log.Debug("Error occurred unplugging pbds", e);
                log.Debug(e, e);

                throw;
            }
            finally
            {
                Exception plugException = null;

                foreach (String pbdRef in pluggedPBDrefs)
                {
                    try
                    {
                        PBD.plug(Session, pbdRef);
                    }
                    catch (Exception e)
                    {
                        if (unplugException == null && plugException == null)
                        {
                            plugException = e;
                        }

                        log.Debug("Error occurred replugging pbds", e);
                        log.Debug(e, e);
                    }
                }

                // Only throw a plug exception if there we no unplug exceptions
                if (unplugException == null && plugException != null)
                {
                    throw plugException;
                }
            }
        }