예제 #1
0
        /// <summary>
        /// Called when the user clicks one of the restart priorities in the context menu.
        /// </summary>
        private void priority_Click(object sender, EventArgs e)
        {
            var menuitem = (ToolStripMenuItem)sender;

            VM.HA_Restart_Priority pri = (VM.HA_Restart_Priority)menuitem.Tag;

            bool changesMade = false;

            foreach (var row in dataGridViewVms.SelectedRows.Cast <VmWithSettingsRow>())
            {
                if (row.RestartPriority != pri)
                {
                    changesMade = true;
                    row.UpdateRestartPriority(pri);
                }
            }

            if (changesMade)
            {
                ChangesMade = true;
                haNtolIndicator.Settings = getCurrentSettings();
                // Will trigger a ntol update under this revised plan
                updateButtons();
            }
        }
예제 #2
0
        /// <summary>
        /// Must be a VM.
        /// </summary>
        public void SetXenObjects(IXenObject orig, IXenObject clone)
        {
            // This should only ever be set once
            System.Diagnostics.Trace.Assert(vm == null);
            vm = (VM)clone;

            origRestartPriority = vm.HARestartPriority();
            SelectedPriority    = origRestartPriority;
            origOrder           = vm.order;
            origStartDelay      = vm.start_delay;

            Repopulate();
            haNtolIndicator.Connection = vm.Connection;
            haNtolIndicator.Settings   = Helpers.GetVmHaRestartPriorities(vm.Connection, Properties.Settings.Default.ShowHiddenVMs);
            haNtolIndicator.UpdateInProgressChanged += new EventHandler(haNtolIndicator_UpdateInProgressChanged);

            // Put property changed listener on pool, disable edits if HA becomes disabled
            pool = Helpers.GetPoolOfOne(vm.Connection);
            if (pool != null)
            {
                pool.PropertyChanged += pool_PropertyChanged;
            }
            origNtol = pool.ha_host_failures_to_tolerate;

            // Put property changed listener on all hosts to listen for changes in their Host_metrics
            foreach (Host host in vm.Connection.Cache.Hosts)
            {
                host.PropertyChanged += host_PropertyChanged;
                // Remember the host so we can deregister the listener later
                hosts.Add(host);
                // Also register on the current metrics object - we need to know if a host goes down
                Host_metrics metrics = vm.Connection.Resolve(host.metrics);
                if (metrics != null)
                {
                    metrics.PropertyChanged += metrics_PropertyChanged;
                    // Remember the metrics object so we can deregister the listener later
                    hostMetrics.Add(metrics);
                }
            }

            // Listen for new hosts so that we can add metrics listeners
            vm.Connection.Cache.RegisterCollectionChanged <Host>(Host_CollectionChangedWithInvoke);

            // Start thread to determine if VM is agile
            ToggleScanningVmAgile(true);

            Thread t = new Thread(UpdateVMAgility);

            t.Name         = "Updater for VM agility for " + Helpers.GetName(vm);
            t.IsBackground = true;
            t.Priority     = ThreadPriority.Highest;
            t.Start();
        }
예제 #3
0
        public void SetXenObjects(IXenObject orig, IXenObject clone)
        {
            Trace.Assert(clone is VM);                                        // only VMs should show this page
            Trace.Assert(!Helpers.FeatureForbidden(clone, Host.RestrictGpu)); // If license insufficient, we show upsell page instead

            vm = (VM)clone;
            SelectedPriority = vm.HARestartPriority;

            if (Connection == null) // on the PropertiesDialog
            {
                Connection = vm.Connection;
            }

            PopulatePage();
        }
예제 #4
0
        private void comboBoxRestartPriority_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (vm == null)
            {
                return;
            }

            VM.HA_Restart_Priority priority = SelectedPriority;

            comboLabel.Text = Helpers.RestartPriorityDescription(priority);

            Dictionary <VM, VM.HA_Restart_Priority> settings = Helpers.GetVmHaRestartPriorities(vm.Connection, Properties.Settings.Default.ShowHiddenVMs);

            // Supplement with the changed setting
            settings[vm] = priority;

            // This will trigger an update in the ntol indicator.
            haNtolIndicator.Settings = settings;
        }
