コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="o"></param>
        /// <param name="query"></param>
        public bool Save()
        {
            InvokeHelper.AssertOffEventThread();

            if (uuid == null)
            {
                uuid = System.Guid.NewGuid().ToString();
            }

            String key   = SearchPrefix + uuid;
            String value = GetXML();

            if (connection == null)
            {
                return(false);
            }

            if (!connection.IsConnected)
            {
                return(false);
            }

            Session session = connection.DuplicateSession();

            foreach (Pool pool in connection.Cache.Pools)
            {
                Pool.remove_from_gui_config(session, pool.opaque_ref, key);
                Pool.add_to_gui_config(session, pool.opaque_ref, key, value);

                return(true);
            }

            return(false);
        }
コード例 #2
0
 public void LoginSession()
 {
     if (connection != null)
     {
         SessionUrl  = connection.Session.Url;
         SessionUuid = connection.DuplicateSession().uuid;
     }
 }
コード例 #3
0
        public void LoginSession()
        {
            if (connection != null)
            {
                SessionUrl       = connection.Session.Url;
                SessionOpaqueRef = connection.DuplicateSession().opaque_ref;
#pragma warning disable 612, 618
                SessionUuid = SessionOpaqueRef;
#pragma warning restore 612, 618
            }
        }
コード例 #4
0
        /// <summary>
        /// Used for cross connection actions (e.g adding a host to a pool, we need to get a session from the connection we are joining)
        /// Checks to see if we are using elevated credentials for this action. Returns a session using them if they exist, otherwise
        /// using the basic credentials of the _supplied_ IXenConnection. Important - will throw exceptions similar to connection.NewSession
        /// </summary>
        /// <param name="xc"></param>
        /// <returns></returns>
        public Session NewSession(IXenConnection xc)
        {
            if (Connection == null)
            {
                return(null);
            }

            if (String.IsNullOrEmpty(sudoPassword) || String.IsNullOrEmpty(sudoUsername))
            {
                return(xc.DuplicateSession());
            }

            return(xc.ElevatedSession(sudoUsername, sudoPassword));
        }
コード例 #5
0
ファイル: Heartbeat.cs プロジェクト: zhaoyingpu/xenadmin
        private void DoHeartbeat()
        {
            if (!connection.IsConnected)
            {
                return;
            }

            try
            {
                if (session == null)
                {
                    // Try to get a new session, but only give the server one chance (otherwise we get the default 3x timeout)
                    session = connection.DuplicateSession(connectionTimeout < 5000 ? 5000 : connectionTimeout);
                    session.ConnectionGroupName = heartbeatConnectionGroupName; // this will force the Heartbeat session onto its own set of TCP streams (see CA-108676)
                }

                GetServerTime();

                // Now that we've successfully received a heartbeat, reset our 'second chance' for the server to timeout
                if (retrying)
                {
                    log.DebugFormat("Heartbeat for {0} has come back", session == null ? "null" : session.Url);
                }
                retrying = false;
            }
            catch (TargetInvocationException exn)
            {
                if (exn.InnerException is SocketException ||
                    exn.InnerException is WebException)
                {
                    log.Debug(exn.Message);
                }
                else
                {
                    log.Error(exn);
                }
                HandleConnectionLoss();
                return;
            }
            catch (Exception exn)
            {
                log.Error(exn);
                HandleConnectionLoss();
                return;
            }
        }
