Ejemplo n.º 1
0
 private void SetConfigurationItems()
 {
     // Populate the Configuration Items
     pdSectionConfiguration.PauseLayout();
     pdSectionConfiguration.ClearData();
     if (WlbServerState.GetState(_pool) == WlbServerState.ServerState.ConnectionError)
     {
         pdSectionConfiguration.AddEntry(Messages.WLB_STATUS, getPoolWLBStatus(_pool));
         pdSectionConfiguration.AddEntry(Messages.WLB_SERVER_URL, getPoolWLBServer(_pool));
     }
     else
     {
         pdSectionConfiguration.AddEntry(Messages.WLB_SERVER_URL, getPoolWLBServer(_pool));
         pdSectionConfiguration.AddEntry(Messages.WLB_OPT_MODE, getPoolOptMode(_pool));
         if (null != _wlbPoolConfiguration && _wlbPoolConfiguration.IsMROrLater)
         {
             if (_wlbPoolConfiguration.AutomateOptimizationMode)
             {
                 pdSectionConfiguration.AddEntry(Messages.WLB_NEXT_OPT_MODE_SCHEDULE_TEXT, getNextOptModeTask(_pool));
             }
             pdSectionConfiguration.AddEntry(Messages.WLB_AUTO_OPT, getAutoOptimization(_pool));
             pdSectionConfiguration.AddEntry(Messages.WLB_PWR_MGT, getPoolWlbPowerManagement(_pool));
         }
     }
     pdSectionConfiguration.Expand();
     pdSectionConfiguration.StartLayout();
 }
Ejemplo n.º 2
0
 private void buttonOK_Click(object sender, EventArgs e)
 {
     if (WlbServerState.GetState(_pool) == WlbServerState.ServerState.ConnectionError || WlbServerState.GetState(_pool) == WlbServerState.ServerState.NotConfigured)
     {
         try
         {
             if (InitializeWLB())
             {
                 this.DialogResult = DialogResult.OK;
                 this.Close();
             }
         }
         catch
         {
             log.Warn("Error Intializing WLB");
         }
     }
     else
     {
         if (WlbServerState.GetState(_pool) == WlbServerState.ServerState.Disabled)
         {
             if (EnableWlb())
             {
                 this.DialogResult = DialogResult.OK;
                 this.Close();
             }
         }
     }
 }
Ejemplo n.º 3
0
        public EvacuateHostDialog(Host host, string elevatedUserName, string elevatedPassword, Session elevatedSession)
            : base(host.Connection)
        {
            InitializeComponent();

            this.elevatedUsername = elevatedUserName;
            this.elevatedPassword = elevatedPassword;
            this.elevatedSession  = elevatedSession;

            _host = host;
            _pool = Helpers.GetPoolOfOne(_host.Connection);

            if (!_host.IsMaster() || connection.Cache.HostCount <= 1)
            {
                tableLayoutPanelNewMaster.Visible = false;
            }
            else
            {
                tableLayoutPanelPSr.Visible = false;
            }

            tableLayoutPanelWlb.Visible = _pool.IsVisible() && Helpers.WlbEnabled(_host.Connection) &&
                                          WlbServerState.GetState(_pool) == WlbServerState.ServerState.Enabled;

            tableLayoutPanelSpinner.Visible = false;
            tableLayoutPanelStatus.Visible  = false;
            progressBar1.Visible            = false;

            _host.PropertyChanged += hostUpdate;
            _pool.PropertyChanged += poolUpdate;

            ActiveControl = CloseButton;
        }