예제 #5
0
        /// <summary>
        /// Called after we determine if the selected VM is agile or not. Fills the combo box with the correct PriorityWrappers.
        /// </summary>
        private void RefillPrioritiesComboBox()
        {
            Program.AssertOnEventThread();

            m_comboBoxProtectionLevel.Items.Clear();
            ToggleScanningVmAgile(false);

            List <VM.HA_Restart_Priority> restartPriorities = VM.GetAvailableRestartPriorities(vm.Connection);

            foreach (var restartPriority in restartPriorities)
            {
                // add "restart" priorities only is vm is agile
                if (VM.HaPriorityIsRestart(vm.Connection, restartPriority) && !vmIsAgile)
                {
                    continue;
                }
                m_comboBoxProtectionLevel.Items.Add(new PriorityWrapper(restartPriority));
            }

            // Select appropriate entry in combo box
            bool found = false;

            VM.HA_Restart_Priority pri = vm.HARestartPriority;
            foreach (PriorityWrapper w in m_comboBoxProtectionLevel.Items)
            {
                if (w.Priority == pri)
                {
                    found = true;
                    m_comboBoxProtectionLevel.SelectedItem = w;
                    break;
                }
            }

            if (!found)
            {
                // Someone might have set a High/Medium/Low restart priority for a non-agile VM through the CLI,
                // even though this is not possible through the GUI. Hence we need to add that priority to the
                // combo box just to prevent things screwing up.
                m_comboBoxProtectionLevel.Items.Insert(0, new PriorityWrapper(pri));
                m_comboBoxProtectionLevel.SelectedIndex = 0;
            }
        }
예제 #6
0
 public PriorityWrapper(VM.HA_Restart_Priority priority)
 {
     this.Priority = priority;
 }
예제 #7
0
        private void updateButtons()
        {
            Program.AssertOnEventThread();

            var selectedRows = dataGridViewVms.SelectedRows.Cast <VmWithSettingsRow>().ToList();

            if (dataGridViewVms.SelectedRows.Count == 0)
            {
                m_dropDownButtonRestartPriority.Enabled = false;
                m_dropDownButtonRestartPriority.Text    = "";
                nudOrder.Enabled = nudStartDelay.Enabled = false;
                nudOrder.Text    = nudStartDelay.Text = "";
                return;
            }

            // if there is a VM with null priority in the selection disable all buttons. We are waiting on the background thread
            // to see if the VM is agile before giving it a starting value
            if (selectedRows.Any(r => r.RestartPriority == null))
            {
                m_dropDownButtonRestartPriority.Enabled = true;
                m_dropDownButtonRestartPriority.Text    = "";
                nudOrder.Enabled = nudStartDelay.Enabled = true;
                nudOrder.Text    = nudStartDelay.Text = "";
                return;
            }

            m_dropDownButtonRestartPriority.Enabled = true;

            //now set the drop down button text

            bool allSamePriority = false;

            foreach (ToolStripMenuItem item in contextMenuStrip.Items)
            {
                VM.HA_Restart_Priority itemRestartPriority = (VM.HA_Restart_Priority)item.Tag;

                if (selectedRows.All(r => r.RestartPriority == itemRestartPriority))
                {
                    allSamePriority = true;
                    m_dropDownButtonRestartPriority.Text = Helpers.RestartPriorityI18n(itemRestartPriority);
                    break;
                }
            }

            if (!allSamePriority && dataGridViewVms.SelectedRows.Count > 1)
            {
                m_dropDownButtonRestartPriority.Text = Messages.HA_ASSIGN_PRIORITIES_MIXED_PROTECTION_LEVELS;
            }

            // set the order and delay NUDs
            nudOrder.Enabled = nudStartDelay.Enabled = true;

            var orderDistList = (from row in selectedRows select row.StartOrder).Distinct().ToList();

            nudOrder.Text = orderDistList.Count == 1 ? orderDistList.ElementAt(0).ToString() : "";

            var delayDistList = (from row in selectedRows select row.StartDelay).Distinct().ToList();

            nudStartDelay.Text = delayDistList.Count == 1 ? delayDistList.ElementAt(0).ToString() : "";

            // check that all the VMs selected in the list are agile and make sure the protect button is disabled with the relevant reason
            VmWithSettingsRow nonAgileRow = selectedRows.FirstOrDefault(r => !r.IsAgile);

            // Now set the buttons and tooltips)
            foreach (ToolStripMenuItem menuItem in contextMenuStrip.Items)
            {
                var priority = (VM.HA_Restart_Priority)menuItem.Tag;

                if (VM.HaPriorityIsRestart(connection, priority))
                {
                    menuItem.Enabled     = (nonAgileRow == null);
                    menuItem.ToolTipText = (nonAgileRow == null)
                                               ? ""
                                               : nonAgileRow.FriendlyNonAgileReason;
                }
                else
                {
                    menuItem.Enabled = true;
                }
            }
        }