コード例 #6
0
        public static void StartDiagnosisForm(VM vm, bool isStart)
        {
            ThreadPool.QueueUserWorkItem(delegate
            {
                string title = Messages.ERROR_DIALOG_START_VM_TITLE;
                string text  = string.Format(Messages.ERROR_DIALOG_START_VM_TEXT, vm);

                if (Win32Window.GetWindowWithText(title) != null)
                {
                    // don't bother showing this if there's one already up.
                    return;
                }

                IXenConnection connection = vm.Connection;
                Session session           = connection.DuplicateSession();
                if (session != null)
                {
                    var reasons = new Dictionary <IXenObject, string>();

                    foreach (Host host in connection.Cache.Hosts)
                    {
                        reasons[host] = string.Empty;
                        if (!isStart && VMOperationHostCommand.VmCpuFeaturesIncompatibleWithHost(host, vm))
                        {
                            reasons[host] = FriendlyErrorNames.VM_INCOMPATIBLE_WITH_THIS_HOST;
                            continue;
                        }
                        try
                        {
                            VM.assert_can_boot_here(session, vm.opaque_ref, host.opaque_ref);
                        }
                        catch (Failure failure)
                        {
                            reasons[host] = failure.Message;
                        }
                    }

                    Program.Invoke(Program.MainWindow, () =>
                    {
                        using (var dialog = new CommandErrorDialog(title, text, reasons))
                            dialog.ShowDialog(Program.MainWindow);
                    });
                }
            });
        }
コード例 #7
0
ファイル: FolderAction.cs プロジェクト: weiling103/xenadmin
        private Session GetSession(IXenConnection conn)
        {
            // First we look at this.Session. This allows us to sudo if we have only one connection.
            if (Session != null && Session.Connection == conn)
            {
                return(Session);
            }

            // Otherwise we dig into our dictionary of sessions for other connections. These cannot be sudo'ed,
            // because there is no good way to make a sudo dialog (or a series of dialogs) for several connections.
            if (Sessions.ContainsKey(conn))
            {
                return(Sessions[conn]);
            }
            Session s = conn.DuplicateSession();

            Sessions[conn] = s;
            return(s);
        }
コード例 #8
0
ファイル: Heartbeat.cs プロジェクト: ryu2048/xenadmin
        private void DoHeartbeat()
        {
            if (!connection.IsConnected)
            {
                return;
            }

            try
            {
                if (session == null)
                {
                    // Try to get a new session, but only give the server one chance (otherwise we get the default 3x timeout)
                    session = connection.DuplicateSession(connectionTimeout < 5000 ? 5000 : connectionTimeout);
                }

                GetServerTime();

                // Now that we've successfully received a heartbeat, reset our 'second chance' for the server to timeout
                retrying = false;
            }
            catch (TargetInvocationException exn)
            {
                if (exn.InnerException is SocketException ||
                    exn.InnerException is WebException)
                {
                    log.Debug(exn.Message);
                }
                else
                {
                    log.Error(exn);
                }
                HandleConnectionLoss();
                return;
            }
            catch (Exception exn)
            {
                log.Error(exn);
                HandleConnectionLoss();
                return;
            }
        }
コード例 #9
0
        private void UpdateVMAgility(object obj)
        {
            Program.AssertOffEventThread();

            try
            {
                IXenConnection c       = vm.Connection;
                Session        session = c.DuplicateSession();

                try
                {
                    VM.assert_agile(session, vm.opaque_ref);
                    // The VM was agile
                    vmIsAgile = true;
                }
                catch (Failure)
                {
                    // VM wasn't agile
                    vmIsAgile = false;
                }
                Program.Invoke(Program.MainWindow, delegate()
                {
                    RefillPrioritiesComboBox();
                });
            }
            catch (Exception e)
            {
                log.Error(e);
            }
            finally
            {
                Program.Invoke(this, delegate()
                {
                    if (verticalTabs != null)
                    {
                        verticalTabs.Refresh();
                    }
                });
            }
        }