Ejemplo n.º 4
0
        internal void EditWLB(Pool pool)
        {
            // Do nothing if there is a WLB action in progress
            if (HelpersGUI.FindActiveWLBAction(pool.Connection) != null)
            {
                log.Debug("Not opening WLB dialog: an WLB action is in progress");
                return;
            }

            if (!pool.Connection.IsConnected)
            {
                log.Debug("Not opening WLB dialog: the connection to the pool is now closed");
                return;
            }

            try
            {
                WlbConfigurationDialog wlbConfigDialog = new WlbConfigurationDialog(pool);
                DialogResult           dr = wlbConfigDialog.ShowDialog();

                if (dr == DialogResult.OK)
                {
                    _wlbPoolConfiguration = wlbConfigDialog.WlbPoolConfiguration;

                    //check to see if the current opt mode matches the current schedule
                    if (_wlbPoolConfiguration.AutomateOptimizationMode)
                    {
                        WlbPoolPerformanceMode scheduledPerfMode = _wlbPoolConfiguration.ScheduledTasks.GetCurrentScheduledPerformanceMode();
                        if (scheduledPerfMode != _wlbPoolConfiguration.PerformanceMode)
                        {
                            string       blurb = string.Format(Messages.WLB_PROMPT_FOR_MODE_CHANGE_BLURB, getOptModeText(scheduledPerfMode), getOptModeText(_wlbPoolConfiguration.PerformanceMode));
                            DialogResult drModeCheck;
                            using (var dlg = new ThreeButtonDialog(
                                       new ThreeButtonDialog.Details(null, blurb, Messages.WLB_PROMPT_FOR_MODE_CHANGE_CAPTION),
                                       ThreeButtonDialog.ButtonYes,
                                       ThreeButtonDialog.ButtonNo))
                            {
                                drModeCheck = dlg.ShowDialog(this);
                            }

                            if (drModeCheck == DialogResult.Yes)
                            {
                                _wlbPoolConfiguration.PerformanceMode = scheduledPerfMode;
                            }
                        }
                    }
                    SaveWLBConfig(_wlbPoolConfiguration);
                }
            }
            catch (Exception ex)
            {
                log.Debug("Unable to open the WLB configuration dialog.", ex);
                return;
            }

            if (!(WlbServerState.GetState(_pool) == WlbServerState.ServerState.NotConfigured))
            {
                RetrieveConfiguration();
            }
        }
Ejemplo n.º 5
0
        protected override void Run()
        {
            try
            {
                log.DebugFormat("Retrieving recommendations for pool {0}", Pool.Name());
                this.WLBOptPoolRecommendations = Pool.retrieve_wlb_recommendations(Session);
                log.DebugFormat("Success retrieving recommendations for pool {0}", Pool.Name());

                //Retrieving the recommendations was successful, so update the WlbServerState to report the current state
                //  This is here in case there was a previous communication error which has been fixed.
                if (WlbServerState.GetState(Pool) == WlbServerState.ServerState.ConnectionError || WlbServerState.GetState(Pool) == WlbServerState.ServerState.Unknown)
                {
                    if (Helpers.WlbEnabled(Pool.Connection))
                    {
                        WlbServerState.SetState(Pool, WlbServerState.ServerState.Enabled);
                    }
                    else
                    {
                        WlbServerState.SetState(Pool, WlbServerState.ServerState.Disabled);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is Failure)
                {
                    WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex);
                }
                log.Error(ex, ex);
            }
        }
Ejemplo n.º 6
0
        public void SetOptControlProperties(bool powerManagementSupport, bool autoOptEnabled, bool powerManagementEnabled)
        {
            _autoOptEnabled         = autoOptEnabled;
            _powerManagementEnabled = powerManagementEnabled;

            this.SuspendLayout();
            if ((powerManagementSupport) && (WlbServerState.GetState(_pool) == WlbServerState.ServerState.Enabled))
            {
                //linkLabelReportHistory.Visible = true;

                // Update listView VM/Host header text
                this.optimizePoolListView.BeginUpdate();
                this.columnHeader1.Text = Messages.WLB_OPT_HEADER_VMHOST;
                this.optimizePoolListView.EndUpdate();
            }
            else
            {
                //linkLabelReportHistory.Visible = false;

                // Update listView VM/Host header text
                this.optimizePoolListView.BeginUpdate();
                this.columnHeader1.Text = Messages.WLB_OPT_HEADER_VM;
                this.optimizePoolListView.EndUpdate();
            }

            this.ResumeLayout();
        }
Ejemplo n.º 7
0
 private void SetControlState()
 {
     switch (WlbServerState.GetState(_pool))
     {
     case WlbServerState.ServerState.NotConfigured:
     case WlbServerState.ServerState.ConnectionError:
     {
         decentGroupBoxWLBServerAddress.Enabled = true;
         break;
     }
     }
 }