예제 #8
0
 public PriorityWrapper(VM.HA_Restart_Priority priority)
 {
     this.Priority = priority;
 }
예제 #9
0
        /// <summary>
        /// Must be a VM.
        /// </summary>
        public void SetXenObjects(IXenObject orig, IXenObject clone)
        {
            // This should only ever be set once
            System.Diagnostics.Trace.Assert(vm == null);
            vm = (VM)clone;

            origRestartPriority = vm.HARestartPriority;
            origOrder = vm.order;
            origStartDelay = vm.start_delay;

            Repopulate();
            haNtolIndicator.Connection = vm.Connection;
            haNtolIndicator.Settings = Helpers.GetVmHaRestartPriorities(vm.Connection, Properties.Settings.Default.ShowHiddenVMs);
            haNtolIndicator.UpdateInProgressChanged += new EventHandler(haNtolIndicator_UpdateInProgressChanged);

            // Put property changed listener on pool, disable edits if HA becomes disabled
            pool = Helpers.GetPoolOfOne(vm.Connection);
            if (pool != null)
            {
                pool.PropertyChanged += pool_PropertyChanged;
            }
            origNtol = pool.ha_host_failures_to_tolerate;

            // Put property changed listener on all hosts to listen for changes in their Host_metrics
            foreach (Host host in vm.Connection.Cache.Hosts)
            {
                host.PropertyChanged += host_PropertyChanged;
                // Remember the host so we can deregister the listener later
                hosts.Add(host);
                // Also register on the current metrics object - we need to know if a host goes down
                Host_metrics metrics = vm.Connection.Resolve(host.metrics);
                if (metrics != null)
                {
                    metrics.PropertyChanged += metrics_PropertyChanged;
                    // Remember the metrics object so we can deregister the listener later
                    hostMetrics.Add(metrics);
                }
            }

            // Listen for new hosts so that we can add metrics listeners
            vm.Connection.Cache.RegisterCollectionChanged<Host>(Host_CollectionChangedWithInvoke);

            // Start thread to determine if VM is agile
            ToggleScanningVmAgile(true);

            Thread t = new Thread(UpdateVMAgility);
            t.Name = "Updater for VM agility for " + Helpers.GetName(vm);
            t.IsBackground = true;
            t.Priority = ThreadPriority.Highest;
            t.Start();
        }
예제 #10
0
        public void SetXenObjects(IXenObject orig, IXenObject clone)
        {
            Trace.Assert(clone is VM);  // only VMs should show this page
            Trace.Assert(Helpers.BostonOrGreater(clone.Connection));  // If not Boston or greater, we shouldn't see this page
            Trace.Assert(!Helpers.FeatureForbidden(clone, Host.RestrictGpu));  // If license insufficient, we show upsell page instead

            vm = (VM)clone;
            SelectedPriority = vm.HARestartPriority;

            if (Connection == null) // on the PropertiesDialog
                Connection = vm.Connection;

            PopulatePage();
        }