コード例 #10
0
        public static void StartDiagnosisForm(VM vm)
        {
            ThreadPool.QueueUserWorkItem(delegate
            {
                string title = Messages.ERROR_DIALOG_START_VM_TITLE;
                string text  = string.Format(Messages.ERROR_DIALOG_START_VM_TEXT, vm);

                if (Win32Window.GetWindowWithText(title) != null)
                {
                    // don't bother showing this if there's one already up.
                    return;
                }

                IXenConnection connection = vm.Connection;
                Session session           = connection.DuplicateSession();
                if (session != null)
                {
                    Dictionary <Host, string> reasons = new Dictionary <Host, string>();

                    foreach (Host host in connection.Cache.Hosts)
                    {
                        reasons[host] = string.Empty;
                        try
                        {
                            VM.assert_can_boot_here(session, vm.opaque_ref, host.opaque_ref);
                        }
                        catch (Failure failure)
                        {
                            reasons[host] = failure.Message;
                        }
                    }

                    Program.Invoke(Program.MainWindow, () => CommandErrorDialog.Create <Host>(title, text, reasons).ShowDialog(Program.MainWindow));
                }
            });
        }
コード例 #11
0
ファイル: HaNtolControl.cs プロジェクト: wuzhiwyyx/xenadmin
        private void updateNtol()
        {
            Program.AssertOffEventThread();
            log.Debug("Thread starting");

            while (!exitNtolUpdateThread)
            {
                waitingNtolUpdate.WaitOne();
                log.Debug("Thread woken");

                Program.Invoke(this, () =>
                {
                    // Don't do GUI stuff if we've been told to exit
                    if (!exitNtolUpdateThread)
                    {
                        LoadCalculatingMode();
                        ntolUpdateInProgressOrFailed = true;
                        OnNtolKnownChanged();
                    }
                });

                try
                {
                    // Turn the settings dictionary into an api-level one we can pass to compute_hypothetical_max.
                    var config = Helpers.GetVmHaRestartPrioritiesForApi(settings);

                    Session dupSess = connection.DuplicateSession(60 * 1000);

                    // Use a 1 minute timeout here (rather than the default 1 day)
                    ntolMax = Pool.GetMaximumTolerableHostFailures(dupSess, config);

                    if (exitNtolUpdateThread)
                    {
                        continue;
                    }

                    log.DebugFormat("Received ntolMax of {0}", ntolMax);
                    Pool p = Helpers.GetPool(connection);
                    if (p == null)
                    {
                        throw new Exception("Pool was equal to null, sleeping");
                    }

                    //This is the value we will use to set the ntol indicator if
                    //it is a first population, or if resetting because of pool changes
                    decimal value = p.ha_enabled
                                        ? (Pool.get_ha_host_failures_to_tolerate(dupSess, p.opaque_ref))
                                        : ntolMax;

                    Program.Invoke(this, () =>
                    {
                        // Don't do GUI stuff if we've been told to exit
                        if (!exitNtolUpdateThread)
                        {
                            LoadCalculationSucceededMode(value);
                            ntolUpdateInProgressOrFailed = false;
                            OnNtolKnownChanged();
                        }
                    });
                }
                catch (Exception e)
                {
                    log.Warn(e, e);
                    ntol = -1;
                    Program.Invoke(this, () =>
                    {
                        // Don't do GUI stuff if we've been told to exit
                        if (!exitNtolUpdateThread)
                        {
                            LoadCalculationFailedMode();
                        }
                    });
                }
            }

            log.Debug("Thread exiting");
        }
コード例 #12
0
ファイル: FolderAction.cs プロジェクト: ushamandya/xenadmin
        private Session GetSession(IXenConnection conn)
        {
            // First we look at this.Session. This allows us to sudo if we have only one connection.
            if (Session != null && Session.Connection == conn)
                return Session;

            // Otherwise we dig into our dictionary of sessions for other connections. These cannot be sudo'ed,
            // because there is no good way to make a sudo dialog (or a series of dialogs) for several connections.
            if (Sessions.ContainsKey(conn))
                return Sessions[conn];
            Session s = conn.DuplicateSession();
            Sessions[conn] = s;
            return s;
        }