Ejemplo n.º 8
0
        /* README
         *
         * This dialog inherits from DialogWithProgress. Be extremely careful about resizing it, as the DialogWithProgress
         * class asserts that the controls which inherit it must match its dimensions... otherwise the expanding progress
         * bar may not show.
         *
         */

        public EvacuateHostDialog(Host host)
            : base(host.Connection)
        {
            this.host = host;

            InitializeComponent();

            Shrink();

            this.OriginalText        = this.Text;
            vmsListBox.Sorted        = true;
            vmsListBox.SelectionMode = SelectionMode.None;
            vmsListBox.DrawMode      = DrawMode.OwnerDrawFixed;
            vmsListBox.DrawItem     += new DrawItemEventHandler(vmsListBox_DrawItem);
            vmsListBox.MouseMove    += new MouseEventHandler(vmsListBox_MouseMove);
            //vmsListBox.MouseDoubleClick += new MouseEventHandler(vmsListBox_MouseDoubleClick);
            vmsListBox.MouseClick += new MouseEventHandler(vmsListBox_MouseDoubleClick);
            vmsListBox.ItemHeight  = 16;

            NewMasterComboBox.DrawMode   = DrawMode.OwnerDrawFixed;
            NewMasterComboBox.DrawItem  += new DrawItemEventHandler(NewMasterComboBox_DrawItem);
            NewMasterComboBox.ItemHeight = 16;

            if (!host.IsMaster() || connection.Cache.HostCount <= 1)
            {
                NewMasterComboBox.Enabled = false;
                NewMasterComboBox.Visible = false;
                NewMasterLabel.Visible    = false;
                labelMasterBlurb.Visible  = false;

                // Move the panel containing the VM listbox up to fill the gap where the labels were
                const int pad       = 6;
                int       extraSize = panel2.Top - labelMasterBlurb.Top - pad;
                panel2.Top     = labelMasterBlurb.Top + pad;
                panel2.Height += extraSize;
            }

            Pool pool = Core.Helpers.GetPool(host.Connection);

            if (Helpers.WlbEnabled(host.Connection) && WlbServerState.GetState(pool) == WlbServerState.ServerState.Enabled)
            {
                lableWLBEnabled.Visible = true;
            }

            vms = new Dictionary <string, VMListBoxItem>();
            this.host.PropertyChanged += new PropertyChangedEventHandler(hostUpdate);

            Program.AssertOnEventThread();
            this.Text = OriginalText + " - " + host.Name;
            populateVMs();
            populateHosts();
            ActiveControl = CloseButton;
        }
Ejemplo n.º 9
0
 private void buttonEnableDisableWlb_Click(object sender, EventArgs e)
 {
     if (WlbServerState.GetState(_pool) != WlbServerState.ServerState.Enabled)
     {
         DisableButtons();
         EnableWLB();
     }
     else
     {
         DisableButtons();
         DisableWLB(false);
     }
 }
Ejemplo n.º 10
0
        protected override bool CanExecuteCore(SelectedItemCollection selection)
        {
            if (selection.Count == 1)
            {
                IXenConnection connection = selection[0].Connection;
                bool           inPool     = selection[0].PoolAncestor != null;

                return(inPool &&
                       (((WlbServerState.GetState(selection[0].PoolAncestor) != WlbServerState.ServerState.NotConfigured) &&
                         (WlbServerState.GetState(selection[0].PoolAncestor) != WlbServerState.ServerState.Unknown)) ||
                        Helpers.FeatureForbidden(connection, Host.RestrictWLB)));
            }
            return(false);
        }
