protected override void Run() { try { log.Debug("Resuming WLB on pool " + Pool.Name()); XenAPI.Pool.set_wlb_enabled(this.Session, Pool.opaque_ref, true); log.Debug("Success resuming WLB on pool " + Pool.Name()); this.Description = Messages.COMPLETED; WlbServerState.SetState(this.Pool, WlbServerState.ServerState.Enabled); //Clear the Optimizing Pool flag in case it was left behind Helpers.SetOtherConfig(this.Session, this.Pool, OPTIMIZINGPOOL, string.Empty); log.Debug("Retrieving Workload Balancing configuration for pool " + Pool.Name()); this.WlbConfiguration = XenAPI.Pool.retrieve_wlb_configuration(this.Session); log.Debug("Success retrieving Workload Balancing configuration on pool " + Pool.Name()); this.Description = Messages.COMPLETED; } catch (Exception ex) { if (ex is Failure) { WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex); } throw ex; } }
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(); } } } }
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; }
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); } }
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(); }
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(); }
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(); } }
protected override void Run() { try { log.Debug("Retrieving Workload Balancing configuration for pool " + Pool.Name); this.WlbConfiguration = XenAPI.Pool.retrieve_wlb_configuration(this.Session); if (this.WlbConfiguration.Count == 0) { //We didn;t get a configuration, so there is somethign wrong log.Debug("Failure retrieving Workload Balancing configuration on pool " + Pool.Name); this.Description = Messages.FAILED; Failure f = new Failure(FriendlyErrorNames.WLB_NOT_INITIALIZED); throw f; } else { log.Debug("Success retrieving Workload Balancing configuration on pool " + Pool.Name); this.Description = Messages.COMPLETED; //Retrieving the configuration 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 (Helpers.WlbEnabled(Pool.Connection)) { WlbServerState.SetState(Pool, WlbServerState.ServerState.Enabled); } else { WlbServerState.SetState(Pool, WlbServerState.ServerState.Disabled); } } } catch (Exception ex) { if (ex is Failure) { // Retrieving the configuration error could also because WLB is not initialized if (((Failure)ex).Message == FriendlyErrorNames.WLB_NOT_INITIALIZED) { WlbServerState.SetState(Pool, WlbServerState.ServerState.NotConfigured); } else { WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex); } if (((Failure)ex).Message == FriendlyErrorNames.WLB_INTERNAL_ERROR) { Failure f = new Failure(new string[] { Messages.ResourceManager.GetString("WLB_ERROR_" + ((Failure)ex).ErrorDescription[1]) }); throw (f); } else { throw (ex); } } } }
protected override void Run() { if (_deconfigure) { try { if (!Helpers.WlbEnabled(Pool.Connection)) { log.Debug("Resuming WLB (prior to disconnecting) for pool " + Pool.Name); XenAPI.Pool.set_wlb_enabled(this.Session, Pool.opaque_ref, true); log.Debug("Success resuming WLB on pool " + Pool.Name); } log.Debug("Disconnecting Workload Balancing from pool " + Pool.Name + " and removing all pool data"); XenAPI.Pool.deconfigure_wlb(this.Session); log.Debug("Success disconnecting Workload Balancing on pool " + Pool.Name); this.Description = Messages.COMPLETED; WlbServerState.SetState(Pool, WlbServerState.ServerState.NotConfigured); } catch (Exception ex) { //Force disabling of WLB XenAPI.Pool.set_wlb_enabled(this.Session, Pool.opaque_ref, false); WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex); log.Debug(string.Format(Messages.ACTION_WLB_DECONFIGURE_FAILED, Pool.Name, ex.Message)); throw new Exception(string.Format(Messages.ACTION_WLB_DECONFIGURE_FAILED, Pool.Name, ex.Message)); } finally { //Clear the Optimizing Pool flag in case it was left behind Helpers.SetOtherConfig(this.Session, this.Pool, OPTIMIZINGPOOL, string.Empty); } } else { try { log.Debug("Pausing Workload Balancing on pool " + Pool.Name); XenAPI.Pool.set_wlb_enabled(this.Session, Pool.opaque_ref, false); log.Debug("Success pausing Workload Balancing on pool " + Pool.Name); this.Description = Messages.COMPLETED; WlbServerState.SetState(Pool, WlbServerState.ServerState.Disabled); } catch (Exception ex) { if (ex is Failure) { WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex); } throw ex; } finally { //Clear the Optimizing Pool flag in case it was left behind Helpers.SetOtherConfig(this.Session, this.Pool, OPTIMIZINGPOOL, string.Empty); } } }
private void SetControlState() { switch (WlbServerState.GetState(_pool)) { case WlbServerState.ServerState.NotConfigured: case WlbServerState.ServerState.ConnectionError: { decentGroupBoxWLBServerAddress.Enabled = true; break; } } }
/* 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; }
private void buttonEnableDisableWlb_Click(object sender, EventArgs e) { if (WlbServerState.GetState(_pool) != WlbServerState.ServerState.Enabled) { DisableButtons(); EnableWLB(); } else { DisableButtons(); DisableWLB(false); } }
protected override void Run() { log.Debug("Sending Workload Balancing configuration for pool " + Pool.Name); ClearKeys(); if ((_kind & SendWlbConfigurationKind.SetHostConfiguration) == SendWlbConfigurationKind.SetHostConfiguration) { this.WlbConfiguration.Add(SET_HOST_CONFIGURATION, "true"); } if ((_kind & SendWlbConfigurationKind.SetScheduledTask) == SendWlbConfigurationKind.SetScheduledTask) { this.WlbConfiguration.Add(SET_SCHEDULED_TASK, "true"); } if ((_kind & SendWlbConfigurationKind.DeleteScheduledTask) == SendWlbConfigurationKind.DeleteScheduledTask) { this.WlbConfiguration.Add(DELETE_SCHEDULED_TASK, "true"); } if ((_kind & SendWlbConfigurationKind.SetReportSubscription) == SendWlbConfigurationKind.SetReportSubscription) { this.WlbConfiguration.Add(SET_REPORT_SUBSCRIPTIONS, "true"); } if ((_kind & SendWlbConfigurationKind.DeleteReportSubscription) == SendWlbConfigurationKind.DeleteReportSubscription) { this.WlbConfiguration.Add(DELETE_REPORT_SUBSCRIPTIONS, "true"); } try { XenAPI.Pool.send_wlb_configuration(this.Session, this.WlbConfiguration); log.Debug("Successfully sent Workload Balancing configuration on pool " + Pool.Name); this.Description = Messages.COMPLETED; } catch (Exception ex) { if (ex is Failure) { WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, (Failure)ex); if (((Failure)ex).Message == FriendlyErrorNames.WLB_INTERNAL_ERROR) { Failure f = new Failure(new string[] { Messages.ResourceManager.GetString("WLB_ERROR_" + ((Failure)ex).ErrorDescription[1]) }); throw (f); } else { throw (ex); } } } }
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); }
/* 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; }
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(); } }
private string getPoolWLBStatus(Pool pool) { return(String.Format(Messages.WLB_RECONFIGURE, String.IsNullOrEmpty(WlbServerState.GetFailureMessage(_pool)) ? string.Empty : WlbServerState.GetFailureMessage(_pool))); }
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; } }
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; } }
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; } }
protected override void Run() { if (vmOptList.Count == 0) { log.ErrorFormat("{0} has no VMs need to be optimized", Helpers.GetName(Pool)); return; } this.Description = Messages.ACTION_WLB_POOL_OPTIMIZING; try { log.Debug("Optimizing " + Pool.Name()); // for checking whether to display recommendations on optimize pool listview Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, Messages.IN_PROGRESS); int start = 0; int each = 90 / vmOptList.Count; foreach (KeyValuePair <VM, WlbOptimizationRecommendation> vmItem in vmOptList) { VM vm = vmItem.Key; if (vmItem.Key.is_control_domain) { log.Debug(vmItem.Value.powerOperation + " " + Helpers.GetName(vmItem.Value.toHost)); Host fromHost = vmItem.Value.fromHost; Helpers.SetOtherConfig(fromHost.Connection.Session, fromHost, WlbOptimizationRecommendation.OPTIMIZINGPOOL, vmItem.Value.recId.ToString()); AsyncAction hostAction = null; int waitingInterval = 10 * 1000; // default to 10s if (vmItem.Value.fromHost.IsLive()) { hostAction = new ShutdownHostAction(fromHost, AddHostToPoolCommand.NtolDialog); } else { hostAction = new HostPowerOnAction(fromHost); waitingInterval = 30 * 1000; // wait for 30s } hostAction.Completed += HostAction_Completed; hostAction.RunAsync(); while (!moveToNext) { if (!String.IsNullOrEmpty(hostActionError)) { throw new Exception(hostActionError); } else { //wait System.Threading.Thread.Sleep(waitingInterval); } } } else { log.Debug("Migrating VM " + vm.Name()); Host toHost = vmItem.Value.toHost; try { // check if there is a conflict with HA, start optimize if we can RelocateVmWithHa(this, vm, toHost, start, start + each, vmItem.Value.recId); } catch (Failure f) { // prompt to user if ha notl can be raised, if yes, continue long newNtol; if (RaiseHANotl(vm, f, out newNtol)) { DelegatedAsyncAction action = new DelegatedAsyncAction(vm.Connection, Messages.HA_LOWERING_NTOL, null, null, delegate(Session session) { // Set new ntol, then retry action XenAPI.Pool.set_ha_host_failures_to_tolerate(session, this.Pool.opaque_ref, newNtol); // ntol set succeeded, start new action Program.MainWindow.CloseActiveWizards(vm); new VMMigrateAction(vm, toHost).RunAsync(); }); action.RunAsync(); } else { Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, Messages.WLB_OPT_FAILED); this.Description = Messages.WLB_OPT_FAILED; throw; } } } start += each; // stop if user cancels optimize pool if (Cancelling) { throw new CancelledException(); } } this.Description = Messages.WLB_OPT_OK_NOTICE_TEXT; Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, optId); log.Debug("Completed optimizing " + Pool.Name()); } catch (Failure ex) { Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, optId); WlbServerState.SetState(Pool, WlbServerState.ServerState.ConnectionError, ex); throw; } catch (CancelledException) { Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, optId); throw; } catch (Exception ex) { log.Error(ex, ex); this.Description = Messages.WLB_OPT_FAILED; Helpers.SetOtherConfig(this.Session, this.Pool, WlbOptimizationRecommendation.OPTIMIZINGPOOL, optId); log.Debug("Optimizing " + Pool.Name() + " is failed"); } this.PercentComplete = 100; }