Ejemplo n.º 1
0
        /// <summary>
        /// Ensures we have at least 1 'slack' server failure. i.e. ensures ntol is such that removing 1 host from the pool
        /// (by reboot, shutdown or disable) will succeed.
        /// May throw CancelledException if the user says no.
        /// </summary>
        /// <param name="actionKind">Must be one of Evacuate, Reboot, RebootAndWait or Shutdown. Required so we can show the correct prompt.</param>
        protected void MaybeReduceNtolBeforeOp(HostActionKind actionKind)
        {
            System.Diagnostics.Trace.Assert(actionKind == HostActionKind.Reboot ||
                                            actionKind == HostActionKind.RebootAndWait || actionKind == HostActionKind.Shutdown || actionKind == HostActionKind.Evacuate);

            // We may need to drop ntol for this disable to succeed.
            Pool pool = Helpers.GetPoolOfOne(Host.Connection);

            if (pool != null && pool.ha_enabled)
            {
                Dictionary <XenRef <VM>, string> config = Helpers.GetVmHaRestartPrioritiesForApi(Helpers.GetVmHaRestartPriorities(pool.Connection, true));
                long max = XenAPI.Pool.ha_compute_hypothetical_max_host_failures_to_tolerate(this.Session, config);

                long currentNtol = pool.ha_host_failures_to_tolerate;
                long targetNtol  = Math.Max(0, max - 1);

                if (currentNtol > targetNtol)
                {
                    bool cancel = false;

                    // We need to lower ntol. Ask user.
                    cancel = (AcceptNTolChanges != null) ? AcceptNTolChanges(this, pool, currentNtol, targetNtol) : false;

                    if (cancel)
                    {
                        throw new CancelledException();
                    }

                    // This ensures we can tolerate at least one failure - i.e. the host we're about to disable
                    XenAPI.Pool.set_ha_host_failures_to_tolerate(this.Session, pool.opaque_ref, targetNtol);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Ensures we have at least 1 'slack' server failure. i.e. ensures ntol is such that removing 1 host from the pool
        /// (by reboot, shutdown or disable) will succeed.
        /// May throw CancelledException if the user says no.
        /// </summary>
        /// <param name="actionKind">Must be one of Evacuate, Reboot, RebootAndWait or Shutdown. Required so we can show the correct prompt.</param>
        protected void MaybeReduceNtolBeforeOp(HostActionKind actionKind)
        {
            System.Diagnostics.Trace.Assert(actionKind == HostActionKind.Reboot ||
                actionKind == HostActionKind.RebootAndWait || actionKind == HostActionKind.Shutdown||actionKind==HostActionKind.Evacuate);

            // We may need to drop ntol for this disable to succeed.
            Pool pool = Helpers.GetPoolOfOne(Host.Connection);
            if (pool != null && pool.ha_enabled)
            {
                Dictionary<XenRef<VM>, string> config = Helpers.GetVmHaRestartPrioritiesForApi(Helpers.GetVmHaRestartPriorities(pool.Connection, true));
                long max = XenAPI.Pool.ha_compute_hypothetical_max_host_failures_to_tolerate(this.Session, config);

                long currentNtol = pool.ha_host_failures_to_tolerate;
                long targetNtol = Math.Max(0, max - 1);

                if (currentNtol > targetNtol)
                {
                    bool cancel = false;

                    // We need to lower ntol. Ask user.
                    cancel = (AcceptNTolChanges != null) ? AcceptNTolChanges(this, pool, currentNtol, targetNtol) : false;

                    if (cancel)
                    {
                        throw new CancelledException();
                    }

                    // This ensures we can tolerate at least one failure - i.e. the host we're about to disable
                    XenAPI.Pool.set_ha_host_failures_to_tolerate(this.Session, pool.opaque_ref, targetNtol);
                }
            }
        }