Ejemplo n.º 11
0
        /* README
         *
         * This dialog inherits from DialogWithProgress. Be extremely careful about resizing it, as the DialogWithProgress
         * class asserts that the controls which inherit it must match its dimensions... otherwise the expanding progress
         * bar may not show.
         *
         */

        public EvacuateHostDialog(Host host)
            : base(host.Connection)
        {
            this.host = host;

            InitializeComponent();

            Shrink();

            NewMasterComboBox.DrawMode   = DrawMode.OwnerDrawFixed;
            NewMasterComboBox.DrawItem  += new DrawItemEventHandler(NewMasterComboBox_DrawItem);
            NewMasterComboBox.ItemHeight = 16;

            if (!host.IsMaster() || connection.Cache.HostCount <= 1)
            {
                NewMasterComboBox.Enabled = false;
                NewMasterComboBox.Visible = false;
                NewMasterLabel.Visible    = false;
                labelMasterBlurb.Visible  = false;

                // Move the panel containing the VM listbox up to fill the gap where the labels were
                const int pad       = 6;
                int       extraSize = panel2.Top - labelMasterBlurb.Top - pad;
                panel2.Top     = labelMasterBlurb.Top + pad;
                panel2.Height += extraSize;
            }

            Pool pool = Core.Helpers.GetPool(host.Connection);

            if (Helpers.WlbEnabled(host.Connection) && WlbServerState.GetState(pool) == WlbServerState.ServerState.Enabled)
            {
                lableWLBEnabled.Visible = true;
            }

            vms = new Dictionary <string, VmPrecheckRow>();
            this.host.PropertyChanged += new PropertyChangedEventHandler(hostUpdate);

            ActiveControl = CloseButton;
        }
Ejemplo n.º 12
0
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            if (Helpers.WlbConfigured(_pool.Connection) &&
                !(WlbServerState.GetState(_pool) == WlbServerState.ServerState.ConnectionError ||
                  WlbServerState.GetState(_pool) == WlbServerState.ServerState.NotConfigured))
            {
                return;
            }

            DisableButtons();
            WlbCredentialsDialog wlbCredentialsDialog = new WlbCredentialsDialog(_pool);
            DialogResult         dr = wlbCredentialsDialog.ShowDialog();

            if (dr == DialogResult.OK)
            {
                EnableWLB();
            }
            else
            {
                SetButtonState();
            }
        }