コード例 #13
0
ファイル: Task.cs プロジェクト: zhaoyingpu/xenadmin
        /// <summary>
        /// Try and run the delegate.
        /// If it fails with a web exception or invalid session, try again.
        /// Only retry 60 times.
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="session"></param>
        /// <param name="f"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public static Object DoWithSessionRetry(IXenConnection connection, ref Session session, Delegate f, params object[] p)
        {
            int retries = 60;

            while (true)
            {
                try
                {
                    object[] ps = new object[p.Length + 1];

                    ps[0] = session;

                    for (int i = 0; i < p.Length; i++)
                    {
                        ps[i + 1] = p[i];
                    }

                    try
                    {
                        return(f.DynamicInvoke(ps));
                    }
                    catch (TargetInvocationException exn)
                    {
                        throw exn.InnerException;
                    }
                }
                catch (WebException we)
                {
                    log.ErrorFormat("WebException in DoWithSessionRetry, retry {0}", retries);
                    log.Error(we, we);

                    if (retries <= 0)
                    {
                        throw;
                    }
                }
                catch (Failure failure)
                {
                    log.ErrorFormat("Failure in DoWithSessionRetry, retry {0}", retries);
                    log.Error(failure, failure);

                    if (retries <= 0)
                    {
                        throw;
                    }

                    if (failure.ErrorDescription.Count < 1 || failure.ErrorDescription[0] != XenAPI.Failure.SESSION_INVALID)
                    {
                        throw;
                    }
                }

                Session newSession = connection.DuplicateSession();

                try
                {
                    // Try and logout the old session using the new session
                    newSession.proxy.session_logout(session.uuid);
                }
                catch
                {
                }

                session = newSession;

                retries--;

                Thread.Sleep(connection.ExpectDisruption ? 500 : 100);
            }
        }
コード例 #14
0
ファイル: Task.cs プロジェクト: robhoes/xenadmin
        /// <summary>
        /// Try and run the delegate.
        /// If it fails with a web exception or invalid session, try again.
        /// Only retry 60 times. 
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="session"></param>
        /// <param name="f"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public static Object DoWithSessionRetry(IXenConnection connection, ref Session session, Delegate f, params object[] p)
        {
            int retries = 60;

            while (true)
            {
                try
                {
                    object[] ps = new object[p.Length + 1];

                    ps[0] = session;

                    for (int i = 0; i < p.Length; i++)
                    {
                        ps[i + 1] = p[i];
                    }

                    try
                    {
                        return f.DynamicInvoke(ps);
                    }
                    catch (TargetInvocationException exn)
                    {
                        throw exn.InnerException;
                    }
                }
                catch (WebException we)
                {
                    log.ErrorFormat("WebException in DoWithSessionRetry, retry {0}", retries);
                    log.Error(we, we);

                    if (retries <= 0)
                        throw;
                }
                catch (Failure failure)
                {
                    log.ErrorFormat("Failure in DoWithSessionRetry, retry {0}", retries);
                    log.Error(failure, failure);

                    if (retries <= 0)
                        throw;

                    if (failure.ErrorDescription.Count < 1 || failure.ErrorDescription[0] != XenAPI.Failure.SESSION_INVALID)
                        throw;
                }

                Session newSession = connection.DuplicateSession();

                try
                {
                    // Try and logout the old session using the new session
                    newSession.proxy.session_logout(session.uuid);
                }
                catch
                {
                }

                session = newSession;

                retries--;

                Thread.Sleep(connection.ExpectDisruption ? 500 : 100);
            }
        }