Ejemplo n.º 13
0
        private void SetButtonState()
        {
            string statusMessage    = string.Empty;
            string rbacUser         = string.Empty;
            bool   passedRbacChecks = PassedRbacChecks();

            if (!passedRbacChecks)
            {
                List <Role> roleList = _pool.Connection.Session.Roles;
                roleList.Sort();
                rbacUser = roleList[0].FriendlyName;
            }

            AsyncAction thisAction = HelpersGUI.FindActiveWLBAction(_pool.Connection);

            if (thisAction is RetrieveWlbConfigurationAction)
            {
                DisableButtons();
                return;
            }

            //if wlb is not configured,
            // disable the config button and change the text of the Enable button to Initialize WLB...
            //else if (!wlbConfigured)
            else if (WlbServerState.GetState(_pool) == WlbServerState.ServerState.NotConfigured)
            {
                buttonConnect.Visible = true;
                buttonConnect.Text    = Messages.WLB_CONNECT;

                buttonConfigure.Visible           = false;
                buttonEnableDisableWlb.Visible    = false;
                buttonReports.Visible             = false;
                pictureBoxWarningTriangle.Visible = false;

                if (passedRbacChecks)
                {
                    statusMessage = string.Format(Messages.WLB_INITIALIZE_WLB_BLURB, _pool.Name);
                }
                else
                {
                    statusMessage = string.Format(Messages.WLB_INITIALIZE_WLB_BLURB_NO_PRIV, _pool.Name, rbacUser);
                }
                labelStatus.Text = statusMessage;
                pictureBoxWarningTriangle.Visible = (WlbServerState.GetState(_pool) == WlbServerState.ServerState.ConnectionError);

                panelConfiguration.Visible = false;
                wlbOptimizePool.Visible    = false;
            }

            //if there is an error contacting the WLB server,
            // disable the config button and change the text of the Enable button to Initialize WLB...
            //else if (!wlbConfigured)
            else if (WlbServerState.GetState(_pool) == WlbServerState.ServerState.ConnectionError)
            {
                buttonConnect.Visible = true;
                buttonConnect.Text    = Messages.WLB_RECONNECT;

                buttonConfigure.Visible           = false;
                buttonEnableDisableWlb.Visible    = false;
                buttonReports.Visible             = false;
                pictureBoxWarningTriangle.Visible = true;

                if (passedRbacChecks)
                {
                    statusMessage = Messages.WLB_CONNECTION_ERROR_BLURB;
                }
                else
                {
                    statusMessage = string.Format(Messages.WLB_CONNECTION_ERROR_BLURB_NO_PRIV, rbacUser);
                }
                labelStatus.Text    = statusMessage;
                labelStatus.Visible = true;

                pictureBoxWarningTriangle.Visible = (WlbServerState.GetState(_pool) == WlbServerState.ServerState.ConnectionError);
                buttonReports.Enabled             = false;
                panelConfiguration.Visible        = false;
                wlbOptimizePool.Visible           = false;
            }

            //if wlb is configured but not enabled,
            //enable the configure button and enble the enable button
            //else if (wlbConfigured && !wlbEnabled)
            else if (WlbServerState.GetState(_pool) == WlbServerState.ServerState.Disabled)
            {
                base.Text = Messages.WORKLOAD_BALANCING;

                buttonConnect.Visible             = false;
                buttonConfigure.Visible           = true;
                buttonEnableDisableWlb.Visible    = true;
                buttonReports.Visible             = true;
                pictureBoxWarningTriangle.Visible = true;

                buttonConfigure.Enabled           = true;
                buttonEnableDisableWlb.Enabled    = true;
                buttonEnableDisableWlb.Text       = Messages.ENABLE_WLB_ELLIPSIS;
                buttonEnableDisableWlb.ImageIndex = 1; //Play arrow

                if (!passedRbacChecks)
                {
                    statusMessage = string.Format(Messages.WLB_ENABLE_WLB_BLURB_NO_PRIV, _pool.Name, rbacUser);
                }
                else
                {
                    statusMessage = string.Format(Messages.WLB_ENABLE_WLB_BLURB, _pool.Name);
                }
                labelStatus.Text = statusMessage;

                buttonReports.Enabled      = true;
                panelConfiguration.Visible = true;
                wlbOptimizePool.Visible    = true;
            }
            //otherwise, if wlb is configured and enabled, allow configuration, and show enable as Disable
            //else if (wlbEnabled)
            else if (WlbServerState.GetState(_pool) == WlbServerState.ServerState.Enabled)
            {
                buttonConnect.Visible             = false;
                buttonConfigure.Visible           = true;
                buttonEnableDisableWlb.Visible    = true;
                buttonReports.Visible             = true;
                pictureBoxWarningTriangle.Visible = false;

                buttonConfigure.Enabled           = true;
                buttonEnableDisableWlb.Enabled    = true;
                buttonEnableDisableWlb.Text       = Messages.DISABLE_WLB_ELLIPSIS;
                buttonEnableDisableWlb.ImageIndex = 0; //Pause hashes

                if (!passedRbacChecks)
                {
                    statusMessage = string.Format(Messages.WLB_NO_PERMISSION_BLURB, rbacUser);
                }
                else
                {
                    statusMessage = string.Format(Messages.WLB_ENABLED_BLURB, _pool.Name);
                }

                labelStatus.Text           = statusMessage;
                buttonReports.Enabled      = true;
                panelConfiguration.Visible = true;
                wlbOptimizePool.Visible    = true;
            }


            if (PassedRbacChecks())
            {
                //Show the buttons
                flowLayoutPanelLeftButtons.Visible = true;
                //panelButtons.Visible = true;
            }
            else
            {
                //disable and hide the buttons
                DisableButtons();
                flowLayoutPanelLeftButtons.Visible = false;
                //panelButtons.Visible = false;
            }
        }