コード例 #15
0
        /// <summary>
        /// Try and run the delegate.
        /// If it fails with a web exception or invalid session, try again.
        /// Only retry 60 times.
        /// </summary>
        public static Object DoWithSessionRetry(IXenConnection connection, ref Session session, Delegate f, params object[] p)
        {
            int retries = 60;

            while (true)
            {
                try
                {
                    object[] ps = new object[p.Length + 1];

                    ps[0] = session;

                    for (int i = 0; i < p.Length; i++)
                    {
                        ps[i + 1] = p[i];
                    }

                    try
                    {
                        return(f.DynamicInvoke(ps));
                    }
                    catch (TargetInvocationException exn)
                    {
                        if (exn.InnerException != null)
                        {
                            throw exn.InnerException;
                        }
                        throw;
                    }
                }
                catch (WebException we)
                {
                    log.Error($"WebException in DoWithSessionRetry, retry {retries}: ", we);

                    if (retries <= 0)
                    {
                        throw;
                    }
                }
                catch (Failure failure)
                {
                    log.Error($"Failure in DoWithSessionRetry, retry {retries}", failure);

                    if (retries <= 0)
                    {
                        throw;
                    }

                    if (failure.ErrorDescription.Count < 1 || failure.ErrorDescription[0] != Failure.SESSION_INVALID)
                    {
                        throw;
                    }
                }

                Session newSession;

                try
                {
                    // try to create a new TCP stream to use, as the other one has failed us
                    newSession = connection.DuplicateSession();
                    session    = newSession;
                }
                catch
                {
                }

                retries--;

                Thread.Sleep(connection.ExpectDisruption ? 500 : 100);
            }
        }
コード例 #16
0
        protected sealed override void _Run()
        {
            Session session = Connection.DuplicateSession();

            RunWithSession(ref session);
        }
コード例 #17
0
ファイル: AsyncAction.cs プロジェクト: ChrisH4rding/xenadmin
        /// <summary>
        /// Used for cross connection actions (e.g adding a host to a pool, we need to get a session from the connection we are joining)
        /// Checks to see if we are using elevated credentials for this action. Returns a session using them if they exist, otherwise
        /// using the basic credentials of the _supplied_ IXenConnection. Important - will throw exceptions similar to connection.NewSession
        /// </summary>
        /// <param name="xc"></param>
        /// <returns></returns>
        public Session NewSession(IXenConnection xc)
        {
            if (Connection == null)
                return null;

            if (String.IsNullOrEmpty(sudoPassword) || String.IsNullOrEmpty(sudoUsername))
                return xc.DuplicateSession();

            return xc.ElevatedSession(sudoUsername, sudoPassword);
        }
コード例 #18
0
        private void DoHeartbeat()
        {
            if (!connection.IsConnected)
            {
                return;
            }

            try
            {
                if (session == null)
                {
                    // Try to get a new session, but only give the server one chance (otherwise we get the default 3x timeout)
                    session = connection.DuplicateSession(connectionTimeout < 5000 ? 5000 : connectionTimeout);
                    session.ConnectionGroupName = heartbeatConnectionGroupName; // this will force the Heartbeat session onto its own set of TCP streams (see CA-108676)
                }

                GetServerTime();

                // Now that we've successfully received a heartbeat, reset our 'second chance' for the server to timeout
                if (retrying)
                {
                    log.DebugFormat("Heartbeat for {0} has come back", session.Url);
                }
                retrying = false;
            }
            catch (TargetInvocationException exn)
            {
                if (exn.InnerException is SocketException ||
                    exn.InnerException is WebException)
                {
                    log.Debug(exn.Message);
                }
                else
                {
                    log.Error(exn);
                }
                HandleConnectionLoss();
            }
            catch (WebException exn)
            {
                log.Error(exn);
                var webResponse = (HttpWebResponse)exn.Response;
                if (webResponse != null && webResponse.StatusCode == HttpStatusCode.ProxyAuthenticationRequired) // work-around for CA-214653
                {
                    if (session == null)
                    {
                        log.Debug("Heartbeat has failed due to null session; closing the main connection");
                    }
                    else if (session.proxy.Proxy.Credentials == null)
                    {
                        log.DebugFormat("Heartbeat for {0} has failed due to missing credentials; closing the main connection", session.Url);
                    }
                    else
                    {
                        log.DebugFormat("Heartbeat for {0} has failed due to incorrect credentials; closing the main connection", session.Url);
                    }

                    connection.Interrupt();
                    DropSession();
                }
                else
                {
                    HandleConnectionLoss();
                }
            }
            catch (Exception exn)
            {
                log.Error(exn);
                HandleConnectionLoss();
            }
        }