Ejemplo n.º 14
0
        private void SaveConfig(Host host, Host.PowerOnMode mode)
        {
            var    newMode    = mode.ToString();
            var    config     = mode.Config;
            string secretuuid = "";


            if (newMode == "iLO" && Helpers.StockholmOrGreater(Connection))
            {
                //the UI should have already prevented us from getting here, but be defensive
                newMode = "";
                config  = new Dictionary <string, string>();
            }

            try
            {
                if (newMode == "DRAC" || newMode == "iLO" || newMode != "wake-on-lan" && newMode != "")
                {
                    if (config.ContainsKey("power_on_password_secret"))
                    {
                        secretuuid = Secret.CreateSecret(Session, config["power_on_password_secret"]);
                        config["power_on_password_secret"] = secretuuid;
                    }
                }
                else if (string.IsNullOrEmpty(newMode))
                {
                    //if WLB is on, we need to exclude the host from WLB power management,
                    //since we cannot turn it back on if it is powered down automatically

                    try
                    {
                        Pool pool = Helpers.GetPool(Connection);
                        if (pool != null && WlbServerState.GetState(pool) == WlbServerState.ServerState.Enabled)
                        {
                            var hostConfig = new WlbHostConfiguration(host.uuid)
                            {
                                ParticipatesInPowerManagement = false
                            };

                            var wlbAction = new SendWlbConfigurationAction(pool, hostConfig.ToDictionary(),
                                                                           SendWlbConfigurationKind.SetHostConfiguration);
                            wlbAction.RunExternal(Session);
                        }
                    }
                    catch
                    {
                        //Do nothing on failure.
                    }
                }

                Host.set_power_on_mode(Session, host.opaque_ref, newMode, config);
            }
            catch
            {
                if (!string.IsNullOrEmpty(secretuuid))
                {
                    string secretRef = Secret.get_by_uuid(Session, secretuuid);
                    Secret.destroy(Session, secretRef);
                }

                throw;
            }
        }
Ejemplo n.º 15
0
        protected void SaveConfig(Host host)
        {
            string secretuuid = "";

            try
            {
                Dictionary <string, string> powerONConfig = new Dictionary <string, string>();
                if (newMode == "DRAC" || newMode == "iLO")
                {
                    powerONConfig.Add("power_on_ip", ip);
                    powerONConfig.Add("power_on_user", user);
                    secretuuid = Secret.CreateSecret(Session, password);
                    powerONConfig.Add("power_on_password_secret", secretuuid);
                }
                else if (newMode != "wake-on-lan" && newMode != "")
                {
                    foreach (KeyValuePair <string, string> pair in customConfig)
                    {
                        if (pair.Key == "power_on_password_secret")
                        {
                            secretuuid = Secret.CreateSecret(Session, pair.Value);
                            powerONConfig.Add(pair.Key, secretuuid);
                        }
                        else
                        {
                            powerONConfig.Add(pair.Key, pair.Value);
                        }
                    }
                }
                else if (string.IsNullOrEmpty(newMode))
                {
                    // We don't want this bit to alter the function of the main action so...
                    try
                    {
                        Pool pool = Core.Helpers.GetPool(this.Connection);
                        if (null != pool)
                        {
                            if (WlbServerState.GetState(pool) == XenAdmin.Wlb.WlbServerState.ServerState.Enabled)
                            {
                                //Tell WLB to not allow this host to be powered down automatically, since we cannot turn it back on
                                WlbHostConfiguration hostConfig = new WlbHostConfiguration(host.uuid);
                                hostConfig.ParticipatesInPowerManagement = false;
                                //Use the existing SendWlbConfig action, as it wraps the config functionality
                                //  as well as the RBAC checks.
                                SendWlbConfigurationAction wlbAction = new SendWlbConfigurationAction(pool,
                                                                                                      hostConfig.ToDictionary(),
                                                                                                      SendWlbConfigurationKind.SetHostConfiguration);
                                wlbAction.RunExternal(Session);
                            }
                        }
                    }

                    catch (Exception)
                    {
                        //Do nothing on failure.
                    }
                }

                Host.set_power_on_mode(Session, host.opaque_ref, newMode, powerONConfig);
            }
            catch (Exception e)
            {
                if (!string.IsNullOrEmpty(secretuuid))
                {
                    string secretRef = Secret.get_by_uuid(Session, secretuuid);
                    Secret.destroy(Session, secretRef);
                }
                throw e;
            }
        }