From bffe739b861fe4c7560557da6b364a10616e392d Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Tue, 9 May 2023 15:12:04 +0100 Subject: [PATCH 1/8] It was not possible to load a xapi database from the CLI. Signed-off-by: Konstantina Chremmou --- XenAdmin/Core/HelpersGUI.cs | 5 +++-- XenAdmin/Dialogs/AddServerDialog.cs | 2 +- XenAdmin/MainWindow.cs | 22 ++++++---------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/XenAdmin/Core/HelpersGUI.cs b/XenAdmin/Core/HelpersGUI.cs index 951c930a5..73ff1b7e1 100644 --- a/XenAdmin/Core/HelpersGUI.cs +++ b/XenAdmin/Core/HelpersGUI.cs @@ -82,10 +82,11 @@ namespace XenAdmin.Core /// The form to be brought to the front. public static void BringFormToFront(Form f) { + if (f == null) + return; + if (f.WindowState == FormWindowState.Minimized) - { f.WindowState = FormWindowState.Normal; - } f.BringToFront(); f.Activate(); diff --git a/XenAdmin/Dialogs/AddServerDialog.cs b/XenAdmin/Dialogs/AddServerDialog.cs index d809eb135..d1bf28e6a 100644 --- a/XenAdmin/Dialogs/AddServerDialog.cs +++ b/XenAdmin/Dialogs/AddServerDialog.cs @@ -172,7 +172,7 @@ namespace XenAdmin.Dialogs { conn.Hostname = server; conn.Port = ConnectionsManager.DEFAULT_XEN_PORT; - XenConnectionUI.ConnectToXapiDatabase(conn, this); + XenConnectionUI.ConnectToXapiDatabase(conn, Owner); } else if (!_changedPass) { diff --git a/XenAdmin/MainWindow.cs b/XenAdmin/MainWindow.cs index d5809ba4f..92f8e9490 100755 --- a/XenAdmin/MainWindow.cs +++ b/XenAdmin/MainWindow.cs @@ -35,6 +35,7 @@ using System.ComponentModel; using System.Configuration; using System.Diagnostics; using System.Drawing; +using System.IO; using System.Runtime.InteropServices; using System.Security.Permissions; using System.Text; @@ -116,7 +117,6 @@ namespace XenAdmin private readonly Dictionary> activePoolWizards = new Dictionary>(); private string[] _commandLineArgs; - private bool _launched; private static readonly System.Windows.Forms.Timer CheckForUpdatesTimer = new System.Windows.Forms.Timer(); @@ -729,13 +729,10 @@ namespace XenAdmin Password = args.Length > 3 ? args[3] : "" }; - if (ConnectionsManager.XenConnectionsContains(connection)) - break; - - lock (ConnectionsManager.ConnectionsLock) - ConnectionsManager.XenConnections.Add(connection); - - XenConnectionUI.BeginConnect(connection, true, null, false); + if (File.Exists(args[1])) + XenConnectionUI.ConnectToXapiDatabase(connection, this); + else + XenConnectionUI.BeginConnect(connection, true, this, false); break; default: log.Warn("CLI: Wrong syntax or unknown command line options."); @@ -743,14 +740,7 @@ namespace XenAdmin } } - if (_launched) - { - // if already running, draw the user's attention - HelpersGUI.BringFormToFront(this); - Activate(); - } - - _launched = true; + HelpersGUI.BringFormToFront(this); } #endregion From d6a11cee777c65e17252c0e536b74bd4b3d7bb65 Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Thu, 25 May 2023 01:33:47 +0100 Subject: [PATCH 2/8] Rewrote the PerfmonAlertOptionsPage to simplify the code and fix issue whereby the settings were saved even if nothing had changed. Signed-off-by: Konstantina Chremmou --- .../PerfmonAlertOptionsPage.Designer.cs | 3 +- .../SettingsPanels/PerfmonAlertOptionsPage.cs | 211 +++---- .../PerfmonAlertOptionsPage.ja.resx | 440 ++----------- .../PerfmonAlertOptionsPage.resx | 589 +++++++++--------- .../Perfmon/PerfmonOptionsDefinitionAction.cs | 54 +- XenModel/Alerts/PerfmonOptionsDefinition.cs | 284 --------- XenModel/XenAPI-Extensions/Pool.cs | 16 +- XenModel/XenModel.csproj | 1 - 8 files changed, 471 insertions(+), 1127 deletions(-) delete mode 100755 XenModel/Alerts/PerfmonOptionsDefinition.cs diff --git a/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.Designer.cs b/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.Designer.cs index 0e5c345bb..cc900a46d 100755 --- a/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.Designer.cs +++ b/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.Designer.cs @@ -63,7 +63,6 @@ namespace XenAdmin.SettingsPanels resources.ApplyResources(this.EmailNotificationCheckBox, "EmailNotificationCheckBox"); this.EmailNotificationCheckBox.Name = "EmailNotificationCheckBox"; this.EmailNotificationCheckBox.UseVisualStyleBackColor = false; - this.EmailNotificationCheckBox.CheckedChanged += new System.EventHandler(this.EmailNotificationCheckBox_CheckedChanged); // // groupBox1 // @@ -81,9 +80,9 @@ namespace XenAdmin.SettingsPanels // // MailLanguageComboBox // - resources.ApplyResources(this.MailLanguageComboBox, "MailLanguageComboBox"); this.MailLanguageComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.MailLanguageComboBox.FormattingEnabled = true; + resources.ApplyResources(this.MailLanguageComboBox, "MailLanguageComboBox"); this.MailLanguageComboBox.Name = "MailLanguageComboBox"; // // MailLanguageLabel diff --git a/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.cs b/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.cs index 33de0fe7a..f46528433 100755 --- a/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.cs +++ b/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.cs @@ -35,24 +35,25 @@ using System.Windows.Forms; using System.Text.RegularExpressions; using XenAPI; -using XenAdmin.Alerts; using XenAdmin.Actions; using XenAdmin.Core; +using XenCenterLib; namespace XenAdmin.SettingsPanels { public partial class PerfmonAlertOptionsPage : UserControl, IEditPage { - private IXenObject _XenModelObject; - private PerfmonOptionsDefinition _PerfmonOptions; + // match anything with an @ sign in the middle + private static readonly Regex emailRegex = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.IgnoreCase); - private bool _OrigEmailNotificationCheckBox; - private string _OrigEmailAddressTextBox; - private string _OrigSmtpServerAddrTextBox; - private string _OrigSmtpServerPortTextBox; - private string _OrigMailLanguageCode; - private bool _bSupportMailLanguage; + private IXenObject _XenModelObject; + + private bool _origEmailNotificationCheckBox; + private string _origEmailAddressTextBox; + private string _origSmtpServerAddrTextBox; + private string _origSmtpServerPortTextBox; + private int _origMailLanguageIndex; private readonly ToolTip InvalidParamToolTip; @@ -62,117 +63,112 @@ namespace XenAdmin.SettingsPanels Text = Messages.EMAIL_OPTIONS; - InvalidParamToolTip = new ToolTip(); - InvalidParamToolTip.IsBalloon = true; - InvalidParamToolTip.ToolTipIcon = ToolTipIcon.Warning; - InvalidParamToolTip.ToolTipTitle = Messages.INVALID_PARAMETER; - - MailLanguageComboBox.DataSource = new BindingSource(PerfmonOptionsDefinition.MailLanguageDataSource(), null); - MailLanguageComboBox.DisplayMember = "Value"; - MailLanguageComboBox.ValueMember = "Key"; - - EmailNotificationCheckBox_CheckedChanged(null, null); - } - - public String SubText - { - get + InvalidParamToolTip = new ToolTip { - if (!EmailNotificationCheckBox.Checked) - return Messages.NONE_DEFINED; + IsBalloon = true, + ToolTipIcon = ToolTipIcon.Warning, + ToolTipTitle = Messages.INVALID_PARAMETER + }; - return EmailAddressTextBox.Text; - } + MailLanguageComboBox.Items.Add(new ToStringWrapper(Messages.MAIL_LANGUAGE_ENGLISH_CODE, Messages.MAIL_LANGUAGE_ENGLISH_NAME)); + MailLanguageComboBox.Items.Add(new ToStringWrapper(Messages.MAIL_LANGUAGE_CHINESE_CODE, Messages.MAIL_LANGUAGE_CHINESE_NAME)); + MailLanguageComboBox.Items.Add(new ToStringWrapper(Messages.MAIL_LANGUAGE_JAPANESE_CODE, Messages.MAIL_LANGUAGE_JAPANESE_NAME)); } + public string SubText => EmailNotificationCheckBox.Checked ? EmailAddressTextBox.Text : Messages.NONE_DEFINED; + public Image Image => Images.StaticImages._000_Email_h32bit_16; - // match anything with an @ sign in the middle - private static readonly Regex emailRegex = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.IgnoreCase); - public static bool IsValidEmail(string s) + private static bool IsValidEmail(string s) { return emailRegex.IsMatch(s); } private bool IsValidSmtpAddress() { - return !SmtpServerAddrTextBox.Text.ToCharArray().Any((c) => c >= 128) && SmtpServerAddrTextBox.Text.Trim().Length > 0; - } - - public void SetMailLanguageComboBoxValue(String code) - { - if (_bSupportMailLanguage && PerfmonOptionsDefinition.MailLanguageHasCode(code)) - MailLanguageComboBox.SelectedValue = code; // Feature supported and code is valid - else - { - // Set default value - if (PerfmonOptionsDefinition.MailLanguageHasCode(BrandManager.PerfAlertMailDefaultLanguage)) - MailLanguageComboBox.SelectedValue = BrandManager.PerfAlertMailDefaultLanguage; - else - MailLanguageComboBox.SelectedIndex = 0; - } + return !SmtpServerAddrTextBox.Text.ToCharArray().Any(c => c >= 128) && SmtpServerAddrTextBox.Text.Trim().Length > 0; } public void SetXenObjects(IXenObject orig, IXenObject clone) { _XenModelObject = clone; - _bSupportMailLanguage = Helpers.InvernessOrGreater(_XenModelObject.Connection); - - Repopulate(); + Populate(); // Save original settings for change detection - _OrigEmailNotificationCheckBox = EmailNotificationCheckBox.Checked; - _OrigEmailAddressTextBox = EmailAddressTextBox.Text; - _OrigSmtpServerAddrTextBox = SmtpServerAddrTextBox.Text; - _OrigSmtpServerPortTextBox = SmtpServerPortTextBox.Text; + _origEmailNotificationCheckBox = EmailNotificationCheckBox.Checked; + _origEmailAddressTextBox = EmailAddressTextBox.Text; + _origSmtpServerAddrTextBox = SmtpServerAddrTextBox.Text; + _origSmtpServerPortTextBox = SmtpServerPortTextBox.Text; + _origMailLanguageIndex = MailLanguageComboBox.SelectedIndex; } - public void Repopulate() + + private void Populate() { - if (_XenModelObject == null) + var pool = Helpers.GetPoolOfOne(_XenModelObject?.Connection); + if (pool == null) return; - try - { - MailLanguageLabel.Visible = MailLanguageComboBox.Visible = _bSupportMailLanguage; - _PerfmonOptions = PerfmonOptionsDefinition.GetPerfmonOptionsDefinitions(_XenModelObject); - if (_PerfmonOptions != null) - { - EmailNotificationCheckBox.Checked = true; - EmailAddressTextBox.Text = _PerfmonOptions.MailDestination; - SmtpServerAddrTextBox.Text = PerfmonOptionsDefinition.GetSmtpServerAddress(_PerfmonOptions.MailHub); - SmtpServerPortTextBox.Text = PerfmonOptionsDefinition.GetSmtpPort(_PerfmonOptions.MailHub); + pool.other_config.TryGetValue(Pool.MAIL_DESTINATION_KEY_NAME, out var mailDestination); + pool.other_config.TryGetValue(Pool.SMTP_MAILHUB_KEY_NAME, out var mailHub); + pool.other_config.TryGetValue(Pool.MAIL_LANGUAGE_KEY_NAME, out var mailLanguageCode); - SetMailLanguageComboBoxValue(_PerfmonOptions.MailLanguageCode); - if (_bSupportMailLanguage) // Save original MailLanguageCode for change detection - _OrigMailLanguageCode = _PerfmonOptions.MailLanguageCode; - else - _OrigMailLanguageCode = null; - } - else - { - SetMailLanguageComboBoxValue(null); - _OrigMailLanguageCode = null; - } - } - catch + EmailNotificationCheckBox.Checked = !string.IsNullOrWhiteSpace(mailDestination) && !string.IsNullOrWhiteSpace(mailHub); + + if (!string.IsNullOrWhiteSpace(mailDestination)) + EmailAddressTextBox.Text = mailDestination.Trim(); + + if (!string.IsNullOrWhiteSpace(mailHub)) { - // ignored + string[] words = mailHub.Trim().Split(':'); + + if (words.Length > 0) + SmtpServerAddrTextBox.Text = words[0]; + + if (words.Length > 1) + SmtpServerPortTextBox.Text = words[1]; } + + bool isLangSupported = Helpers.InvernessOrGreater(pool.Connection); + + MailLanguageLabel.Visible = MailLanguageComboBox.Visible = isLangSupported; + + int index = -1; + + if (isLangSupported && !string.IsNullOrWhiteSpace(mailLanguageCode)) + index = IndexOfLangItem(mailLanguageCode.Trim()); + + if (index == -1) + index = IndexOfLangItem(BrandManager.PerfAlertMailDefaultLanguage); + + if (index == -1) + index = 0; + + MailLanguageComboBox.SelectedIndex = index; } - public bool HasChanged + private int IndexOfLangItem(string code) { - get + if (string.IsNullOrWhiteSpace(code)) + return -1; + + for (var index = 0; index < MailLanguageComboBox.Items.Count; index++) { - return ((_OrigEmailNotificationCheckBox != EmailNotificationCheckBox.Checked) || - (_OrigEmailAddressTextBox != EmailAddressTextBox.Text) || - (_OrigSmtpServerAddrTextBox != SmtpServerAddrTextBox.Text) || - (_OrigSmtpServerPortTextBox != SmtpServerPortTextBox.Text) || - (_bSupportMailLanguage && _OrigMailLanguageCode != MailLanguageComboBox.SelectedValue.ToString())); + var obj = MailLanguageComboBox.Items[index]; + if (obj is ToStringWrapper wrapper && wrapper.item.ToLower() == code.ToLower()) + return index; } + + return -1; } + public bool HasChanged => + _origEmailNotificationCheckBox != EmailNotificationCheckBox.Checked || + _origEmailAddressTextBox != EmailAddressTextBox.Text || + _origSmtpServerAddrTextBox != SmtpServerAddrTextBox.Text || + _origSmtpServerPortTextBox != SmtpServerPortTextBox.Text || + _origMailLanguageIndex != MailLanguageComboBox.SelectedIndex; + public void ShowLocalValidationMessages() { if (!IsValidEmail(EmailAddressTextBox.Text)) @@ -205,20 +201,9 @@ namespace XenAdmin.SettingsPanels } } - public bool ValidToSave - { - get - { - if (EmailNotificationCheckBox.Checked) - { - return IsValidEmail(EmailAddressTextBox.Text) && Util.IsValidPort(SmtpServerPortTextBox.Text) && IsValidSmtpAddress(); - } - else - { - return true; - } - } - } + public bool ValidToSave => + !EmailNotificationCheckBox.Checked || + IsValidEmail(EmailAddressTextBox.Text) && Util.IsValidPort(SmtpServerPortTextBox.Text) && IsValidSmtpAddress(); public void Cleanup() { @@ -227,25 +212,21 @@ namespace XenAdmin.SettingsPanels public AsyncAction SaveSettings() { - PerfmonOptionsDefinition perfmonOptions = null; // a null value will clear the definitions + // a null value will clear the definitions + string mailDestination = null; + string mailHub = null; + string mailLangCode = null; + if (EmailNotificationCheckBox.Checked) { - string smtpMailHub = SmtpServerAddrTextBox.Text + ":" + SmtpServerPortTextBox.Text; - string mailLanguageCode = null; - if (_bSupportMailLanguage && null != MailLanguageComboBox.SelectedValue) - mailLanguageCode = MailLanguageComboBox.SelectedValue.ToString(); - perfmonOptions = new PerfmonOptionsDefinition(smtpMailHub, EmailAddressTextBox.Text, mailLanguageCode); + mailDestination = EmailAddressTextBox.Text; + mailHub = SmtpServerAddrTextBox.Text + ":" + SmtpServerPortTextBox.Text; + + if (MailLanguageComboBox.Visible && MailLanguageComboBox.SelectedValue != null) + mailLangCode = MailLanguageComboBox.SelectedValue.ToString(); } - return new PerfmonOptionsDefinitionAction(_XenModelObject.Connection, perfmonOptions, true); - } - - private void EmailNotificationCheckBox_CheckedChanged(object sender, EventArgs e) - { - EmailAddressTextBox.Enabled = EmailNotificationCheckBox.Checked; - SmtpServerAddrTextBox.Enabled = EmailNotificationCheckBox.Checked; - SmtpServerPortTextBox.Enabled = EmailNotificationCheckBox.Checked; - MailLanguageComboBox.Enabled = EmailNotificationCheckBox.Checked; + return new PerfmonOptionsDefinitionAction(_XenModelObject.Connection, mailDestination, mailHub, mailLangCode, true); } } } diff --git a/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.ja.resx b/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.ja.resx index 6a052e9c3..79a087c8f 100755 --- a/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.ja.resx +++ b/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.ja.resx @@ -59,46 +59,46 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - - - + + + - + - - - - + + + + - - + + - - + + - - - - + + + + - + - + @@ -117,409 +117,65 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="SendEmailNoteLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="EmailNotificationCheckBox" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="groupBox1" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,Percent,100,Absolute,20" /></TableLayoutSettings> + + サーバーによりシステム アラートが生成されたときにメールが送信されるように設定できます。このプールまたはスタンドアロン サーバーでこの機能を有効にするには、アラート通知メールの送信先アドレスを入力してください。 - - NoControl - - + - 160, 17 + 164, 17 アラートをメールで送信する(&E) - - NoControl - - - 2 - - - Fill - - - 22, 5, 3, 3 - - - 0 - - - SmtpServerPortTextBox - - - 74, 13 - - - - 0 - - - SmtpServerLabel - - - PerfmonAlertOptionsPage - - - 388, 45 - - - False - - - True - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 59, 20 - - - $this - - - 4 - - - メール言語(&L): - - - MailLanguageComboBox - - - 0, 0 - - - 0, 0 - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 76, 13 - - - 485, 333 - - - groupBox1 - - - 1 - - - 4 - - - False - - - 0 - - - 送信先 - - - 3 - - - 210, 20 - - - MiddleLeft - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 29, 13 - - - 3, 3, 3, 0 - - - 31 - - - True - - - MiddleLeft - - - True - - - tableLayoutPanel1 - - - 1 - - - MiddleLeft - - - 2 - - - GrowAndShrink - - - 9 - - - True - - - groupBox1 - - - 0 - - - 25 - - - 5 - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - NoControl - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - ポート(&P): - - - 0, 0, 0, 0 - - - EmailAddressLabel - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 + + 113, 71 210, 21 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 74, 13 - - 8, 48 + + メール言語(&L): - - SmtpServerAddrTextBox + + 51, 13 - - 5, 9, 5, 0 + + ポート(&P): - - tableLayoutPanel1 + + 388, 45 - - SendEmailNoteLabel - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - groupBox1 - - - 22, 77 - - - SMTP サーバー(&S): - - - MailLanguageLabel - - - 455, 108 - - - NoControl - - - Top, Left, Right - - - 7 - - - サーバーによりシステム アラートが生成されたときにメールが送信されるように設定できます。このプールまたはスタンドアロン サーバーでこの機能を有効にするには、アラート通知メールの送信先アドレスを入力してください。 - - - 0, 0, 0, 10 + + 59, 20 113, 19 - - 113, 71 + + 334, 20 - - True - - - tableLayoutPanel1 - - - groupBox1 - - - 6 - - - XenAdmin.Controls.DecentGroupBox, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null - - - 1 - - - Top, Right - - - Top, Left, Right - - - groupBox1 - - - NoControl - - - SmtpPortLabel - - - 8, 74 - - - 7 + + 92, 13 メール アドレス(&M): - - 485, 333 - - - 8 - - - 5 - - - 6 - - - 330, 48 - - - 334, 20 - 113, 45 - - 75, 13 + + 210, 20 - - Fill + + 96, 13 - - 32 + + SMTP サーバー(&S): - - 3 + + 送信先 - - True - - - groupBox1 - - - True - - - EmailNotificationCheckBox - - - groupBox1 - - - Top, Right - - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - MiddleLeft - - - 3 - - - 3, 3, 3, 0 - - - 2 - - - System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 8, 22 - - - No - - - 485, 39 - - - 32 - - - 3, 52 - - - EmailAddressTextBox - - - NoControl - - - 96, 96 - - - True - - - ja - \ No newline at end of file diff --git a/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.resx b/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.resx index 1dfce8efa..a56f3f9b3 100755 --- a/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.resx +++ b/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.resx @@ -117,409 +117,394 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 1 + + + True + - - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="SendEmailNoteLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="EmailNotificationCheckBox" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="groupBox1" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,Percent,100,Absolute,20" /></TableLayoutSettings> - - - NoControl - - - - 160, 17 - - - Send &email alert notifications + + Fill NoControl - - 2 + + + 0, 0 - - Fill + + 0, 0, 0, 10 - - 22, 5, 3, 3 + + 485, 26 - + + 32 + + + If you want to be notified via email when alerts are generated for your system's resources, enter an address where email notifications will be sent. + + + SendEmailNoteLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + 0 - - SmtpServerPortTextBox + + True - - 74, 13 + + NoControl + + + 3, 39 + + + 160, 17 - 0 - - SmtpServerLabel + + Send email alert &notifications - - PerfmonAlertOptionsPage + + EmailNotificationCheckBox - - 368, 45 + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 1 + + + True + + + GrowAndShrink + + + 100, 71 + + + No + + + 220, 21 + + + 9 False - - True - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 79, 20 - - - $this - - - 4 - - - Mail &language: - MailLanguageComboBox - - 0, 0 + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 0, 0 + + groupBox1 - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 0 + + + True + + + NoControl + + + 8, 74 76, 13 - - 485, 333 + + 8 - + + &Mail language: + + + False + + + MailLanguageLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + groupBox1 1 - - 4 + + Top, Right - - False - - - 0 - - - Delivery address - - - 3 - - - 220, 20 - - - MiddleLeft - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 29, 13 - - - 3, 3, 3, 0 - - - 31 - - + True - - MiddleLeft - - - True - - - tableLayoutPanel1 - - - 1 - - - MiddleLeft - - - 2 - - - GrowAndShrink - - - 9 - - - True - - - groupBox1 - - - 0 - - - 25 - - - 5 - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - + NoControl - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - &Port: + + 330, 48 0, 0, 0, 0 - - EmailAddressLabel + + 29, 13 - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 6 + + + &Port: + + + SmtpPortLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 2 + + + Top, Right + + + 368, 45 + + + 3, 3, 3, 0 + + + 79, 20 + + + 7 + + + 25 + + + SmtpServerPortTextBox + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 groupBox1 - - 220, 21 + + 3 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 8, 48 - - - SmtpServerAddrTextBox - - - 5, 9, 5, 0 - - - tableLayoutPanel1 - - - SendEmailNoteLabel - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - groupBox1 - - - 22, 77 - - - &SMTP Server: - - - MailLanguageLabel - - - 455, 108 - - - NoControl - - + Top, Left, Right - - 7 - - - The server can update you by email regarding system alerts that are being generated by your managed servers. To enable this feature, enter an address where email notifications will be sent for the servers and VMs in this pool (or for this standalone server). - - - 0, 0, 0, 10 - 100, 19 - - 100, 71 + + 347, 20 + + + 3 + + + EmailAddressTextBox + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 4 True - - tableLayoutPanel1 + + NoControl - + + 8, 22 + + + 75, 13 + + + 2 + + + &Email address: + + + EmailAddressLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 5 + + + Top, Left, Right + + + 100, 45 + + + 3, 3, 3, 0 + + + 220, 20 + + + 5 + + + SmtpServerAddrTextBox + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + groupBox1 6 - - XenAdmin.Controls.DecentGroupBox, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + + True - - 1 + + NoControl - - Top, Right + + 8, 48 - - Top, Left, Right + + 74, 13 + + + 4 + + + &SMTP Server: + + + SmtpServerLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 groupBox1 - - NoControl - - - SmtpPortLabel - - - 8, 74 - - + 7 - - E&mail address: + + 22, 64 - - 485, 333 + + 22, 5, 3, 3 - - 8 + + 5, 9, 5, 0 - - 5 + + 455, 108 - - 6 + + 31 - - 330, 48 - - - 347, 20 - - - 100, 45 - - - 75, 13 - - - Fill - - - 32 - - - 3 - - - True - - - groupBox1 - - - True - - - EmailNotificationCheckBox + + Delivery address groupBox1 - - Top, Right + + XenAdmin.Controls.DecentGroupBox, [XenCenter_No_Space], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null - - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - MiddleLeft - - - 3 - - - 3, 3, 3, 0 + + tableLayoutPanel1 2 - - System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Fill - - 8, 22 + + 0, 0 - - No + + 3 - - 485, 39 + + 485, 333 32 - - 3, 52 + + tableLayoutPanel1 - - EmailAddressTextBox + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - NoControl + + $this - - 96, 96 + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="SendEmailNoteLabel" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="EmailNotificationCheckBox" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="groupBox1" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,Percent,100,Absolute,20" /></TableLayoutSettings> True - - ja - + + 96, 96 + + + 485, 333 + + + PerfmonAlertOptionsPage + + + System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/XenModel/Actions/Perfmon/PerfmonOptionsDefinitionAction.cs b/XenModel/Actions/Perfmon/PerfmonOptionsDefinitionAction.cs index 93ef417e4..abd95a730 100755 --- a/XenModel/Actions/Perfmon/PerfmonOptionsDefinitionAction.cs +++ b/XenModel/Actions/Perfmon/PerfmonOptionsDefinitionAction.cs @@ -28,7 +28,6 @@ * SUCH DAMAGE. */ -using XenAdmin.Alerts; using XenAdmin.Core; using XenAdmin.Network; using XenAPI; @@ -38,49 +37,54 @@ namespace XenAdmin.Actions { public class PerfmonOptionsDefinitionAction : AsyncAction { - private readonly Pool pool; - private readonly PerfmonOptionsDefinition perfmonOptions; + private readonly Pool _pool; + private readonly string _mailDestination; + private readonly string _mailHub; + private readonly string _mailLangCode; - public PerfmonOptionsDefinitionAction(IXenConnection connection, PerfmonOptionsDefinition perfmonOptions, bool suppressHistory) + public PerfmonOptionsDefinitionAction(IXenConnection connection, string mailDestination, string mailHub, string mailLangCode, bool suppressHistory) : base(connection, Messages.ACTION_CHANGE_EMAIL_OPTIONS, suppressHistory) { - this.perfmonOptions = perfmonOptions; - pool = Helpers.GetPoolOfOne(connection); - Description = string.Format(Messages.ACTION_CHANGING_EMAIL_OPTIONS_FOR, pool); + _mailDestination = mailDestination; + _mailHub = mailHub; + _mailLangCode = mailLangCode; + _pool = Helpers.GetPoolOfOne(connection); - ApiMethodsToRoleCheck.AddWithKey("pool.remove_from_other_config", PerfmonOptionsDefinition.MAIL_DESTINATION_KEY_NAME); - ApiMethodsToRoleCheck.AddWithKey("pool.remove_from_other_config", PerfmonOptionsDefinition.SMTP_MAILHUB_KEY_NAME); - ApiMethodsToRoleCheck.AddWithKey("pool.remove_from_other_config", PerfmonOptionsDefinition.MAIL_LANGUAGE_KEY_NAME); + Description = string.Format(Messages.ACTION_CHANGING_EMAIL_OPTIONS_FOR, _pool); - if (perfmonOptions != null) + ApiMethodsToRoleCheck.AddWithKey("pool.remove_from_other_config", Pool.MAIL_DESTINATION_KEY_NAME); + ApiMethodsToRoleCheck.AddWithKey("pool.remove_from_other_config", Pool.SMTP_MAILHUB_KEY_NAME); + ApiMethodsToRoleCheck.AddWithKey("pool.remove_from_other_config", Pool.MAIL_LANGUAGE_KEY_NAME); + + if (_mailDestination != null && _mailHub != null) { - ApiMethodsToRoleCheck.AddWithKey("pool.add_to_other_config", PerfmonOptionsDefinition.MAIL_DESTINATION_KEY_NAME); - ApiMethodsToRoleCheck.AddWithKey("pool.add_to_other_config", PerfmonOptionsDefinition.SMTP_MAILHUB_KEY_NAME); + ApiMethodsToRoleCheck.AddWithKey("pool.add_to_other_config", Pool.MAIL_DESTINATION_KEY_NAME); + ApiMethodsToRoleCheck.AddWithKey("pool.add_to_other_config", Pool.SMTP_MAILHUB_KEY_NAME); - if (perfmonOptions.MailLanguageCode != null) - ApiMethodsToRoleCheck.AddWithKey("pool.add_to_other_config", PerfmonOptionsDefinition.MAIL_LANGUAGE_KEY_NAME); + if (_mailLangCode != null) + ApiMethodsToRoleCheck.AddWithKey("pool.add_to_other_config", Pool.MAIL_LANGUAGE_KEY_NAME); } } protected override void Run() { - if (pool == null) + if (_pool == null) return; - Pool.remove_from_other_config(Session, pool.opaque_ref, PerfmonOptionsDefinition.MAIL_DESTINATION_KEY_NAME); + Pool.remove_from_other_config(Session, _pool.opaque_ref, Pool.MAIL_DESTINATION_KEY_NAME); - if (perfmonOptions != null) - Pool.add_to_other_config(Session, pool.opaque_ref, PerfmonOptionsDefinition.MAIL_DESTINATION_KEY_NAME, perfmonOptions.MailDestination); + if (_mailDestination != null) + Pool.add_to_other_config(Session, _pool.opaque_ref, Pool.MAIL_DESTINATION_KEY_NAME, _mailDestination); - Pool.remove_from_other_config(Session, pool.opaque_ref, PerfmonOptionsDefinition.SMTP_MAILHUB_KEY_NAME); + Pool.remove_from_other_config(Session, _pool.opaque_ref, Pool.SMTP_MAILHUB_KEY_NAME); - if (perfmonOptions != null) - Pool.add_to_other_config(Session, pool.opaque_ref, PerfmonOptionsDefinition.SMTP_MAILHUB_KEY_NAME, perfmonOptions.MailHub); + if (_mailHub != null) + Pool.add_to_other_config(Session, _pool.opaque_ref, Pool.SMTP_MAILHUB_KEY_NAME, _mailHub); - Pool.remove_from_other_config(Session, pool.opaque_ref, PerfmonOptionsDefinition.MAIL_LANGUAGE_KEY_NAME); + Pool.remove_from_other_config(Session, _pool.opaque_ref, Pool.MAIL_LANGUAGE_KEY_NAME); - if (perfmonOptions?.MailLanguageCode != null) - Pool.add_to_other_config(Session, pool.opaque_ref, PerfmonOptionsDefinition.MAIL_LANGUAGE_KEY_NAME, perfmonOptions.MailLanguageCode); + if (_mailLangCode != null) + Pool.add_to_other_config(Session, _pool.opaque_ref, Pool.MAIL_LANGUAGE_KEY_NAME, _mailLangCode); } } } diff --git a/XenModel/Alerts/PerfmonOptionsDefinition.cs b/XenModel/Alerts/PerfmonOptionsDefinition.cs deleted file mode 100755 index 6863ccfa8..000000000 --- a/XenModel/Alerts/PerfmonOptionsDefinition.cs +++ /dev/null @@ -1,284 +0,0 @@ -/* Copyright (c) Cloud Software Group, Inc. - * - * Redistribution and use in source and binary forms, - * with or without modification, are permitted provided - * that the following conditions are met: - * - * * Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -using System; -using System.Collections.Generic; -using XenAPI; -using XenAdmin.Network; -using XenAdmin.Core; - -namespace XenAdmin.Alerts -{ - public class PerfmonOptionsDefinition - { - public const String MAIL_DESTINATION_KEY_NAME = "mail-destination"; - public const String SMTP_MAILHUB_KEY_NAME = "ssmtp-mailhub"; - public const String MAIL_LANGUAGE_KEY_NAME = "mail-language"; - - private class MailLanguageList - { - private Dictionary _list; - - public MailLanguageList(Dictionary initList) - { - _list = new Dictionary(initList); - } - - public String CodeFromName(String name) - { - String ret = null; - - if (null == name) - return ret; - - foreach(KeyValuePair pair in _list) - { - if(pair.Value == name) - { - ret = pair.Key; - break; - } - } - - return ret; - } - - public String NameFromCode(String code) - { - String ret = null; - - if (null == code) - return ret; - - foreach (KeyValuePair pair in _list) - { - if (pair.Key == code) - { - ret = pair.Value; - break; - } - } - - return ret; - } - - public bool HasCode(String code) - { - return null == code ? false : _list.ContainsKey(code); - } - - public Dictionary dataSource() - { - return new Dictionary(_list); - } - } - - private static readonly char[] mailHubDelim = new char[] { ':' }; - private readonly String mailHub; - private readonly String mailDestination; - private readonly String mailLanguageCode; - - private static MailLanguageList ml_list = new MailLanguageList(new Dictionary() { - {Messages.MAIL_LANGUAGE_ENGLISH_CODE, Messages.MAIL_LANGUAGE_ENGLISH_NAME}, - {Messages.MAIL_LANGUAGE_CHINESE_CODE, Messages.MAIL_LANGUAGE_CHINESE_NAME}, - {Messages.MAIL_LANGUAGE_JAPANESE_CODE, Messages.MAIL_LANGUAGE_JAPANESE_NAME} - }); - - public PerfmonOptionsDefinition(String mailHub, String mailDestination, String mailLanguageCode) - { - this.mailHub = mailHub; - this.mailDestination = mailDestination; - this.mailLanguageCode = mailLanguageCode; - } - - public String MailHub - { - get - { - return mailHub; - } - } - - public String MailDestination - { - get - { - return mailDestination; - } - } - - public String MailLanguageCode - { - get - { - return mailLanguageCode; - } - } - - public String MailLanguageName - { - get - { - return ml_list.NameFromCode(mailLanguageCode); - } - } - - public static String GetSmtpServerAddress(string mailHub) - { - try - { - string[] words = mailHub.Split(mailHubDelim); - if (words.Length > 0) - { - return words[0]; - } - } - catch - { - // ignored - } - - return ""; - } - - public static String GetSmtpPort(string mailHub) - { - try - { - string[] words = mailHub.Split(mailHubDelim); - if (words.Length > 1) - { - return words[1]; - } - } - catch - { - // ignored - } - - return "25"; - } - - public override string ToString() - { - return String.Format("mail-destination: {0} ssmtp-mailhub: {1}", MailDestination, MailHub); - } - - public static PerfmonOptionsDefinition GetPerfmonOptionsDefinitions(IXenObject xmo) - { - if (xmo == null) - return null; - - IXenConnection connection = xmo.Connection; - if (connection == null) - return null; - - string mailDestination = GetMailDestination(connection); - string mailHub = GetSmtpMailHub(connection); - string mailLanguageCode = GetMailLanguageCode(connection); - - if (mailDestination == null || mailHub == null) - return null; - - return new PerfmonOptionsDefinition(mailHub, mailDestination, mailLanguageCode); - } - - public static string GetMailDestination(IXenConnection connection) - { - var pool = Helpers.GetPoolOfOne(connection); - if (pool == null) - return null; - - var otherConfig = Helpers.GetOtherConfig(pool); - if (otherConfig == null) - return null; - - if (!otherConfig.ContainsKey(MAIL_DESTINATION_KEY_NAME)) - return null; - - var mailAddress = otherConfig[MAIL_DESTINATION_KEY_NAME]?.Trim(); - return string.IsNullOrEmpty(mailAddress) ? null : mailAddress; - } - - public static string GetSmtpMailHub(IXenConnection connection) - { - var pool = Helpers.GetPoolOfOne(connection); - if (pool == null) - return null; - - var otherConfig = Helpers.GetOtherConfig(pool); - if (otherConfig == null) - return null; - - if (!otherConfig.ContainsKey(SMTP_MAILHUB_KEY_NAME)) - return null; - - var mailHub = otherConfig[SMTP_MAILHUB_KEY_NAME]?.Trim(); - return string.IsNullOrEmpty(mailHub) ? null : mailHub; - } - - public static string GetMailLanguageCode(IXenConnection connection) - { - var pool = Helpers.GetPoolOfOne(connection); - if (pool == null) - return null; - - var otherConfig = Helpers.GetOtherConfig(pool); - if (otherConfig == null) - return null; - - if (!otherConfig.ContainsKey(MAIL_LANGUAGE_KEY_NAME)) - return null; - - var mailLanguageCode = otherConfig[MAIL_LANGUAGE_KEY_NAME]?.Trim(); - return string.IsNullOrEmpty(mailLanguageCode) ? null : mailLanguageCode; - } - - public static String MailLanguageNameFromCode(String code) - { - return ml_list.NameFromCode(code); - } - - public static String MailLanguageCodeFromName(String name) - { - return ml_list.CodeFromName(name); - } - - public static bool MailLanguageHasCode(String code) - { - return ml_list.HasCode(code); - } - - public static object MailLanguageDataSource() - { - return PerfmonOptionsDefinition.ml_list.dataSource(); - } - } -} diff --git a/XenModel/XenAPI-Extensions/Pool.cs b/XenModel/XenAPI-Extensions/Pool.cs index 7da6104c0..138328a01 100644 --- a/XenModel/XenAPI-Extensions/Pool.cs +++ b/XenModel/XenAPI-Extensions/Pool.cs @@ -38,6 +38,16 @@ namespace XenAPI { public partial class Pool : IComparable, IEquatable { + private const string ROLLING_UPGRADE_IN_PROGRESS = "rolling_upgrade_in_progress"; + private const string FORBID_RPU_FOR_HCI = "hci-forbid-rpu"; + private const string FAULT_TOLERANCE_LIMIT_FOR_HCI = "hci-limit-fault-tolerance"; + private const string FORBID_UPDATE_AUTO_RESTARTS = "hci-forbid-update-auto-restart"; + public const string HEALTH_CHECK_ENROLLMENT = "Enrollment"; + + public const string MAIL_DESTINATION_KEY_NAME = "mail-destination"; + public const string SMTP_MAILHUB_KEY_NAME = "ssmtp-mailhub"; + public const string MAIL_LANGUAGE_KEY_NAME = "mail-language"; + public override string ToString() { return Name(); @@ -107,12 +117,6 @@ namespace XenAPI return Connection != null && (name_label != "" || Connection.Cache.HostCount > 1); } - private const string ROLLING_UPGRADE_IN_PROGRESS = "rolling_upgrade_in_progress"; - private const string FORBID_RPU_FOR_HCI = "hci-forbid-rpu"; - private const string FAULT_TOLERANCE_LIMIT_FOR_HCI = "hci-limit-fault-tolerance"; - private const string FORBID_UPDATE_AUTO_RESTARTS = "hci-forbid-update-auto-restart"; - public const string HEALTH_CHECK_ENROLLMENT = "Enrollment"; - public bool RollingUpgrade() { return other_config != null && other_config.ContainsKey(ROLLING_UPGRADE_IN_PROGRESS); diff --git a/XenModel/XenModel.csproj b/XenModel/XenModel.csproj index 3a6a9a7e8..2e84ed39f 100755 --- a/XenModel/XenModel.csproj +++ b/XenModel/XenModel.csproj @@ -304,7 +304,6 @@ - InvisibleMessages.resx True From a191ccf3ec74dd8e8c7db66445dbaf66706a6847 Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Thu, 1 Jun 2023 03:15:25 +0100 Subject: [PATCH 3/8] Fixed issue where the XenObject was not correctly locked when saving changes. Also, renamed field to match C# naming conventions. Signed-off-by: Konstantina Chremmou --- XenAdmin/Dialogs/PropertiesDialog.cs | 81 ++++++++++++++-------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/XenAdmin/Dialogs/PropertiesDialog.cs b/XenAdmin/Dialogs/PropertiesDialog.cs index b098342c3..b9016dc21 100755 --- a/XenAdmin/Dialogs/PropertiesDialog.cs +++ b/XenAdmin/Dialogs/PropertiesDialog.cs @@ -83,7 +83,7 @@ namespace XenAdmin.Dialogs private PoolAdvancedEditPage _poolAdvancedEditPage; #endregion - private IXenObject xenObject, xenObjectBefore, xenObjectCopy; + private readonly IXenObject _xenObjectBefore, _xenObjectCopy; private AsyncAction _action; private bool _startAction = true; private System.Timers.Timer timer = new System.Timers.Timer(); @@ -98,12 +98,11 @@ namespace XenAdmin.Dialogs InitializeComponent(); - this.xenObject = xenObject; - xenObjectBefore = xenObject.Clone(); - xenObjectCopy = xenObject.Clone(); + _xenObjectBefore = xenObject; + _xenObjectCopy = xenObject.Clone(); - Name = String.Format("Edit{0}GeneralSettingsDialog", xenObject.GetType().Name); - Text = String.Format(Messages.PROPERTIES_DIALOG_TITLE, Helpers.GetName(xenObject)); + Name = string.Format("Edit{0}GeneralSettingsDialog", xenObject.GetType().Name); + Text = string.Format(Messages.PROPERTIES_DIALOG_TITLE, Helpers.GetName(xenObject)); if (!Application.RenderWithVisualStyles) ContentPanel.BackColor = SystemColors.Control; @@ -115,25 +114,25 @@ namespace XenAdmin.Dialogs { var pool = Helpers.GetPoolOfOne(connection); - bool is_host = xenObjectCopy is Host; - bool is_vm = xenObjectCopy is VM && !((VM)xenObjectCopy).is_a_snapshot; - bool is_sr = xenObjectCopy is SR; + bool is_host = _xenObjectCopy is Host; + bool is_vm = _xenObjectCopy is VM && !((VM)_xenObjectCopy).is_a_snapshot; + bool is_sr = _xenObjectCopy is SR; - bool is_pool = xenObjectCopy is Pool; - bool is_vdi = xenObjectCopy is VDI; - bool is_network = xenObjectCopy is XenAPI.Network; + bool is_pool = _xenObjectCopy is Pool; + bool is_vdi = _xenObjectCopy is VDI; + bool is_network = _xenObjectCopy is XenAPI.Network; - bool is_hvm = is_vm && ((VM)xenObjectCopy).IsHVM(); - bool is_template = is_vm && ((VM)xenObjectCopy).is_a_template; - bool is_in_pool = Helpers.GetPool(xenObjectCopy.Connection) != null; + bool is_hvm = is_vm && ((VM)_xenObjectCopy).IsHVM(); + bool is_template = is_vm && ((VM)_xenObjectCopy).is_a_template; + bool is_in_pool = Helpers.GetPool(_xenObjectCopy.Connection) != null; bool is_pool_or_standalone = is_pool || (is_host && !is_in_pool); - bool wlb_enabled = (Helpers.WlbEnabledAndConfigured(xenObjectCopy.Connection)); + bool wlb_enabled = (Helpers.WlbEnabledAndConfigured(_xenObjectCopy.Connection)); - bool is_VM_appliance = xenObjectCopy is VM_appliance; + bool is_VM_appliance = _xenObjectCopy is VM_appliance; - bool is_VMSS = xenObjectCopy is VMSS; + bool is_VMSS = _xenObjectCopy is VMSS; ContentPanel.SuspendLayout(); verticalTabs.BeginUpdate(); @@ -158,7 +157,7 @@ namespace XenAdmin.Dialogs if (is_vm || is_host || is_sr) { - if (Helpers.FeatureForbidden(xenObjectCopy, Host.RestrictAlerts)) + if (Helpers.FeatureForbidden(_xenObjectCopy, Host.RestrictAlerts)) { PerfmonAlertUpsellEditPage = new UpsellPage { @@ -177,7 +176,7 @@ namespace XenAdmin.Dialogs if (is_pool_or_standalone) { - if (Helpers.FeatureForbidden(xenObjectCopy, Host.RestrictAlerts)) + if (Helpers.FeatureForbidden(_xenObjectCopy, Host.RestrictAlerts)) { PerfmonAlertOptionsUpsellEditPage = new UpsellPage { @@ -202,22 +201,22 @@ namespace XenAdmin.Dialogs if (is_host || is_pool) ShowTab(HostPowerONEditPage = new HostPowerONEditPage()); - if ((is_pool_or_standalone && Helpers.VGpuCapability(xenObjectCopy.Connection)) - || (is_host && ((Host)xenObjectCopy).CanEnableDisableIntegratedGpu())) + if ((is_pool_or_standalone && Helpers.VGpuCapability(_xenObjectCopy.Connection)) + || (is_host && ((Host)_xenObjectCopy).CanEnableDisableIntegratedGpu())) { ShowTab(PoolGpuEditPage = new PoolGpuEditPage()); } - if (is_pool_or_standalone && !Helpers.FeatureForbidden(xenObject.Connection, Host.RestrictSslLegacySwitch) && !Helpers.StockholmOrGreater(connection)) + if (is_pool_or_standalone && !Helpers.FeatureForbidden(_xenObjectCopy.Connection, Host.RestrictSslLegacySwitch) && !Helpers.StockholmOrGreater(connection)) ShowTab(SecurityEditPage = new SecurityEditPage()); - if (is_pool_or_standalone && !Helpers.FeatureForbidden(xenObject.Connection, Host.RestrictIGMPSnooping) && Helpers.GetCoordinator(pool).vSwitchNetworkBackend()) + if (is_pool_or_standalone && !Helpers.FeatureForbidden(_xenObjectCopy.Connection, Host.RestrictIGMPSnooping) && Helpers.GetCoordinator(pool).vSwitchNetworkBackend()) ShowTab(NetworkOptionsEditPage = new NetworkOptionsEditPage()); - if (is_pool_or_standalone && !Helpers.FeatureForbidden(xenObject.Connection, Host.RestrictCorosync)) + if (is_pool_or_standalone && !Helpers.FeatureForbidden(_xenObjectCopy.Connection, Host.RestrictCorosync)) ShowTab(ClusteringEditPage = new ClusteringEditPage()); - if (is_pool && Helpers.Post82X(xenObject.Connection) && Helpers.XapiEqualOrGreater_22_33_0(xenObject.Connection)) + if (is_pool && Helpers.Post82X(_xenObjectCopy.Connection) && Helpers.XapiEqualOrGreater_22_33_0(_xenObjectCopy.Connection)) ShowTab(_poolAdvancedEditPage = new PoolAdvancedEditPage()); if (is_network) @@ -226,9 +225,9 @@ namespace XenAdmin.Dialogs if (is_vm && !wlb_enabled) ShowTab(HomeServerPage = new HomeServerEditPage()); - if (is_vm && ((VM)xenObjectCopy).CanHaveGpu()) + if (is_vm && ((VM)_xenObjectCopy).CanHaveGpu()) { - if (Helpers.FeatureForbidden(xenObjectCopy, Host.RestrictGpu)) + if (Helpers.FeatureForbidden(_xenObjectCopy, Host.RestrictGpu)) { GpuUpsellEditPage = new UpsellPage { @@ -245,7 +244,7 @@ namespace XenAdmin.Dialogs } } - if (is_hvm && !is_template && !Helpers.FeatureForbidden(xenObjectCopy, Host.RestrictUsbPassthrough) && + if (is_hvm && !is_template && !Helpers.FeatureForbidden(_xenObjectCopy, Host.RestrictUsbPassthrough) && pool.Connection.Cache.Hosts.Any(host => host.PUSBs.Count > 0)) { usbEditPage = new USBEditPage(); @@ -258,12 +257,12 @@ namespace XenAdmin.Dialogs ShowTab(VMAdvancedEditPage = new VMAdvancedEditPage()); } - if (is_vm && Helpers.ContainerCapability(xenObject.Connection)) + if (is_vm && Helpers.ContainerCapability(_xenObjectCopy.Connection)) { - if (((VM)xenObjectCopy).CanBeEnlightened()) + if (((VM)_xenObjectCopy).CanBeEnlightened()) ShowTab(VMEnlightenmentEditPage = new VMEnlightenmentEditPage()); - if (((VM)xenObjectCopy).CanHaveCloudConfigDrive()) + if (((VM)_xenObjectCopy).CanHaveCloudConfigDrive()) ShowTab(CloudConfigParametersPage = new Page_CloudConfigParameters()); } @@ -282,14 +281,14 @@ namespace XenAdmin.Dialogs ShowTab(newVmApplianceVmOrderAndDelaysPage1 = new NewVMApplianceVMOrderAndDelaysPage { Pool = pool }); } - if (is_sr && ((SR)xenObjectCopy).SupportsReadCaching() && !Helpers.FeatureForbidden(xenObjectCopy, Host.RestrictReadCaching)) + if (is_sr && ((SR)_xenObjectCopy).SupportsReadCaching() && !Helpers.FeatureForbidden(_xenObjectCopy, Host.RestrictReadCaching)) ShowTab(SrReadCachingEditPage = new SrReadCachingEditPage()); if (is_vdi) { ShowTab(vdiSizeLocation = new VDISizeLocationPage()); - VDI vdi = xenObjectCopy as VDI; + VDI vdi = _xenObjectCopy as VDI; List vbdEditPages = new List(); @@ -335,7 +334,7 @@ namespace XenAdmin.Dialogs pageAsControl.BackColor = Color.Transparent; pageAsControl.Dock = DockStyle.Fill; - editPage.SetXenObjects(xenObject, xenObjectCopy); + editPage.SetXenObjects(_xenObjectBefore, _xenObjectCopy); verticalTabs.Items.Add(editPage); } @@ -378,12 +377,12 @@ namespace XenAdmin.Dialogs // Must come first because some pages' SaveChanges() rely on modifying the object via the xenObjectCopy before their actions are run. int index = 0; - if (xenObjectBefore is VMSS vmss && vmss.type != vmss_type.snapshot_with_quiesce) + if (_xenObjectBefore is VMSS vmss && vmss.type != vmss_type.snapshot_with_quiesce) index = actions.Count; - actions.Insert(index, new SaveChangesAction(xenObjectCopy, true, xenObjectBefore)); + actions.Insert(index, new SaveChangesAction(_xenObjectCopy, true, _xenObjectBefore)); - var objName = Helpers.GetName(xenObject).Ellipsise(50); + var objName = Helpers.GetName(_xenObjectBefore).Ellipsise(50); _action = new MultipleAction( connection, string.Format(Messages.UPDATE_PROPERTIES, objName), @@ -391,21 +390,21 @@ namespace XenAdmin.Dialogs string.Format(Messages.UPDATED_PROPERTIES, objName), actions); - _action.SetObject(xenObjectCopy); + _action.SetObject(_xenObjectCopy); _action.Completed += action_Completed; Close(); if (_startAction) { - xenObject.Locked = true; + _xenObjectBefore.Locked = true; _action.RunAsync(); } } private void action_Completed(ActionBase sender) { - xenObject.Locked = false; + _xenObjectBefore.Locked = false; Program.Invoke(Program.MainWindow.GeneralPage, Program.MainWindow.GeneralPage.UpdateButtons); } From 77edbd3b1ee1beea1a9d8d53686e5582ed1b73b1 Mon Sep 17 00:00:00 2001 From: Danilo Del Busso Date: Wed, 7 Jun 2023 13:15:34 +0100 Subject: [PATCH 4/8] Prevent `long` overflow when VM has a very large amount of memory (#3154) * Prevent `long` overflow when VM has a very large amount of memory. Resulted in XenCenter hanging with a significant memory leak. * Remove unused `label` parameter from `LabelShouldBeShown` * Use `double` for increment variable when calculating increments in `ShinyBar` * Use `Debug.Assert` call to avoid issues with `DrawGrid` in `ShinyBar` Signed-off-by: Danilo Del Busso --- XenAdmin/Controls/Ballooning/ShinyBar.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/XenAdmin/Controls/Ballooning/ShinyBar.cs b/XenAdmin/Controls/Ballooning/ShinyBar.cs index eef7db45c..ebb1b39e8 100644 --- a/XenAdmin/Controls/Ballooning/ShinyBar.cs +++ b/XenAdmin/Controls/Ballooning/ShinyBar.cs @@ -30,6 +30,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; @@ -222,6 +223,7 @@ namespace XenAdmin.Controls.Ballooning protected void DrawGrid(Graphics g, Rectangle barArea, double bytesPerPixel, double max) { + Debug.Assert(max > 0, "Memory value should be larger than zero"); const int min_gap = 40; // min gap between consecutive labels (which are on alternate ticks) const int line_height = 12; @@ -236,15 +238,15 @@ namespace XenAdmin.Controls.Ballooning int text_top = text_bottom - labelSize.Height; // Calculate a suitable increment - long incr = Util.BINARY_MEGA / 2; - while((double)incr / bytesPerPixel * 2 < min_gap + longest) + var incr = Util.BINARY_MEGA / 2.0; + while(incr / bytesPerPixel * 2 < min_gap + longest) incr *= 2; // Draw the grid using (Pen pen = new Pen(Grid)) { bool withLabel = true; - for (long x = 0; x <= max; x += incr) + for (var x = 0.0; x <= max; x += incr) { // Tick int pos = barArea.Left + (int)((double)x / bytesPerPixel); @@ -257,7 +259,7 @@ namespace XenAdmin.Controls.Ballooning Size size = Drawing.MeasureText(g, label, Program.DefaultFont); Rectangle rect = new Rectangle(new Point(pos - size.Width/2, text_top), size); - if (LabelShouldBeShown(max, label, x)) + if (LabelShouldBeShown(max, x)) { Drawing.DrawText(g, label, Program.DefaultFont, rect, Grid, Color.Transparent); } @@ -273,10 +275,9 @@ namespace XenAdmin.Controls.Ballooning /// 2. If the maximum is greater than 1 GB, then show only the labels that are a multiple of half a GB. /// /// - /// /// /// - private static bool LabelShouldBeShown(double max, string label, long x) + private static bool LabelShouldBeShown(double max, double x) { return max <= Util.BINARY_GIGA || (x % (0.5 * Util.BINARY_GIGA)) == 0; } From 6c584bb351133ad225646156f904266394100178 Mon Sep 17 00:00:00 2001 From: Danilo Del Busso Date: Thu, 8 Jun 2023 11:24:39 +0100 Subject: [PATCH 5/8] CA-375532, CA-336510, and CP-41825: Add warnings when user selects too many vCPUs (#3119) * Tidy up `SelectMultipleVMDestinationPage.cs` * CA-375532 & CA-336510: Add warning when importing VMs with too many vCPUs * CA-375532 & CA-336510: Prevent users from starting appliance if a VM has too many vCPUs * Tidy up `Page_CpuMem`: use expression-bodied properties * Tidy up `Page_CpuMem`: use conventional naming scheme * Tidy up `Page_CpuMem`: use explicit modifiers * Tidy up `Page_CpuMem`: use `en-US` locale for names * Tidy up `Page_CpuMem`: use `var` when possible * Tidy up `Page_CpuMem`: rename `Vcpus` to `VCpus` * Tidy up `Page_CpuMem`: reorder elements * Tidy up `Page_CpuMem`: revert class renaming and fix `vCpus` typos * CA-375532: Prevent users from starting VM if they select too many vCPUs * Tidy up `Page_Finish`: use expression-bodied properties * Tidy up `Page_Finish`: fix typo * Tidy up `Page_CpuMem`: rename `CanStartVM` to `CanStartVm` * Remove unnecessary using directives * Anchor warning icon to the top-left corner of its parent * CA-375532 & CA-336510: Warn users when selecting more vCPUs than pCPUs in the Properties page * CP-41825: Add warning for imported VMs with > 32 vCPUs * CP-41825: Add warning for new VMs with > 32 vCPUs * CP-41825: Add warning for existing VMs when selecting > 32 vCPUs * CP-41825: Update wording used to alert users running VMs with > 32vCPUs * Remove unused local variable in `VappStartCommand.cs` * Reword some vCPUs messages * Simplify assignment of `CanStartImmediately` in `Page_Finish.cs` * Simplify assignment of `CanStartVmsAutomatically` in `ImportFinishPage.cs` * Remove useless `Count` check in `VappStartCommand` * Rename `pictureBox1` to `warningPictureBox` and change its `SizeMode` * Separate CPU and memory warnings in `Page_CpuMem` * Shorten warning messages shown in `Page_CpuMem` * Disable option to start VM when memory configuration isn't valid * Report number of vCPUs and pCPUs when showing warning in New VM wizard * Tidy up `CpuMemoryEditPage`: rename elements * Tidy up `CpuMemoryEditPage`: use explicity modifiers * Tidy up `CpuMemoryEditPage`: Rename `CPUMemoryEditPage` to `CpuMemoryEditPage` * Tidy up `CpuMemoryEditPage`: Miscellaneous renames and improvements * Tidy up `CpuMemoryEditPage`: Fix whitespace * Tidy up `CpuMemoryEditPage`: Use ReSharper code formatter * Tidy up `CpuMemoryEditPage`: Move events to own region * Tidy up `CpuMemoryEditPage`: Move `IEditPage` members to own region * Tidy up `CpuMemoryEditPage`: Order members outside of regions * Replace topology and vCPU warning labels with structured warnings * Ensure warnings ends with a dot * Allow multiple CPU warnings to show at the same time * Remove warning link for vCPUS > pCPUS Option is not achievable * Enable option to force unit used in `MemorySpinner` * Replace `NumericUpDown` with `MemorySpinner` and show warnings at bottom of control * Check destination pCPUs count when destination is not a pool * Do not disable option to start VMs after import if user selects a shared SR * Add memory warning when importing appliance with too much memory * Sort vCPUs and memory warning strings * Remove target from `ImportWizard`'s summary Target is not useful and can cause confusion as appliance VMs could start on non-target hosts * The home server is needed in the summary when importing XVA. The target server is not needed in the summary when migrating a VM. * Update warnings when the server selection changes. Corrected memory calculation. * Show all warnings for vCPUs. Moved topology warning to the bottom. Separated methods for showing memory and vCPU warnings. * Removed the memory setting from the VM Properties dialog. Split running VM info to a separate panel. * Corrections to the logic for starting the VM automatically. Also, Fixed a bit the layout of the Finish page to make better use of the available space. * Corrections as per code review. Signed-off-by: Danilo Del Busso Co-authored-by: Konstantina Chremmou --- XenAdmin/Commands/VappStartCommand.cs | 4 +- XenAdmin/Controls/Ballooning/MemorySpinner.cs | 1 + XenAdmin/Dialogs/PropertiesDialog.cs | 4 +- .../CPUMemoryEditPage.Designer.cs | 215 ++-- XenAdmin/SettingsPanels/CPUMemoryEditPage.cs | 697 ++++------ .../SettingsPanels/CPUMemoryEditPage.ja.resx | 2 +- .../SettingsPanels/CPUMemoryEditPage.resx | 670 +++++----- .../CPUMemoryEditPage.zh-CN.resx | 2 +- .../CrossPoolMigrateWizard.cs | 1 - ...electMultipleVMDestinationPage.Designer.cs | 2 +- .../SelectMultipleVMDestinationPage.cs | 65 +- .../SelectMultipleVMDestinationPage.resx | 3 - .../Wizards/GenericPages/VMMappingSummary.cs | 45 +- .../Wizards/ImportWizard/ImportFinishPage.cs | 9 +- .../ImportWizard/ImportSelectHostPage.cs | 198 ++- XenAdmin/Wizards/ImportWizard/ImportWizard.cs | 19 +- XenAdmin/Wizards/NewVMWizard/NewVMWizard.cs | 31 +- .../NewVMWizard/Page_CpuMem.Designer.cs | 325 ++--- XenAdmin/Wizards/NewVMWizard/Page_CpuMem.cs | 455 +++---- XenAdmin/Wizards/NewVMWizard/Page_CpuMem.resx | 1119 +++++++++-------- .../NewVMWizard/Page_Finish.Designer.cs | 39 +- XenAdmin/Wizards/NewVMWizard/Page_Finish.cs | 39 +- XenAdmin/Wizards/NewVMWizard/Page_Finish.resx | 139 +- XenAdmin/XenAdmin.csproj | 18 +- XenModel/Actions/OvfActions/Import.cs | 15 +- XenModel/Messages.Designer.cs | 171 +-- XenModel/Messages.resx | 83 +- XenModel/XenAPI-Extensions/VM.cs | 12 +- XenModel/XenModel.csproj | 10 +- 29 files changed, 2230 insertions(+), 2163 deletions(-) diff --git a/XenAdmin/Commands/VappStartCommand.cs b/XenAdmin/Commands/VappStartCommand.cs index c4631538e..50f6bd072 100644 --- a/XenAdmin/Commands/VappStartCommand.cs +++ b/XenAdmin/Commands/VappStartCommand.cs @@ -88,7 +88,9 @@ namespace XenAdmin.Commands } foreach (var app in appsToStart) - (new StartApplianceAction(app, false)).RunAsync(); + { + new StartApplianceAction(app, false).RunAsync(); + } } private bool CanStartAppliance(VM_appliance app) diff --git a/XenAdmin/Controls/Ballooning/MemorySpinner.cs b/XenAdmin/Controls/Ballooning/MemorySpinner.cs index 6ded8f448..7ff09cecb 100644 --- a/XenAdmin/Controls/Ballooning/MemorySpinner.cs +++ b/XenAdmin/Controls/Ballooning/MemorySpinner.cs @@ -52,6 +52,7 @@ namespace XenAdmin.Controls.Ballooning amount = Util.CorrectRoundingErrors(amount); Units = static_max <= Util.BINARY_GIGA ? Messages.VAL_MEGB : Messages.VAL_GIGB; + ChangeSpinnerSettings(); previousUnitsValue = Units; Initialize(amount, RoundingBehaviour.None); diff --git a/XenAdmin/Dialogs/PropertiesDialog.cs b/XenAdmin/Dialogs/PropertiesDialog.cs index b098342c3..b9d4e12c3 100755 --- a/XenAdmin/Dialogs/PropertiesDialog.cs +++ b/XenAdmin/Dialogs/PropertiesDialog.cs @@ -49,7 +49,7 @@ namespace XenAdmin.Dialogs public partial class PropertiesDialog : VerticallyTabbedDialog { #region Tabs - private CPUMemoryEditPage VCpuMemoryEditPage; + private CpuMemoryEditPage VCpuMemoryEditPage; private HostMultipathPage hostMultipathPage1; private CustomFieldsDisplayPage CustomFieldsEditPage; private LogDestinationEditPage LogDestinationEditPage; @@ -149,7 +149,7 @@ namespace XenAdmin.Dialogs if (is_vm) { - ShowTab(VCpuMemoryEditPage = new CPUMemoryEditPage()); + ShowTab(VCpuMemoryEditPage = new CpuMemoryEditPage()); ShowTab(StartupOptionsEditPage = new BootOptionsEditPage()); VMHAEditPage = new VMHAEditPage(); VMHAEditPage.Populated += EditPage_Populated; diff --git a/XenAdmin/SettingsPanels/CPUMemoryEditPage.Designer.cs b/XenAdmin/SettingsPanels/CPUMemoryEditPage.Designer.cs index 04f0b2791..5b234b2b1 100644 --- a/XenAdmin/SettingsPanels/CPUMemoryEditPage.Designer.cs +++ b/XenAdmin/SettingsPanels/CPUMemoryEditPage.Designer.cs @@ -1,6 +1,6 @@ namespace XenAdmin.SettingsPanels { - partial class CPUMemoryEditPage + partial class CpuMemoryEditPage { /// /// Required designer variable. @@ -28,34 +28,36 @@ namespace XenAdmin.SettingsPanels /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CPUMemoryEditPage)); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CpuMemoryEditPage)); this.lblSliderHighest = new System.Windows.Forms.Label(); this.lblSliderNormal = new System.Windows.Forms.Label(); this.lblSliderLowest = new System.Windows.Forms.Label(); this.lblPriority = new System.Windows.Forms.Label(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.warningsTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.cpuWarningPictureBox = new System.Windows.Forms.PictureBox(); + this.cpuWarningLabel = new System.Windows.Forms.Label(); + this.topologyWarningLabel = new System.Windows.Forms.Label(); + this.topologyPictureBox = new System.Windows.Forms.PictureBox(); this.comboBoxInitialVCPUs = new System.Windows.Forms.ComboBox(); this.labelInitialVCPUs = new System.Windows.Forms.Label(); - this.labelInvalidVCPUWarning = new System.Windows.Forms.Label(); this.comboBoxTopology = new XenAdmin.Controls.CPUTopologyComboBox(); this.labelTopology = new System.Windows.Forms.Label(); - this.MemWarningLabel = new System.Windows.Forms.Label(); - this.panel2 = new System.Windows.Forms.Panel(); - this.lblMB = new System.Windows.Forms.Label(); - this.nudMemory = new System.Windows.Forms.NumericUpDown(); this.panel1 = new System.Windows.Forms.Panel(); this.transparentTrackBar1 = new XenAdmin.Controls.TransparentTrackBar(); this.lblVCPUs = new System.Windows.Forms.Label(); - this.lblVcpuWarning = new System.Windows.Forms.LinkLabel(); - this.lblMemory = new System.Windows.Forms.Label(); - this.VCPUWarningLabel = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.comboBoxVCPUs = new System.Windows.Forms.ComboBox(); - this.initialVCPUWarningLabel = new System.Windows.Forms.Label(); + this.tableLayoutPanelInfo = new System.Windows.Forms.TableLayoutPanel(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.labelInfo = new System.Windows.Forms.Label(); this.tableLayoutPanel1.SuspendLayout(); - this.panel2.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nudMemory)).BeginInit(); + this.warningsTableLayoutPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.cpuWarningPictureBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.topologyPictureBox)).BeginInit(); this.panel1.SuspendLayout(); + this.tableLayoutPanelInfo.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // // lblSliderHighest @@ -76,31 +78,60 @@ namespace XenAdmin.SettingsPanels // lblPriority // resources.ApplyResources(this.lblPriority, "lblPriority"); - this.tableLayoutPanel1.SetColumnSpan(this.lblPriority, 4); + this.tableLayoutPanel1.SetColumnSpan(this.lblPriority, 3); this.lblPriority.Name = "lblPriority"; // // tableLayoutPanel1 // this.tableLayoutPanel1.BackColor = System.Drawing.Color.Transparent; resources.ApplyResources(this.tableLayoutPanel1, "tableLayoutPanel1"); - this.tableLayoutPanel1.Controls.Add(this.initialVCPUWarningLabel, 2, 6); - this.tableLayoutPanel1.Controls.Add(this.comboBoxInitialVCPUs, 1, 6); - this.tableLayoutPanel1.Controls.Add(this.labelInitialVCPUs, 0, 6); - this.tableLayoutPanel1.Controls.Add(this.labelInvalidVCPUWarning, 1, 5); - this.tableLayoutPanel1.Controls.Add(this.comboBoxTopology, 1, 4); - this.tableLayoutPanel1.Controls.Add(this.labelTopology, 0, 4); - this.tableLayoutPanel1.Controls.Add(this.MemWarningLabel, 3, 10); - this.tableLayoutPanel1.Controls.Add(this.panel2, 1, 10); - this.tableLayoutPanel1.Controls.Add(this.panel1, 0, 9); - this.tableLayoutPanel1.Controls.Add(this.lblPriority, 0, 8); + this.tableLayoutPanel1.Controls.Add(this.warningsTableLayoutPanel, 0, 7); + this.tableLayoutPanel1.Controls.Add(this.comboBoxInitialVCPUs, 1, 4); + this.tableLayoutPanel1.Controls.Add(this.labelInitialVCPUs, 0, 4); + this.tableLayoutPanel1.Controls.Add(this.comboBoxTopology, 1, 3); + this.tableLayoutPanel1.Controls.Add(this.labelTopology, 0, 3); + this.tableLayoutPanel1.Controls.Add(this.panel1, 0, 6); + this.tableLayoutPanel1.Controls.Add(this.lblPriority, 0, 5); this.tableLayoutPanel1.Controls.Add(this.lblVCPUs, 0, 2); - this.tableLayoutPanel1.Controls.Add(this.lblVcpuWarning, 0, 1); - this.tableLayoutPanel1.Controls.Add(this.lblMemory, 0, 10); - this.tableLayoutPanel1.Controls.Add(this.VCPUWarningLabel, 2, 2); this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0); this.tableLayoutPanel1.Controls.Add(this.comboBoxVCPUs, 1, 2); + this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanelInfo, 0, 1); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; // + // warningsTableLayoutPanel + // + resources.ApplyResources(this.warningsTableLayoutPanel, "warningsTableLayoutPanel"); + this.tableLayoutPanel1.SetColumnSpan(this.warningsTableLayoutPanel, 3); + this.warningsTableLayoutPanel.Controls.Add(this.cpuWarningPictureBox, 0, 0); + this.warningsTableLayoutPanel.Controls.Add(this.cpuWarningLabel, 1, 0); + this.warningsTableLayoutPanel.Controls.Add(this.topologyWarningLabel, 0, 2); + this.warningsTableLayoutPanel.Controls.Add(this.topologyPictureBox, 0, 2); + this.warningsTableLayoutPanel.Name = "warningsTableLayoutPanel"; + // + // cpuWarningPictureBox + // + this.cpuWarningPictureBox.Image = global::XenAdmin.Properties.Resources._000_Alert2_h32bit_16; + resources.ApplyResources(this.cpuWarningPictureBox, "cpuWarningPictureBox"); + this.cpuWarningPictureBox.Name = "cpuWarningPictureBox"; + this.cpuWarningPictureBox.TabStop = false; + // + // cpuWarningLabel + // + resources.ApplyResources(this.cpuWarningLabel, "cpuWarningLabel"); + this.cpuWarningLabel.Name = "cpuWarningLabel"; + // + // topologyWarningLabel + // + resources.ApplyResources(this.topologyWarningLabel, "topologyWarningLabel"); + this.topologyWarningLabel.Name = "topologyWarningLabel"; + // + // topologyPictureBox + // + this.topologyPictureBox.Image = global::XenAdmin.Properties.Resources._000_Alert2_h32bit_16; + resources.ApplyResources(this.topologyPictureBox, "topologyPictureBox"); + this.topologyPictureBox.Name = "topologyPictureBox"; + this.topologyPictureBox.TabStop = false; + // // comboBoxInitialVCPUs // this.comboBoxInitialVCPUs.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; @@ -114,16 +145,9 @@ namespace XenAdmin.SettingsPanels resources.ApplyResources(this.labelInitialVCPUs, "labelInitialVCPUs"); this.labelInitialVCPUs.Name = "labelInitialVCPUs"; // - // labelInvalidVCPUWarning - // - resources.ApplyResources(this.labelInvalidVCPUWarning, "labelInvalidVCPUWarning"); - this.tableLayoutPanel1.SetColumnSpan(this.labelInvalidVCPUWarning, 3); - this.labelInvalidVCPUWarning.ForeColor = System.Drawing.Color.Red; - this.labelInvalidVCPUWarning.Name = "labelInvalidVCPUWarning"; - // // comboBoxTopology // - this.tableLayoutPanel1.SetColumnSpan(this.comboBoxTopology, 3); + this.tableLayoutPanel1.SetColumnSpan(this.comboBoxTopology, 2); this.comboBoxTopology.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; resources.ApplyResources(this.comboBoxTopology, "comboBoxTopology"); this.comboBoxTopology.FormattingEnabled = true; @@ -135,51 +159,10 @@ namespace XenAdmin.SettingsPanels resources.ApplyResources(this.labelTopology, "labelTopology"); this.labelTopology.Name = "labelTopology"; // - // MemWarningLabel - // - resources.ApplyResources(this.MemWarningLabel, "MemWarningLabel"); - this.MemWarningLabel.ForeColor = System.Drawing.Color.Red; - this.MemWarningLabel.Name = "MemWarningLabel"; - this.tableLayoutPanel1.SetRowSpan(this.MemWarningLabel, 2); - // - // panel2 - // - resources.ApplyResources(this.panel2, "panel2"); - this.tableLayoutPanel1.SetColumnSpan(this.panel2, 2); - this.panel2.Controls.Add(this.lblMB); - this.panel2.Controls.Add(this.nudMemory); - this.panel2.Name = "panel2"; - // - // lblMB - // - resources.ApplyResources(this.lblMB, "lblMB"); - this.lblMB.Name = "lblMB"; - // - // nudMemory - // - resources.ApplyResources(this.nudMemory, "nudMemory"); - this.nudMemory.Maximum = new decimal(new int[] { - 1048576, - 0, - 0, - 0}); - this.nudMemory.Minimum = new decimal(new int[] { - 64, - 0, - 0, - 0}); - this.nudMemory.Name = "nudMemory"; - this.nudMemory.Value = new decimal(new int[] { - 64, - 0, - 0, - 0}); - this.nudMemory.ValueChanged += new System.EventHandler(this.nudMemory_ValueChanged); - // // panel1 // resources.ApplyResources(this.panel1, "panel1"); - this.tableLayoutPanel1.SetColumnSpan(this.panel1, 4); + this.tableLayoutPanel1.SetColumnSpan(this.panel1, 3); this.panel1.Controls.Add(this.lblSliderHighest); this.panel1.Controls.Add(this.lblSliderNormal); this.panel1.Controls.Add(this.lblSliderLowest); @@ -198,32 +181,10 @@ namespace XenAdmin.SettingsPanels resources.ApplyResources(this.lblVCPUs, "lblVCPUs"); this.lblVCPUs.Name = "lblVCPUs"; // - // lblVcpuWarning - // - resources.ApplyResources(this.lblVcpuWarning, "lblVcpuWarning"); - this.tableLayoutPanel1.SetColumnSpan(this.lblVcpuWarning, 4); - this.lblVcpuWarning.LinkColor = System.Drawing.SystemColors.ActiveCaption; - this.lblVcpuWarning.Name = "lblVcpuWarning"; - this.lblVcpuWarning.TabStop = true; - this.lblVcpuWarning.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lblVcpuWarning_LinkClicked); - // - // lblMemory - // - resources.ApplyResources(this.lblMemory, "lblMemory"); - this.lblMemory.Name = "lblMemory"; - // - // VCPUWarningLabel - // - resources.ApplyResources(this.VCPUWarningLabel, "VCPUWarningLabel"); - this.tableLayoutPanel1.SetColumnSpan(this.VCPUWarningLabel, 2); - this.VCPUWarningLabel.ForeColor = System.Drawing.Color.Red; - this.VCPUWarningLabel.Name = "VCPUWarningLabel"; - this.tableLayoutPanel1.SetRowSpan(this.VCPUWarningLabel, 2); - // // label1 // resources.ApplyResources(this.label1, "label1"); - this.tableLayoutPanel1.SetColumnSpan(this.label1, 4); + this.tableLayoutPanel1.SetColumnSpan(this.label1, 3); this.label1.Name = "label1"; // // comboBoxVCPUs @@ -234,14 +195,27 @@ namespace XenAdmin.SettingsPanels this.comboBoxVCPUs.Name = "comboBoxVCPUs"; this.comboBoxVCPUs.SelectedIndexChanged += new System.EventHandler(this.comboBoxVCPUs_SelectedIndexChanged); // - // initialVCPUWarningLabel + // tableLayoutPanelInfo // - resources.ApplyResources(this.initialVCPUWarningLabel, "initialVCPUWarningLabel"); - this.tableLayoutPanel1.SetColumnSpan(this.initialVCPUWarningLabel, 2); - this.initialVCPUWarningLabel.ForeColor = System.Drawing.Color.Red; - this.initialVCPUWarningLabel.Name = "initialVCPUWarningLabel"; + resources.ApplyResources(this.tableLayoutPanelInfo, "tableLayoutPanelInfo"); + this.tableLayoutPanel1.SetColumnSpan(this.tableLayoutPanelInfo, 3); + this.tableLayoutPanelInfo.Controls.Add(this.pictureBox1, 0, 0); + this.tableLayoutPanelInfo.Controls.Add(this.labelInfo, 1, 0); + this.tableLayoutPanelInfo.Name = "tableLayoutPanelInfo"; // - // CPUMemoryEditPage + // pictureBox1 + // + this.pictureBox1.Image = global::XenAdmin.Properties.Resources._000_Info3_h32bit_16; + resources.ApplyResources(this.pictureBox1, "pictureBox1"); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.TabStop = false; + // + // labelInfo + // + resources.ApplyResources(this.labelInfo, "labelInfo"); + this.labelInfo.Name = "labelInfo"; + // + // CpuMemoryEditPage // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; @@ -249,14 +223,18 @@ namespace XenAdmin.SettingsPanels this.Controls.Add(this.tableLayoutPanel1); this.DoubleBuffered = true; this.ForeColor = System.Drawing.SystemColors.ControlText; - this.Name = "CPUMemoryEditPage"; + this.Name = "CpuMemoryEditPage"; this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); - this.panel2.ResumeLayout(false); - this.panel2.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nudMemory)).EndInit(); + this.warningsTableLayoutPanel.ResumeLayout(false); + this.warningsTableLayoutPanel.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.cpuWarningPictureBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.topologyPictureBox)).EndInit(); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); + this.tableLayoutPanelInfo.ResumeLayout(false); + this.tableLayoutPanelInfo.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); } @@ -264,27 +242,26 @@ namespace XenAdmin.SettingsPanels #endregion private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; - private System.Windows.Forms.NumericUpDown nudMemory; - private System.Windows.Forms.Label lblMB; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Label lblSliderHighest; private System.Windows.Forms.Label lblSliderNormal; private System.Windows.Forms.Label lblSliderLowest; private System.Windows.Forms.Label lblPriority; private System.Windows.Forms.Label lblVCPUs; - private System.Windows.Forms.Label lblMemory; - private System.Windows.Forms.LinkLabel lblVcpuWarning; private XenAdmin.Controls.TransparentTrackBar transparentTrackBar1; - private System.Windows.Forms.Panel panel2; - private System.Windows.Forms.Label VCPUWarningLabel; - private System.Windows.Forms.Label MemWarningLabel; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label labelTopology; private XenAdmin.Controls.CPUTopologyComboBox comboBoxTopology; - private System.Windows.Forms.Label labelInvalidVCPUWarning; private System.Windows.Forms.ComboBox comboBoxVCPUs; private System.Windows.Forms.ComboBox comboBoxInitialVCPUs; private System.Windows.Forms.Label labelInitialVCPUs; - private System.Windows.Forms.Label initialVCPUWarningLabel; + private System.Windows.Forms.TableLayoutPanel warningsTableLayoutPanel; + private System.Windows.Forms.PictureBox cpuWarningPictureBox; + private System.Windows.Forms.Label cpuWarningLabel; + private System.Windows.Forms.Label topologyWarningLabel; + private System.Windows.Forms.PictureBox topologyPictureBox; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanelInfo; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Label labelInfo; } } diff --git a/XenAdmin/SettingsPanels/CPUMemoryEditPage.cs b/XenAdmin/SettingsPanels/CPUMemoryEditPage.cs index 807ec6c88..d79da31d6 100644 --- a/XenAdmin/SettingsPanels/CPUMemoryEditPage.cs +++ b/XenAdmin/SettingsPanels/CPUMemoryEditPage.cs @@ -31,541 +31,241 @@ using System; using System.Collections.Generic; using System.Drawing; -using System.Text; +using System.Linq; using System.Windows.Forms; - using XenAdmin.Actions; -using XenAdmin.Commands; using XenAdmin.Core; using XenAPI; -using XenAdmin.Dialogs; - namespace XenAdmin.SettingsPanels { - public partial class CPUMemoryEditPage : UserControl, IEditPage + public partial class CpuMemoryEditPage : UserControl, IEditPage { - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod()?.DeclaringType); - private VM vm; - bool ShowMemory = false; // If this VM has DMC, we don't show the memory controls on this page. - - private bool _ValidToSave = true; - private decimal _OrigMemory; - private long _OrigVCPUs; - private long _OrigVCPUsMax; - private long _OrigVCPUsAtStartup; - private decimal _OrigVCPUWeight; - private decimal _CurrentVCPUWeight; - private bool isVcpuHotplugSupported; - private int minVCPUs; + private VM _vm; + private bool _validToSave = true; + private long _origVCpus; + private long _origVCpusMax; + private long _origVCpusAtStartup; + private decimal _origVCpuWeight; + private decimal _currentVCpuWeight; + private bool _isVCpuHotplugSupported; + private int _minVCpus; + private long _prevVCpusMax; // Please note that the comboBoxVCPUs control can represent two different VM properties, depending whether the VM supports vCPU hotplug or not: // If vCPU hotplug is supported, comboBoxVCPUs represents the maximum number of vCPUs (VCPUs_max). And the initial number of vCPUs is represented in comboBoxInitialVCPUs (which is only visible in this case) // If vCPU hotplug is not supported, comboBoxVCPUs represents the initial number of vCPUs (VCPUs_at_startup). In this case we will also set the VM property VCPUs_max to the same value. // We use the _OrigVCPUs variable to store the original value that populates this combo box (VCPUs_max if hotplug is allowed, otherwise VCPUs_at_startup) - private ChangeMemorySettingsAction memoryAction; - public bool ValidToSave - { - get - { - if (!_ValidToSave) - return false; + private bool HasVCpuChanged => _origVCpus != (long)comboBoxVCPUs.SelectedItem; - // Also confirm whether the user wants to save memory changes. - // If not, don't close the properties dialog. - if (HasMemoryChanged) - { - long mem = Convert.ToInt64(this.nudMemory.Value * Util.BINARY_MEGA); - memoryAction = ConfirmAndCalcActions(mem); - if (memoryAction == null) - return false; - } + private bool HasVCpuWeightChanged => _origVCpuWeight != _currentVCpuWeight; - return true; - } - } + private bool HasVCpusAtStartupChanged => + _isVCpuHotplugSupported && _origVCpusAtStartup != (long)comboBoxInitialVCPUs.SelectedItem; - private ChangeMemorySettingsAction ConfirmAndCalcActions(long mem) - { - if (vm.memory_static_max / Util.BINARY_MEGA == mem / Util.BINARY_MEGA) - { - // don't want to show warning dialog just for rounding errors - mem = vm.memory_static_max; - } - else if (vm.power_state != vm_power_state.Halted) - { - var msg = vm.SupportsBallooning() && !Helpers.FeatureForbidden(vm, Host.RestrictDMC) - ? Messages.CONFIRM_CHANGE_MEMORY_MAX_SINGULAR - : Messages.CONFIRM_CHANGE_MEMORY_SINGULAR; + private bool HasTopologyChanged => _vm.GetCoresPerSocket() != comboBoxTopology.CoresPerSocket; - using (var dlg = new WarningDialog(msg, - ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo)) - { - if (dlg.ShowDialog(this) != DialogResult.Yes) - return null; - } - } + private long SelectedVCpusMax => (long)comboBoxVCPUs.SelectedItem; - return new ChangeMemorySettingsAction(vm, - string.Format(Messages.ACTION_CHANGE_MEMORY_SETTINGS, vm.Name()), - vm.memory_static_min, mem, mem, mem, - VMOperationCommand.WarningDialogHAInvalidConfig, VMOperationCommand.StartDiagnosisForm, true); - } - - public CPUMemoryEditPage() - { - InitializeComponent(); - - Text = Messages.CPU_AND_MEMORY; - - transparentTrackBar1.Scroll += new EventHandler(tbPriority_Scroll); - - this.nudMemory.TextChanged += new EventHandler(nudMemory_TextChanged); - this.nudMemory.LostFocus += new EventHandler(nudMemory_LostFocus); - } + private long SelectedVCpusAtStartup => _isVCpuHotplugSupported + ? (long)comboBoxInitialVCPUs.SelectedItem + : (long)comboBoxVCPUs.SelectedItem; public Image Image => Images.StaticImages._000_CPU_h32bit_16; - void nudMemory_LostFocus(object sender, EventArgs e) + public string SubText => string.Format(Messages.CPU_SUB, SelectedVCpusAtStartup); + + public CpuMemoryEditPage() { - ValidateNud(nudMemory, (decimal)vm.memory_static_max / Util.BINARY_MEGA); + InitializeComponent(); + transparentTrackBar1.Scroll += tbPriority_Scroll; + Text = Messages.CPU; } - private void ValidateNud(NumericUpDown nud, Decimal defaultValue) + private void InitializeVCpuControls() { - if (!String.IsNullOrEmpty(nud.Text.Trim())) - return; - - nud.Value = defaultValue >= nud.Minimum && defaultValue <= nud.Maximum ? - defaultValue : nud.Maximum; - - nud.Text = nud.Value.ToString(); - } - - void nudMemory_TextChanged(object sender, EventArgs e) - { - decimal val; - if (decimal.TryParse(nudMemory.Text, out val)) - { - if (val >= nudMemory.Minimum && val <= nudMemory.Maximum) - nudMemory_ValueChanged(null, null); - else if (val > nudMemory.Maximum) - ShowMemError(true, false); - else - ShowMemError(false, false); - } - if (this.nudMemory.Text == "") - { - _ValidToSave = false; - } - else - { - _ValidToSave = true; - } - } - - private void tbPriority_Scroll(object sender, EventArgs e) - { - _CurrentVCPUWeight = Convert.ToDecimal(Math.Pow(4.0d, Convert.ToDouble(transparentTrackBar1.Value))); - if (transparentTrackBar1.Value == transparentTrackBar1.Max) - _CurrentVCPUWeight--; - } - - /// - /// Must be a VM. - /// - public void SetXenObjects(IXenObject orig, IXenObject clone) - { - vm = (VM)clone; - ShowMemory = Helpers.FeatureForbidden(vm, Host.RestrictDMC); - Repopulate(); - } - - public void Repopulate() - { - VM vm = this.vm; - - Text = ShowMemory ? Messages.CPU_AND_MEMORY : Messages.CPU; - if (!ShowMemory) - lblMemory.Visible = panel2.Visible = MemWarningLabel.Visible = false; - else if (vm.power_state != vm_power_state.Halted && vm.power_state != vm_power_state.Running) - { - panel2.Enabled = false; - MemWarningLabel.Text = Messages.MEM_NOT_WHEN_SUSPENDED; - MemWarningLabel.ForeColor = SystemColors.ControlText; - MemWarningLabel.Visible = true; - } - - // Since updates come in dribs and drabs, avoid error if new max and min arrive - // out of sync and maximum < minimum. - if (vm.memory_dynamic_max >= vm.memory_dynamic_min && - vm.memory_static_max >= vm.memory_static_min) - { - decimal min = Convert.ToDecimal(vm.memory_static_min / Util.BINARY_MEGA); - decimal max = Convert.ToDecimal(vm.MaxMemAllowed() / Util.BINARY_MEGA); - decimal value = Convert.ToDecimal(vm.memory_static_max / Util.BINARY_MEGA); - // Avoid setting the range to exclude the current value: CA-40041 - if (value > max) - max = value; - if (value < min) - min = value; - this.nudMemory.Minimum = min; - this.nudMemory.Maximum = max; - this.nudMemory.Text = (this.nudMemory.Value = value).ToString(); - } - - Host currentHost = Helpers.GetCoordinator(this.vm.Connection); - if (currentHost != null) - { - // Show the performance warning about vCPUs > pCPUs. - // Don't show if the VM isn't running, since we don't know which server it will - // run on (and so can't count the number of pCPUs). - if ( vm.power_state == vm_power_state.Running - && vm.VCPUs_at_startup > currentHost.host_CPUs.Count - && !vm.GetIgnoreExcessiveVcpus()) - { - lblVcpuWarning.Visible = true; - this.tableLayoutPanel1.RowStyles[1].SizeType = SizeType.Absolute; - this.tableLayoutPanel1.RowStyles[1].Height = 30; - } - else - { - lblVcpuWarning.Visible = false; - } - } - else - { - lblVcpuWarning.Visible = false; - } - - isVcpuHotplugSupported = vm.SupportsVcpuHotplug(); - minVCPUs = vm.MinVCPUs(); - - label1.Text = GetRubric(); - - _OrigMemory = nudMemory.Value; - _OrigVCPUsMax = vm.VCPUs_max > 0 ? vm.VCPUs_max : 1; - _OrigVCPUsAtStartup = vm.VCPUs_at_startup > 0 ? vm.VCPUs_at_startup : 1; - _OrigVCPUWeight = _CurrentVCPUWeight; - _OrigVCPUs = isVcpuHotplugSupported ? _OrigVCPUsMax : _OrigVCPUsAtStartup; - _prevVCPUsMax = _OrigVCPUsMax; // we use variable in RefreshCurrentVCPUs for checking if VcpusAtStartup and VcpusMax were equal before VcpusMax changed - - _CurrentVCPUWeight = Convert.ToDecimal(vm.GetVcpuWeight()); - - InitializeVcpuControls(); - - _ValidToSave = true; - } - - private void InitializeVcpuControls() - { - lblVCPUs.Text = isVcpuHotplugSupported + lblVCPUs.Text = _isVCpuHotplugSupported ? Messages.VM_CPUMEMPAGE_MAX_VCPUS_LABEL : Messages.VM_CPUMEMPAGE_VCPUS_LABEL; - labelInitialVCPUs.Text = vm.power_state == vm_power_state.Halted + labelInitialVCPUs.Text = _vm.power_state == vm_power_state.Halted ? Messages.VM_CPUMEMPAGE_INITIAL_VCPUS_LABEL : Messages.VM_CPUMEMPAGE_CURRENT_VCPUS_LABEL; - - labelInitialVCPUs.Visible = comboBoxInitialVCPUs.Visible = isVcpuHotplugSupported; - comboBoxInitialVCPUs.Enabled = isVcpuHotplugSupported && - (vm.power_state == vm_power_state.Halted || - vm.power_state == vm_power_state.Running); - comboBoxVCPUs.Enabled = comboBoxTopology.Enabled = vm.power_state == vm_power_state.Halted; + labelInitialVCPUs.Visible = comboBoxInitialVCPUs.Visible = _isVCpuHotplugSupported; + comboBoxInitialVCPUs.Enabled = _isVCpuHotplugSupported && + (_vm.power_state == vm_power_state.Halted || + _vm.power_state == vm_power_state.Running); - comboBoxTopology.Populate(vm.VCPUs_at_startup, vm.VCPUs_max, vm.GetCoresPerSocket(), vm.MaxCoresPerSocket()); + comboBoxVCPUs.Enabled = comboBoxTopology.Enabled = _vm.power_state == vm_power_state.Halted; + + comboBoxTopology.Populate(_vm.VCPUs_at_startup, _vm.VCPUs_max, _vm.GetCoresPerSocket(), + _vm.MaxCoresPerSocket()); // CA-12941 // We set a sensible maximum based on the template, but if the user sets something higher // from the CLI then use that as the maximum. - var maxAllowed = vm.MaxVCPUsAllowed(); - long maxVCPUs = maxAllowed < _OrigVCPUs ? _OrigVCPUs : maxAllowed; - PopulateVCPUs(maxVCPUs, _OrigVCPUs); + var maxAllowed = _vm.MaxVCPUsAllowed(); + var maxVCpus = maxAllowed < _origVCpus ? _origVCpus : maxAllowed; + PopulateVCpus(maxVCpus, _origVCpus); - if (isVcpuHotplugSupported) - PopulateVCPUsAtStartup(_OrigVCPUsMax, _OrigVCPUsAtStartup); + if (_isVCpuHotplugSupported) + PopulateVCpusAtStartup(_origVCpusMax, _origVCpusAtStartup); - transparentTrackBar1.Value = Convert.ToInt32(Math.Log(Convert.ToDouble(vm.GetVcpuWeight())) / Math.Log(4.0d)); - panel1.Enabled = vm.power_state == vm_power_state.Halted; + transparentTrackBar1.Value = + Convert.ToInt32(Math.Log(Convert.ToDouble(_vm.GetVcpuWeight())) / Math.Log(4.0d)); + panel1.Enabled = _vm.power_state == vm_power_state.Halted; } - private void PopulateVCPUComboBox(ComboBox comboBox, long min, long max, long currentValue, Predicate isValid) + private void Repopulate() + { + var vm = _vm; + + _isVCpuHotplugSupported = vm.SupportsVcpuHotplug(); + _minVCpus = vm.MinVCPUs(); + + label1.Text = Messages.VM_CPUMEMPAGE_RUBRIC; + + if (_isVCpuHotplugSupported) + label1.Text += Messages.VM_CPUMEMPAGE_RUBRIC_HOTPLUG; + + if (_vm.power_state != vm_power_state.Halted) + { + if (_isVCpuHotplugSupported) + { + labelInfo.Text = Messages.VM_CPUMEMPAGE_MAX_VCPUS_READONLY; + + if (_vm.power_state != vm_power_state.Running) + labelInfo.Text += Messages.VM_CPUMEMPAGE_CURRENT_VCPUS_READONLY; + } + else + { + labelInfo.Text = Messages.VCPU_ONLY_WHEN_HALTED; + } + + tableLayoutPanelInfo.Visible = true; + } + else + { + tableLayoutPanelInfo.Visible = false; + } + + _origVCpusMax = vm.VCPUs_max > 0 ? vm.VCPUs_max : 1; + _origVCpusAtStartup = vm.VCPUs_at_startup > 0 ? vm.VCPUs_at_startup : 1; + _origVCpuWeight = _currentVCpuWeight; + _origVCpus = _isVCpuHotplugSupported ? _origVCpusMax : _origVCpusAtStartup; + _prevVCpusMax = _origVCpusMax; // we use variable in RefreshCurrentVCPUs for checking if VcpusAtStartup and VcpusMax were equal before VcpusMax changed + + _currentVCpuWeight = Convert.ToDecimal(vm.GetVcpuWeight()); + + InitializeVCpuControls(); + + _validToSave = true; + } + + private void PopulateVCpuComboBox(ComboBox comboBox, long min, long max, long currentValue, + Predicate isValid) { comboBox.BeginUpdate(); comboBox.Items.Clear(); - for (long i = min; i <= max; ++i) + for (var i = min; i <= max; ++i) { if (i == currentValue || isValid(i)) comboBox.Items.Add(i); } + if (currentValue > max) comboBox.Items.Add(currentValue); comboBox.SelectedItem = currentValue; comboBox.EndUpdate(); } - private void PopulateVCPUs(long maxVCPUs, long currentVCPUs) + private void PopulateVCpus(long maxVCpus, long currentVCpus) { - PopulateVCPUComboBox(comboBoxVCPUs, 1, maxVCPUs, currentVCPUs, i => comboBoxTopology.IsValidVCPU(i)); + PopulateVCpuComboBox(comboBoxVCPUs, 1, maxVCpus, currentVCpus, i => comboBoxTopology.IsValidVCPU(i)); } - private void PopulateVCPUsAtStartup(long max, long currentValue) + private void PopulateVCpusAtStartup(long max, long currentValue) { - long min = vm.power_state == vm_power_state.Halted ? 1 : _OrigVCPUsAtStartup; - PopulateVCPUComboBox(comboBoxInitialVCPUs, min, max, currentValue, i => true); + var min = _vm.power_state == vm_power_state.Halted ? 1 : _origVCpusAtStartup; + PopulateVCpuComboBox(comboBoxInitialVCPUs, min, max, currentValue, i => true); } - private string GetRubric() + private void ShowCpuWarnings(IReadOnlyCollection warnings) { - StringBuilder sb = new StringBuilder(); - sb.Append(Messages.VM_CPUMEMPAGE_RUBRIC); - // add hotplug text - if (isVcpuHotplugSupported) - sb.Append(Messages.VM_CPUMEMPAGE_RUBRIC_HOTPLUG); - // add power state warning - if (vm.power_state != vm_power_state.Halted) - { - sb.AppendLine(); - sb.AppendLine(); - sb.Append(isVcpuHotplugSupported ? Messages.VM_CPUMEMPAGE_MAX_VCPUS_READONLY : Messages.VCPU_ONLY_WHEN_HALTED); - } - // add power state warning for Current number of vCPUs - if (isVcpuHotplugSupported && vm.power_state != vm_power_state.Halted && vm.power_state != vm_power_state.Running) - { - sb.Append(Messages.VM_CPUMEMPAGE_CURRENT_VCPUS_READONLY); - } - return sb.ToString(); + var show = warnings.Count > 0; + cpuWarningLabel.Text = show ? string.Join($"{Environment.NewLine}{Environment.NewLine}", warnings) : null; + cpuWarningPictureBox.Visible = cpuWarningLabel.Visible = show; } - public bool HasChanged + private void ShowTopologyWarnings(IReadOnlyCollection warnings) { - get { return HasVCPUChanged || HasMemoryChanged || HasTopologyChanged || HasVCPUsAtStartupChanged || HasVCPUWeightChanged; } + var show = warnings.Count > 0; + topologyWarningLabel.Text = show ? string.Join($"{Environment.NewLine}{Environment.NewLine}", warnings) : null; + topologyPictureBox.Visible = topologyWarningLabel.Visible = show; } - private bool HasMemoryChanged + private void ValidateVCpuSettings() { - get - { - return _OrigMemory != nudMemory.Value; - } - } - - private bool HasVCPUChanged - { - get - { - return _OrigVCPUs != (long)comboBoxVCPUs.SelectedItem; - } - } - - private bool HasVCPUWeightChanged - { - get - { - return _OrigVCPUWeight != _CurrentVCPUWeight; - } - } - - private bool HasVCPUsAtStartupChanged - { - get - { - return isVcpuHotplugSupported && _OrigVCPUsAtStartup != (long)comboBoxInitialVCPUs.SelectedItem; - } - } - - private bool HasTopologyChanged - { - get - { - return vm.GetCoresPerSocket() != comboBoxTopology.CoresPerSocket; - } - } - - private long SelectedVcpusMax - { - get - { - return (long)comboBoxVCPUs.SelectedItem; - } - } - - private long SelectedVcpusAtStartup - { - get - { - return isVcpuHotplugSupported ? (long)comboBoxInitialVCPUs.SelectedItem : (long)comboBoxVCPUs.SelectedItem; - } - } - - public AsyncAction SaveSettings() - { - List actions = new List(); - - if (HasVCPUWeightChanged) - { - vm.SetVcpuWeight(Convert.ToInt32(_CurrentVCPUWeight)); - } - - if (HasVCPUChanged || HasVCPUsAtStartupChanged) - { - actions.Add(new ChangeVCPUSettingsAction(vm, SelectedVcpusMax, SelectedVcpusAtStartup)); - } - - if (HasTopologyChanged) - { - vm.SetCoresPerSocket(comboBoxTopology.CoresPerSocket); - } - - if (HasMemoryChanged) - { - actions.Add(memoryAction); // Calculated in ValidToSave - } - - if (actions.Count == 0) - return null; - else if (actions.Count == 1) - return actions[0]; - else - { - MultipleAction multipleAction = new MultipleAction(vm.Connection, "", "", "", actions, true); - return multipleAction; - } - } - - /** Show local validation balloon tooltips */ - public void ShowLocalValidationMessages() { } - - public void HideLocalValidationMessages() { } - - /** Unregister listeners, dispose balloon tooltips, etc. */ - public void Cleanup() { } - - /// - /// Shows the warning dialog about vCPUs > pCPUs. - /// - private void lblVcpuWarning_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) - { - if (vm == null) - { - System.Diagnostics.Trace.Assert(false, "Selected object should be a vm"); - return; - } - - using (var dialog = new WarningDialog(Messages.VCPUS_MORE_THAN_PCPUS) - { - ShowCheckbox = true, - CheckboxCaption = Messages.DO_NOT_SHOW_THIS_MESSAGE - }) - { - dialog.ShowDialog(this); - - if (dialog.IsCheckBoxChecked) - { - // User clicked 'ignore': set flag in VM. - log.DebugFormat("Setting IgnoreExcessiveVcpus flag to true for VM {0}", vm.Name()); - - VM copyVm = (VM)vm.Clone(); - copyVm.SetIgnoreExcessiveVcpus(true); - - try - { - vm.Locked = true; - copyVm.SaveChanges(vm.Connection.Session); - } - finally - { - vm.Locked = false; - } - } - else if (Program.MainWindow.SelectObjectInTree(vm)) - { - Program.MainWindow.SwitchToTab(MainWindow.Tab.General); - } - } - - Refresh(); - } - - private void nudMemory_ValueChanged(object sender, EventArgs e) - { - ShowMemError(false, true); - } - - private void ShowMemError(bool showAlways, bool testValue) - { - if (vm == null || !ShowMemory) + if (_vm == null || !comboBoxVCPUs.Enabled) return; - Host selectedAffinity = vm.Connection.Resolve(vm.power_state == vm_power_state.Running ? vm.resident_on : vm.affinity); - if (selectedAffinity != null) + var homeHost = _vm.Home(); + var maxPhysicalCpus = _vm.Connection.Cache.Hosts.Select(h => h.host_CPUs.Count).Max(); + var homeHostPhysicalCpus = homeHost?.host_CPUs.Count; + + var warnings = new List(); + + if (comboBoxVCPUs.SelectedItem != null && maxPhysicalCpus < SelectedVCpusMax) { - Host_metrics host_metrics = vm.Connection.Resolve(selectedAffinity.metrics); - if ((showAlways || (testValue && (host_metrics != null && (double)host_metrics.memory_total < (double)nudMemory.Value * (double)Util.BINARY_MEGA)))) + if (homeHostPhysicalCpus != null && homeHostPhysicalCpus < SelectedVCpusMax && + maxPhysicalCpus >= SelectedVCpusMax) { - MemWarningLabel.Visible = true; + warnings.Add(Messages.VM_CPUMEMPAGE_VCPU_HOME_HOST_WARNING); } - else + else if (maxPhysicalCpus < SelectedVCpusMax) { - MemWarningLabel.Visible = false; + warnings.Add(Messages.VM_CPUMEMPAGE_VCPU_WARNING); } } - } - private void comboBoxVCPUs_SelectedIndexChanged(object sender, EventArgs e) - { - ValidateVCPUSettings(); - comboBoxTopology.Update((long)comboBoxVCPUs.SelectedItem); - ValidateTopologySettings(); - RefreshCurrentVCPUs(); - } - - private void ValidateVCPUSettings() - { - if (vm == null || !comboBoxVCPUs.Enabled) - return; - Host selectedAffinity = vm.Home(); - if (selectedAffinity == null && vm.Connection.Cache.Hosts.Length == 1) - selectedAffinity = vm.Connection.Cache.Hosts[0]; - - if (selectedAffinity != null && comboBoxVCPUs.SelectedItem != null && selectedAffinity.host_CPUs.Count < SelectedVcpusMax) + if (comboBoxVCPUs.SelectedItem != null && SelectedVCpusMax < _minVCpus) { - VCPUWarningLabel.Text = Messages.VM_CPUMEMPAGE_VCPU_WARNING; - VCPUWarningLabel.Visible = true; - } - else if (comboBoxVCPUs.SelectedItem != null && SelectedVcpusMax < minVCPUs) - { - VCPUWarningLabel.Text = string.Format(Messages.VM_CPUMEMPAGE_VCPU_MIN_WARNING, minVCPUs); - VCPUWarningLabel.Visible = true; - } - else - { - VCPUWarningLabel.Visible = false; + warnings.Add(string.Format(Messages.VM_CPUMEMPAGE_VCPU_MIN_WARNING, _minVCpus)); } - if (comboBoxInitialVCPUs.SelectedItem != null && SelectedVcpusAtStartup < minVCPUs) + if (comboBoxVCPUs.SelectedItem != null && SelectedVCpusMax > VM.MAX_VCPUS_FOR_NON_TRUSTED_VMS) { - initialVCPUWarningLabel.Text = string.Format(Messages.VM_CPUMEMPAGE_VCPU_MIN_WARNING, minVCPUs); - initialVCPUWarningLabel.Visible = true; + warnings.Add(string.Format(Messages.VCPUS_UNTRUSTED_VM_WARNING, VM.MAX_VCPUS_FOR_NON_TRUSTED_VMS, BrandManager.ProductBrand)); } - else + + if (comboBoxInitialVCPUs.SelectedItem != null && SelectedVCpusAtStartup < _minVCpus) { - initialVCPUWarningLabel.Visible = false; + warnings.Add(string.Format(Messages.VM_CPUMEMPAGE_VCPU_MIN_WARNING, _minVCpus)); } + + ShowCpuWarnings(warnings); } private void ValidateTopologySettings() { + var warnings = new List(); if (comboBoxVCPUs.SelectedItem != null) - labelInvalidVCPUWarning.Text = VM.ValidVCPUConfiguration((long)comboBoxVCPUs.SelectedItem, comboBoxTopology.CoresPerSocket); + { + var topologyWarning = VM.ValidVCPUConfiguration((long)comboBoxVCPUs.SelectedItem, comboBoxTopology.CoresPerSocket); + + if (!string.IsNullOrEmpty(topologyWarning)) + { + warnings.Add($"{topologyWarning}."); + } + } + ShowTopologyWarnings(warnings); } - private long _prevVCPUsMax; - - private void RefreshCurrentVCPUs() + private void RefreshCurrentVCpus() { // refresh comboBoxInitialVCPUs if it's visible and populated if (comboBoxInitialVCPUs.Visible && comboBoxInitialVCPUs.Items.Count > 0) @@ -574,28 +274,88 @@ namespace XenAdmin.SettingsPanels // So if VcpusMax is decreased below VcpusAtStartup, then VcpusAtStartup is decreased to that number too // If VcpusAtStartup and VcpusMax are equal, and VcpusMax is changed, then VcpusAtStartup is changed to match // But if the numbers are unequal, and VcpusMax is changed but is still higher than VcpusAtStartup, then VcpusAtStartup is unchanged - var newValue = SelectedVcpusAtStartup; - - if (SelectedVcpusMax < SelectedVcpusAtStartup) - newValue = SelectedVcpusMax; - else if (SelectedVcpusAtStartup == _prevVCPUsMax && SelectedVcpusMax != _prevVCPUsMax) - newValue = SelectedVcpusMax; + var newValue = SelectedVCpusAtStartup; - PopulateVCPUsAtStartup(SelectedVcpusMax, newValue); - _prevVCPUsMax = SelectedVcpusMax; + if (SelectedVCpusMax < SelectedVCpusAtStartup) + newValue = SelectedVCpusMax; + else if (SelectedVCpusAtStartup == _prevVCpusMax && SelectedVCpusMax != _prevVCpusMax) + newValue = SelectedVCpusMax; + + PopulateVCpusAtStartup(SelectedVCpusMax, newValue); + _prevVCpusMax = SelectedVCpusMax; } } - public String SubText + #region IEditPage + + public AsyncAction SaveSettings() { - get + var actions = new List(); + + if (HasVCpuWeightChanged) { - return ShowMemory ? - String.Format(Messages.CPU_AND_MEMORY_SUB, SelectedVcpusAtStartup, nudMemory.Value) : - String.Format(Messages.CPU_SUB, SelectedVcpusAtStartup); + _vm.SetVcpuWeight(Convert.ToInt32(_currentVCpuWeight)); + } + + if (HasVCpuChanged || HasVCpusAtStartupChanged) + { + actions.Add(new ChangeVCPUSettingsAction(_vm, SelectedVCpusMax, SelectedVCpusAtStartup)); + } + + if (HasTopologyChanged) + { + _vm.SetCoresPerSocket(comboBoxTopology.CoresPerSocket); + } + + switch (actions.Count) + { + case 0: + return null; + case 1: + return actions[0]; + default: + { + var multipleAction = new MultipleAction(_vm.Connection, "", "", "", actions, true); + return multipleAction; + } } } - + + /// + /// Must be a VM. + /// + public void SetXenObjects(IXenObject orig, IXenObject clone) + { + _vm = (VM)clone; + Repopulate(); + } + + public bool ValidToSave => _validToSave; + + /** Show local validation balloon tooltips */ + public void ShowLocalValidationMessages() + { + // not applicable + } + + public void HideLocalValidationMessages() + { + // not applicable + } + + /** Unregister listeners, dispose balloon tooltips, etc. */ + public void Cleanup() + { + // not applicable + } + + public bool HasChanged => HasVCpuChanged || HasTopologyChanged || + HasVCpusAtStartupChanged || HasVCpuWeightChanged; + + #endregion + + #region Events + private void comboBoxTopology_SelectedIndexChanged(object sender, EventArgs e) { ValidateTopologySettings(); @@ -603,7 +363,24 @@ namespace XenAdmin.SettingsPanels private void comboBoxInitialVCPUs_SelectedIndexChanged(object sender, EventArgs e) { - ValidateVCPUSettings(); + ValidateVCpuSettings(); } + + private void comboBoxVCPUs_SelectedIndexChanged(object sender, EventArgs e) + { + ValidateVCpuSettings(); + comboBoxTopology.Update((long)comboBoxVCPUs.SelectedItem); + ValidateTopologySettings(); + RefreshCurrentVCpus(); + } + + private void tbPriority_Scroll(object sender, EventArgs e) + { + _currentVCpuWeight = Convert.ToDecimal(Math.Pow(4.0d, Convert.ToDouble(transparentTrackBar1.Value))); + if (transparentTrackBar1.Value == transparentTrackBar1.Max) + _currentVCpuWeight--; + } + + #endregion } -} +} \ No newline at end of file diff --git a/XenAdmin/SettingsPanels/CPUMemoryEditPage.ja.resx b/XenAdmin/SettingsPanels/CPUMemoryEditPage.ja.resx index fe06ba25f..5fcf02426 100644 --- a/XenAdmin/SettingsPanels/CPUMemoryEditPage.ja.resx +++ b/XenAdmin/SettingsPanels/CPUMemoryEditPage.ja.resx @@ -898,7 +898,7 @@ 500, 500 - CPUMemoryEditPage + CpuMemoryEditPage System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 diff --git a/XenAdmin/SettingsPanels/CPUMemoryEditPage.resx b/XenAdmin/SettingsPanels/CPUMemoryEditPage.resx index bc5efc025..d7a1cb2e5 100644 --- a/XenAdmin/SettingsPanels/CPUMemoryEditPage.resx +++ b/XenAdmin/SettingsPanels/CPUMemoryEditPage.resx @@ -226,52 +226,178 @@ True - 4 + 3 - + True - - Fill + + GrowAndShrink - + + 2 + + NoControl - - 185, 133 + + 3, 3 - - 312, 27 + + 16, 16 - - 19 - - - MiddleLeft - - - False - - - initialVCPUWarningLabel - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - + 0 + + False + + + cpuWarningPictureBox + + + System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + warningsTableLayoutPanel + + + 0 + + + Left + + + True + + + NoControl + + + 25, 4 + + + 0, 13 + + + 0 + + + False + + + cpuWarningLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + warningsTableLayoutPanel + + + 1 + + + Left + + + True + + + NoControl + + + 25, 32 + + + 0, 13 + + + 2 + + + False + + + topologyWarningLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + warningsTableLayoutPanel + + + 2 + + + NoControl + + + 3, 31 + + + 16, 16 + + + 5 + + + False + + + topologyPictureBox + + + System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + warningsTableLayoutPanel + + + 3 + + + Top + + + 0, 255 + + + 0, 20, 0, 0 + + + 3 + + + 500, 50 + + + 11 + + + warningsTableLayoutPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="cpuWarningPictureBox" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="cpuWarningLabel" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="topologyWarningLabel" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="topologyPictureBox" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0,Absolute,6,AutoSize,0" /></TableLayoutSettings> + - 129, 136 + 129, 130 50, 21 - 8 + 6 comboBoxInitialVCPUs @@ -285,33 +411,27 @@ 1 + + Left + True - - Fill - NoControl - 3, 136 - - - 3, 3, 3, 3 + 3, 134 - 120, 21 + 120, 13 - 7 + 5 Initial number of v&CPUs: - - MiddleLeft - labelInitialVCPUs @@ -324,90 +444,51 @@ 2 - - True - - - Fill - - - NoControl - - - 129, 114 - - - 3, 0, 3, 6 - - - 368, 13 - - - 7 - - - labelInvalidVCPUWarning - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 3 - Tahoma, 8pt - 129, 90 + 129, 103 250, 21 - 6 + 4 comboBoxTopology - XenAdmin.Controls.CPUTopologyComboBox, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + XenAdmin.Controls.CPUTopologyComboBox, [XenCenter_No_Space], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null tableLayoutPanel1 - 4 + 3 + + + Left True - - Fill - NoControl - 3, 90 - - - 3, 3, 3, 3 + 3, 107 - 120, 21 + 54, 13 - 5 + 3 &Topology: - - MiddleLeft - labelTopology @@ -418,139 +499,7 @@ tableLayoutPanel1 - 5 - - - True - - - Fill - - - NoControl - - - 230, 272 - - - 267, 26 - - - 12 - - - The amount of physical memory allocated to this VM is greater than the total memory of its home server - - - MiddleLeft - - - False - - - MemWarningLabel - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 6 - - - True - - - GrowAndShrink - - - True - - - NoControl - - - 72, 3 - - - 3, 3, 3, 3 - - - 23, 13 - - - 1 - - - MB - - - MiddleLeft - - - lblMB - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 0 - - - 1, 0 - - - 0, 0, 0, 0 - - - 71, 20 - - - 0 - - - nudMemory - - - System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 1 - - - Fill - - - 126, 275 - - - 0, 3, 0, 3 - - - 101, 20 - - - 11 - - - panel2 - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 7 + 4 Top, Left, Right @@ -571,7 +520,7 @@ transparentTrackBar1 - XenAdmin.Controls.TransparentTrackBar, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + XenAdmin.Controls.TransparentTrackBar, [XenCenter_No_Space], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null panel1 @@ -580,10 +529,7 @@ 3 - 3, 206 - - - 3, 3, 3, 24 + 3, 190 0, 0, 0, 6 @@ -592,7 +538,7 @@ 494, 42 - 9 + 8 panel1 @@ -604,35 +550,29 @@ tableLayoutPanel1 - 8 + 5 + + + Left True - - Fill - NoControl - 3, 63 - - - 3, 3, 3, 3 + 3, 80 - 120, 21 + 95, 13 - 2 + 1 &Number of vCPUs: - - MiddleLeft - lblVCPUs @@ -643,121 +583,7 @@ tableLayoutPanel1 - 10 - - - True - - - NoControl - - - 3, 41 - - - 3, 0, 3, 6 - - - 183, 13 - - - 1 - - - How can I improve VM performance? - - - MiddleLeft - - - lblVcpuWarning - - - System.Windows.Forms.LinkLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 11 - - - True - - - Fill - - - NoControl - - - 3, 275 - - - 3, 3, 3, 3 - - - 120, 20 - - - 10 - - - &VM memory: - - - MiddleLeft - - - lblMemory - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 12 - - - True - - - Fill - - - NoControl - - - 185, 60 - - - 312, 27 - - - 4 - - - More vCPUs than physical CPUs may lead to reduced VM performance - - - MiddleLeft - - - False - - - VCPUWarningLabel - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 13 + 7 True @@ -771,11 +597,11 @@ 3, 0 - - 0, 0, 0, 15 + + 3, 0, 3, 15 - 494, 41 + 494, 26 0 @@ -793,16 +619,16 @@ tableLayoutPanel1 - 14 + 8 - 129, 63 + 129, 76 50, 21 - 3 + 2 comboBoxVCPUs @@ -814,7 +640,97 @@ tableLayoutPanel1 - 15 + 9 + + + True + + + GrowAndShrink + + + 2 + + + 3, 3 + + + 16, 16 + + + 0 + + + pictureBox1 + + + System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanelInfo + + + 0 + + + Left + + + True + + + 25, 4 + + + 0, 13 + + + 1 + + + labelInfo + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanelInfo + + + 1 + + + Fill + + + 0, 41 + + + 0, 0, 0, 10 + + + 1 + + + 500, 22 + + + 12 + + + tableLayoutPanelInfo + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 10 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="pictureBox1" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="labelInfo" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0" /></TableLayoutSettings> Fill @@ -826,10 +742,10 @@ 0, 0, 0, 0 - 13 + 8 - 500, 500 + 500, 400 0 @@ -847,22 +763,22 @@ 0 - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="initialVCPUWarningLabel" Row="6" RowSpan="1" Column="2" ColumnSpan="2" /><Control Name="comboBoxInitialVCPUs" Row="6" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="labelInitialVCPUs" Row="6" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="labelInvalidVCPUWarning" Row="5" RowSpan="1" Column="1" ColumnSpan="3" /><Control Name="comboBoxTopology" Row="4" RowSpan="1" Column="1" ColumnSpan="3" /><Control Name="labelTopology" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="MemWarningLabel" Row="10" RowSpan="2" Column="3" ColumnSpan="1" /><Control Name="panel2" Row="10" RowSpan="1" Column="1" ColumnSpan="2" /><Control Name="panel1" Row="9" RowSpan="1" Column="0" ColumnSpan="4" /><Control Name="lblPriority" Row="8" RowSpan="1" Column="0" ColumnSpan="4" /><Control Name="lblVCPUs" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="lblVcpuWarning" Row="1" RowSpan="1" Column="0" ColumnSpan="4" /><Control Name="lblMemory" Row="10" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="VCPUWarningLabel" Row="2" RowSpan="2" Column="2" ColumnSpan="2" /><Control Name="label1" Row="0" RowSpan="1" Column="0" ColumnSpan="4" /><Control Name="comboBoxVCPUs" Row="2" RowSpan="1" Column="1" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,AutoSize,0,Absolute,45,Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,20,AutoSize,0,Absolute,20,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,100,Percent,50,Absolute,20" /></TableLayoutSettings> + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="warningsTableLayoutPanel" Row="7" RowSpan="1" Column="0" ColumnSpan="3" /><Control Name="comboBoxInitialVCPUs" Row="4" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="labelInitialVCPUs" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="comboBoxTopology" Row="3" RowSpan="1" Column="1" ColumnSpan="2" /><Control Name="labelTopology" Row="3" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="panel1" Row="6" RowSpan="1" Column="0" ColumnSpan="3" /><Control Name="lblPriority" Row="5" RowSpan="1" Column="0" ColumnSpan="3" /><Control Name="lblVCPUs" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="label1" Row="0" RowSpan="1" Column="0" ColumnSpan="3" /><Control Name="comboBoxVCPUs" Row="2" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="tableLayoutPanelInfo" Row="1" RowSpan="1" Column="0" ColumnSpan="3" /></Controls><Columns Styles="AutoSize,0,AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,Percent,100" /></TableLayoutSettings> NoControl - 3, 180 + 3, 174 - - 0, 10, 0, 0 + + 3, 20, 3, 0 - 179, 23 + 179, 13 - 8 + 7 vCPU priority for this virtual machine: @@ -880,7 +796,7 @@ tableLayoutPanel1 - 9 + 6 True @@ -892,13 +808,13 @@ 0, 0, 0, 0 - 500, 500 + 500, 400 - 500, 500 + 500, 400 - CPUMemoryEditPage + CpuMemoryEditPage System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 diff --git a/XenAdmin/SettingsPanels/CPUMemoryEditPage.zh-CN.resx b/XenAdmin/SettingsPanels/CPUMemoryEditPage.zh-CN.resx index 7733afb83..524ee73d3 100644 --- a/XenAdmin/SettingsPanels/CPUMemoryEditPage.zh-CN.resx +++ b/XenAdmin/SettingsPanels/CPUMemoryEditPage.zh-CN.resx @@ -898,7 +898,7 @@ 500, 500 - CPUMemoryEditPage + CpuMemoryEditPage System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 diff --git a/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateWizard.cs b/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateWizard.cs index a20a83f10..8553c6bd1 100644 --- a/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateWizard.cs +++ b/XenAdmin/Wizards/CrossPoolMigrateWizard/CrossPoolMigrateWizard.cs @@ -469,7 +469,6 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard summary = new VmTitleSummary(summary, pair.Value); summary = new DestinationPoolSummary(summary, pair.Value, TargetConnection); - summary = new TargetServerSummary(summary, pair.Value, TargetConnection); summary = new TransferNetworkSummary(summary, m_pageTransferNetwork.NetworkUuid.Value); summary = new StorageSummary(summary, pair.Value, xenConnection); summary = new NetworkSummary(summary, pair.Value, xenConnection); diff --git a/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.Designer.cs b/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.Designer.cs index bd80b1c32..881b3659d 100644 --- a/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.Designer.cs +++ b/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.Designer.cs @@ -129,8 +129,8 @@ // // pictureBox1 // - resources.ApplyResources(this.pictureBox1, "pictureBox1"); this.pictureBox1.Image = global::XenAdmin.Properties.Resources._000_WarningAlert_h32bit_32; + resources.ApplyResources(this.pictureBox1, "pictureBox1"); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.TabStop = false; // diff --git a/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.cs b/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.cs index cbaad3765..7a4818800 100755 --- a/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.cs +++ b/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.cs @@ -49,7 +49,6 @@ namespace XenAdmin.Wizards.GenericPages internal abstract partial class SelectMultipleVMDestinationPage : XenTabPage { private Dictionary m_vmMappings; - public IXenObject SelectedTarget { get; set; } private bool updatingDestinationCombobox; private bool restoreGridHomeServerSelection; private bool updatingHomeServerList; @@ -58,6 +57,7 @@ namespace XenAdmin.Wizards.GenericPages private readonly CollectionChangeEventHandler Host_CollectionChangedWithInvoke; private string _preferredHomeRef; private IXenObject _selectedTargetPool; + private IXenObject _selectedTarget; #region Nested classes @@ -121,8 +121,24 @@ namespace XenAdmin.Wizards.GenericPages get => _selectedTargetPool; private set { + var oldTargetPool = _selectedTargetPool; _selectedTargetPool = value; - OnChosenItemChanged(); + + if (oldTargetPool?.opaque_ref != _selectedTargetPool?.opaque_ref) + OnSelectedTargetPoolChanged(); + } + } + + public IXenObject SelectedTarget + { + get => _selectedTarget; + set + { + var oldTarget = _selectedTarget; + _selectedTarget = value; + + if (oldTarget?.opaque_ref != SelectedTarget?.opaque_ref) + OnSelectedTargetChanged(); } } @@ -143,9 +159,14 @@ namespace XenAdmin.Wizards.GenericPages /// protected abstract string TargetServerSelectionIntroText { get; } - protected virtual void OnChosenItemChanged() + protected virtual void OnSelectedTargetPoolChanged() { } + protected virtual void OnSelectedTargetChanged() + { + + } + protected void ShowWarning(string warningText) { if (string.IsNullOrEmpty(warningText)) @@ -208,15 +229,15 @@ namespace XenAdmin.Wizards.GenericPages { foreach (DataGridViewRow row in m_dataGridView.Rows) { - string sysId = (string)row.Cells[0].Tag; + var sysId = (string)row.Cells[0].Tag; if (m_vmMappings.ContainsKey(sysId)) { var mapping = m_vmMappings[sysId]; - DataGridViewEnableableComboBoxCell cbCell = row.Cells[m_colTarget.Index] as DataGridViewEnableableComboBoxCell; + var cbCell = row.Cells[m_colTarget.Index] as DataGridViewEnableableComboBoxCell; System.Diagnostics.Debug.Assert(cbCell != null, "ComboBox cell was not found"); - IEnableableXenObjectComboBoxItem selectedItem = cbCell.Value as IEnableableXenObjectComboBoxItem; + var selectedItem = cbCell.Value as IEnableableXenObjectComboBoxItem; System.Diagnostics.Debug.Assert(selectedItem != null, "Vm has no target mapped"); var type = selectedItem.Item.GetType(); @@ -231,7 +252,7 @@ namespace XenAdmin.Wizards.GenericPages return m_vmMappings; } - set { m_vmMappings = value; } + set => m_vmMappings = value; } #endregion @@ -257,8 +278,7 @@ namespace XenAdmin.Wizards.GenericPages foreach (var item in m_comboBoxConnection.Items) { - DelayLoadingOptionComboBoxItem tempItem = item as DelayLoadingOptionComboBoxItem; - if (tempItem != null) + if (item is DelayLoadingOptionComboBoxItem tempItem) tempItem.ReasonUpdated -= DelayLoadedComboBoxItem_ReasonChanged; } m_comboBoxConnection.Items.Clear(); @@ -290,11 +310,11 @@ namespace XenAdmin.Wizards.GenericPages { DelayLoadingOptionComboBoxItem item = null; - Pool pool = Helpers.GetPool(xenConnection); + var pool = Helpers.GetPool(xenConnection); if (pool == null) { - Host host = Helpers.GetCoordinator(xenConnection); + var host = Helpers.GetCoordinator(xenConnection); if (host != null) { @@ -345,7 +365,7 @@ namespace XenAdmin.Wizards.GenericPages { foreach (DataGridViewRow row in m_dataGridView.Rows) { - string sysId = (string)row.Cells[m_colVmName.Index].Tag; + var sysId = (string)row.Cells[m_colVmName.Index].Tag; if (m_vmMappings.TryGetValue(sysId, out var mapping) && row.Cells[m_colTarget.Index] is DataGridViewEnableableComboBoxCell cbCell) @@ -485,17 +505,16 @@ namespace XenAdmin.Wizards.GenericPages Program.Invoke(this, () => { - int index = m_comboBoxConnection.Items.IndexOf(item); + var index = m_comboBoxConnection.Items.IndexOf(item); if (index < 0 || index >= m_comboBoxConnection.Items.Count) return; if (updatingDestinationCombobox || updatingHomeServerList) return; - int selectedIndex = m_comboBoxConnection.SelectedIndex; + var selectedIndex = m_comboBoxConnection.SelectedIndex; - var tempItem = m_comboBoxConnection.Items[index] as DelayLoadingOptionComboBoxItem; - if (tempItem == null) + if (!(m_comboBoxConnection.Items[index] is DelayLoadingOptionComboBoxItem tempItem)) throw new NullReferenceException("Trying to update delay loaded reason but failed to extract reason"); tempItem.CopyFrom(item); @@ -527,8 +546,7 @@ namespace XenAdmin.Wizards.GenericPages if (item == null) throw new NullReferenceException("Trying to update delay loaded reason but failed to extract reason"); - var cb = item.ParentComboBox as DataGridViewEnableableComboBoxCell; - if (cb == null) + if (!(item.ParentComboBox is DataGridViewEnableableComboBoxCell cb)) return; Program.Invoke(this, () => @@ -595,7 +613,7 @@ namespace XenAdmin.Wizards.GenericPages //If the item is delay loading and them item is disabled, null the selection made //and clear the table containing server data - IEnableableXenObjectComboBoxItem item = m_comboBoxConnection.SelectedItem as IEnableableXenObjectComboBoxItem; + var item = m_comboBoxConnection.SelectedItem as IEnableableXenObjectComboBoxItem; if (item != null && !item.Enabled) { m_comboBoxConnection.SelectedIndex = -1; @@ -604,8 +622,7 @@ namespace XenAdmin.Wizards.GenericPages return; } - AddHostRunningComboBoxItem exeItem = m_comboBoxConnection.SelectedItem as AddHostRunningComboBoxItem; - if (exeItem != null && !updatingDestinationCombobox) + if (m_comboBoxConnection.SelectedItem is AddHostRunningComboBoxItem exeItem && !updatingDestinationCombobox) exeItem.RunCommand(this); else if (!updatingDestinationCombobox) @@ -643,8 +660,7 @@ namespace XenAdmin.Wizards.GenericPages m_dataGridView.BeginEdit(false); - var editingControl = m_dataGridView.EditingControl as ComboBox; - if (editingControl != null) + if (m_dataGridView.EditingControl is ComboBox editingControl) editingControl.DroppedDown = true; } @@ -699,8 +715,7 @@ namespace XenAdmin.Wizards.GenericPages { foreach (var item in m_comboBoxConnection.Items) { - DelayLoadingOptionComboBoxItem comboBoxItem = item as DelayLoadingOptionComboBoxItem; - if (comboBoxItem != null) + if (item is DelayLoadingOptionComboBoxItem comboBoxItem) comboBoxItem.CancelFilters(); } } diff --git a/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.resx b/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.resx index 268d98e59..618111dbb 100644 --- a/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.resx +++ b/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.resx @@ -300,9 +300,6 @@ 2 - - Left - 3, 3 diff --git a/XenAdmin/Wizards/GenericPages/VMMappingSummary.cs b/XenAdmin/Wizards/GenericPages/VMMappingSummary.cs index f9d466242..d2baab1f6 100644 --- a/XenAdmin/Wizards/GenericPages/VMMappingSummary.cs +++ b/XenAdmin/Wizards/GenericPages/VMMappingSummary.cs @@ -166,46 +166,6 @@ namespace XenAdmin.Wizards.GenericPages } } - public class TargetServerSummary : MappingSummaryDecorator - { - private readonly VmMapping mapping; - private readonly IXenConnection connection; - - public TargetServerSummary(MappingSummary summary, VmMapping mapping, IXenConnection connection) - : base(summary) - { - this.mapping = mapping; - this.connection = connection; - } - - public override List Details - { - get - { - List decoratedSummary = summary.Details; - decoratedSummary.Add(new SummaryDetails(Messages.CPM_SUMMARY_KEY_HOME_SERVER, ResolveLabel())); - return decoratedSummary; - } - } - - private string ResolveLabel() - { - if (mapping.XenRef is XenRef) - { - Host targetHost = connection.Resolve(mapping.XenRef as XenRef); - - if (targetHost == null) - { - return Messages.UNKNOWN; - } - - return mapping.TargetName; - } - - return Messages.CPM_SUMMARY_UNSET; - } - } - public class StorageSummary : MappingSummaryDecorator { private readonly VmMapping mapping; @@ -355,9 +315,6 @@ namespace XenAdmin.Wizards.GenericPages this.summary = summary; } - public override List Details - { - get { return summary != null ? summary.Details : new List(); } - } + public override List Details => summary != null ? summary.Details : new List(); } } diff --git a/XenAdmin/Wizards/ImportWizard/ImportFinishPage.cs b/XenAdmin/Wizards/ImportWizard/ImportFinishPage.cs index 3a339b0e1..beffc2451 100644 --- a/XenAdmin/Wizards/ImportWizard/ImportFinishPage.cs +++ b/XenAdmin/Wizards/ImportWizard/ImportFinishPage.cs @@ -87,10 +87,17 @@ namespace XenAdmin.Wizards.ImportWizard public Func>> SummaryRetriever { private get; set; } + private bool _canStartVmsAutomatically = true; + public bool CanStartVmsAutomatically + { + get => _canStartVmsAutomatically; + set => _canStartVmsAutomatically = m_checkBoxStartVms.Enabled = m_checkBoxStartVms.Checked = value; + } + /// /// Do the action described after the import/export has finished? /// - public bool StartVmsAutomatically => m_checkBoxStartVms.Visible && m_checkBoxStartVms.Checked; + public bool StartVmsAutomatically => CanStartVmsAutomatically && m_checkBoxStartVms.Visible && m_checkBoxStartVms.Checked; public bool ShowStartVmsGroupBox { diff --git a/XenAdmin/Wizards/ImportWizard/ImportSelectHostPage.cs b/XenAdmin/Wizards/ImportWizard/ImportSelectHostPage.cs index 8240b7557..d89fbc83b 100755 --- a/XenAdmin/Wizards/ImportWizard/ImportSelectHostPage.cs +++ b/XenAdmin/Wizards/ImportWizard/ImportSelectHostPage.cs @@ -50,12 +50,16 @@ namespace XenAdmin.Wizards.ImportWizard private List vgpuSettings = new List(); private List hardwarePlatformSettings = new List(); private List vendorDeviceSettings = new List(); - + private int _ovfMaxVCpusCount; + private long _ovfMemory; + private readonly List _ovfVCpusCount; public event Action ConnectionSelectionChanged; public ImportSelectHostPage() { InitializeText(); + ShowWarning(null); + _ovfVCpusCount = new List(); } #region XenTabPage overrides @@ -109,6 +113,52 @@ namespace XenAdmin.Wizards.ImportWizard if (data == null) continue; + _ovfVCpusCount.Clear(); + foreach (var rasdType in vhs.Item) + { + // Processor + if (rasdType.ResourceType.Value == 3 && + int.TryParse(rasdType.VirtualQuantity.Value.ToString(), out var vCpusCount)) + { + _ovfVCpusCount.Add(vCpusCount); + if (_ovfMaxVCpusCount < vCpusCount) + { + _ovfMaxVCpusCount = vCpusCount; + } + } + // Memory + if (rasdType.ResourceType.Value == 4 && double.TryParse(rasdType.VirtualQuantity.Value.ToString(), out var memory)) + { + //The default memory unit is MB (2^20), however, the RASD may contain a different + //one with format byte*memoryBase^memoryPower (byte being a literal string) + + double memoryBase = 2.0; + double memoryPower = 20.0; + + if (rasdType.AllocationUnits.Value.ToLower().StartsWith("byte")) + { + string[] a1 = rasdType.AllocationUnits.Value.Split('*', '^'); + + if (a1.Length == 3) + { + if (!double.TryParse(a1[1].Trim(), out memoryBase)) + memoryBase = 2.0; + if (!double.TryParse(a1[2].Trim(), out memoryPower)) + memoryPower = 20.0; + } + } + + double memoryMultiplier = Math.Pow(memoryBase, memoryPower); + memory *= memoryMultiplier; + + if (memory > long.MaxValue) + memory = long.MaxValue; + + if (_ovfMemory < memory) + _ovfMemory = (long)memory; + } + } + foreach (var s in data) { if (s.Name == "vgpu") @@ -128,7 +178,7 @@ namespace XenAdmin.Wizards.ImportWizard protected override string TargetServerSelectionIntroText => Messages.IMPORT_WIZARD_DESTINATION_TABLE_INTRO; - protected override void OnChosenItemChanged() + protected override void OnSelectedTargetPoolChanged() { var warnings = new List(); @@ -151,12 +201,36 @@ namespace XenAdmin.Wizards.ImportWizard else if (VmMappings.Count > 1) warnings.Add(Messages.IMPORT_VM_WITH_VGPU_WARNING_MANY); } + + var ovfCountsAboveLimit = _ovfVCpusCount.Count(vCpusCount => vCpusCount > VM.MAX_VCPUS_FOR_NON_TRUSTED_VMS); + if (ovfCountsAboveLimit > 0) + { + warnings.Add(string.Format(Messages.IMPORT_VM_CPUS_COUNT_UNTRUSTED_WARNING, ovfCountsAboveLimit, VM.MAX_VCPUS_FOR_NON_TRUSTED_VMS, BrandManager.BrandConsole)); + } } - ShowWarning(string.Join("\n", warnings)); + ApplianceCanBeStarted = true; - if (ConnectionSelectionChanged != null) - ConnectionSelectionChanged(SelectedTargetPool?.Connection); + if (!CheckDestinationHasEnoughPhysicalCpus(out var physicalCpusWarningMessage)) + { + warnings.Add(physicalCpusWarningMessage); + ApplianceCanBeStarted = false; + } + + if (!CheckDestinationHasEnoughMemory(out var memoryWarningMessage)) + { + warnings.Add(memoryWarningMessage); + ApplianceCanBeStarted = false; + } + + ShowWarning(string.Join("\n\n", warnings)); + + ConnectionSelectionChanged?.Invoke(SelectedTargetPool?.Connection); + } + + protected override void OnSelectedTargetChanged() + { + OnSelectedTargetPoolChanged(); } protected override DelayLoadingOptionComboBoxItem CreateDelayLoadingOptionComboBoxItem(IXenObject xenItem) @@ -208,6 +282,120 @@ namespace XenAdmin.Wizards.ImportWizard return true; } + /// + /// Check if the appliance can be started on the selected host or pool. Note that if the user selects + /// a shared SR in other pages, the VM could still start. The check considers both vCPU count and memory requirements + /// of the appliance. + /// + public bool ApplianceCanBeStarted { get; private set; } = true; + + private bool CheckDestinationHasEnoughPhysicalCpus(out string warningMessage) + { + warningMessage = string.Empty; + + var selectedTarget = SelectedTarget ?? SelectedTargetPool; + var physicalCpusCount = GetPhysicalCpus(selectedTarget); + + if (physicalCpusCount < 0 || physicalCpusCount >= _ovfMaxVCpusCount) + return true; + + if (selectedTarget is Pool) + warningMessage = string.Format(Messages.IMPORT_WIZARD_CPUS_COUNT_MISMATCH_POOL, _ovfMaxVCpusCount, physicalCpusCount); + else if (selectedTarget is Host) + warningMessage = string.Format(Messages.IMPORT_WIZARD_CPUS_COUNT_MISMATCH_HOST, _ovfMaxVCpusCount, physicalCpusCount); + else + return true; + + return false; + } + + private bool CheckDestinationHasEnoughMemory(out string warningMessage) + { + warningMessage = string.Empty; + + var selectedTarget = SelectedTarget ?? SelectedTargetPool; + var memory = GetFreeMemory(selectedTarget); + + if (memory >= _ovfMemory) + return true; + + if (selectedTarget is Pool) + warningMessage = string.Format(Messages.IMPORT_WIZARD_INSUFFICIENT_MEMORY_POOL, Util.MemorySizeStringSuitableUnits(_ovfMemory, true), Util.MemorySizeStringSuitableUnits(memory, true)); + else if (selectedTarget is Host) + warningMessage = string.Format(Messages.IMPORT_WIZARD_INSUFFICIENT_MEMORY_HOST, Util.MemorySizeStringSuitableUnits(_ovfMemory, true), Util.MemorySizeStringSuitableUnits(memory, true)); + else + return true; + + return false; + } + + /// + /// Returns the number of physical CPUs on the specified ( or ) or -1 if the value cannot be determined. + /// + /// The XenObject for which to determine the number of physical CPUs. + /// The number of physical CPUs on the specified or -1 if the value cannot be determined. + private int GetPhysicalCpus(IXenObject xenObject) + { + var physicalCpusCount = -1; + + switch (xenObject) + { + case Host host: + { + var hostCpuCount = host.CpuCount(); + if(hostCpuCount > 0) + physicalCpusCount = hostCpuCount; + break; + } + case Pool pool: + { + var hosts = pool.Connection.Cache.Hosts; + var maxCpuCounts = hosts + .Select(h => h.CpuCount()) + .ToList(); + if (maxCpuCounts.Count > 0) + { + physicalCpusCount = maxCpuCounts.Max(); + } + + break; + } + } + + return physicalCpusCount; + } + + private long GetFreeMemory(IXenObject xenObject) + { + long memory = 0; + + switch (xenObject) + { + case Host host: + { + var hostMemory = host.memory_available_calc(); + if (hostMemory > 0) + memory = hostMemory; + break; + } + case Pool pool: + { + var hosts = pool.Connection.Cache.Hosts; + var maxMemories = hosts + .Select(h => h.memory_available_calc()) + .ToList(); + if (maxMemories.Count > 0) + { + memory = maxMemories.Max(); + } + + break; + } + } + + return memory; + } + private bool CheckDestinationSupportsVendorDevice() { var dundeeOrNewerHosts = Helpers.DundeeOrGreater(SelectedTargetPool.Connection) ? SelectedTargetPool.Connection.Cache.Hosts : new Host[] {}; diff --git a/XenAdmin/Wizards/ImportWizard/ImportWizard.cs b/XenAdmin/Wizards/ImportWizard/ImportWizard.cs index ed4c04acd..05f36e108 100644 --- a/XenAdmin/Wizards/ImportWizard/ImportWizard.cs +++ b/XenAdmin/Wizards/ImportWizard/ImportWizard.cs @@ -372,6 +372,21 @@ namespace XenAdmin.Wizards.ImportWizard && lunPerVdiMappingPage.MapLunsToVdisRequired && m_typeOfImport == ImportType.Ovf) AddAfterPage(m_pageStorage, lunPerVdiMappingPage); + + // If the user has selected shared SRs, we cannot be sure that the VMs can't be started. + // m_pageHost.ApplianceCanBeStarted only checks the number of pCPUs on the selected target. + // We therefore allow users to selected "Start VMs automatically", as they will be shown + // an error message in case their configuration isn't valid. + var canStartVMsAutomatically = m_pageHost.ApplianceCanBeStarted || + m_pageStorage.VmMappings.Values + .SelectMany(mapping => mapping.Storage.Values) + .Any(sr => sr != null && sr.shared); + + if(canStartVMsAutomatically != m_pageFinish.CanStartVmsAutomatically) + { + m_pageFinish.CanStartVmsAutomatically = canStartVMsAutomatically; + NotifyNextPagesOfChange(m_pageFinish); + } } else if (type == typeof(LunPerVdiImportPage)) { @@ -567,7 +582,7 @@ namespace XenAdmin.Wizards.ImportWizard { var temp = new List(); temp.Add(new Tuple(Messages.FINISH_PAGE_VMNAME, m_pageXvaStorage.ImportedVm.Name())); - temp.Add(new Tuple(Messages.FINISH_PAGE_TARGET, m_pageXvaHost.SelectedHost == null ? m_pageXvaHost.SelectedConnection.Name : m_pageXvaHost.SelectedHost.Name())); + temp.Add(new Tuple(Messages.FINISH_PAGE_TARGET_FOR_VM, m_pageXvaHost.SelectedHost == null ? m_pageXvaHost.SelectedConnection.Name : m_pageXvaHost.SelectedHost.Name())); temp.Add(new Tuple(Messages.FINISH_PAGE_STORAGE, m_pageXvaStorage.SR.Name())); var con = m_pageXvaHost.SelectedHost == null ? m_pageXvaHost.SelectedConnection : m_pageXvaHost.SelectedHost.Connection; @@ -632,11 +647,9 @@ namespace XenAdmin.Wizards.ImportWizard foreach (var mapping in m_vmMappings.Values) { - var targetLbl = m_vmMappings.Count == 1 ? Messages.FINISH_PAGE_TARGET : string.Format(Messages.FINISH_PAGE_TARGET_FOR_VM, mapping.VmNameLabel); var storageLbl = m_vmMappings.Count == 1 ? Messages.FINISH_PAGE_STORAGE : string.Format(Messages.FINISH_PAGE_STORAGE_FOR_VM, mapping.VmNameLabel); var networkLbl = m_vmMappings.Count == 1 ? Messages.FINISH_PAGE_NETWORK : string.Format(Messages.FINISH_PAGE_NETWORK_FOR_VM, mapping.VmNameLabel); - temp.Add(new Tuple(targetLbl, mapping.TargetName)); bool first = true; foreach (var sr in mapping.Storage) { diff --git a/XenAdmin/Wizards/NewVMWizard/NewVMWizard.cs b/XenAdmin/Wizards/NewVMWizard/NewVMWizard.cs index d58428ac2..babfb5d06 100644 --- a/XenAdmin/Wizards/NewVMWizard/NewVMWizard.cs +++ b/XenAdmin/Wizards/NewVMWizard/NewVMWizard.cs @@ -62,7 +62,7 @@ namespace XenAdmin.Wizards.NewVMWizard private readonly Page_CloudConfigParameters page_CloudConfigParameters; private Host m_affinity; - private bool BlockAffinitySelection = false; + private bool BlockAffinitySelection; private bool gpuCapability; public AsyncAction Action; @@ -131,7 +131,7 @@ namespace XenAdmin.Wizards.NewVMWizard } #endregion - page_8_Finish.SummaryRetreiver = GetSummary; + page_8_Finish.SummaryRetriever = GetSummary; AddPages(page_1_Template, page_2_Name, page_3_InstallationMedia, page_4_HomeServer, page_5_CpuMem, page_6_Storage, page_7_Networking, page_8_Finish); @@ -161,8 +161,8 @@ namespace XenAdmin.Wizards.NewVMWizard page_3_InstallationMedia.SelectedUrl, page_3_InstallationMedia.SelectedBootMode, m_affinity, - page_5_CpuMem.SelectedVcpusMax, - page_5_CpuMem.SelectedVcpusAtStartup, + page_5_CpuMem.SelectedVCpusMax, + page_5_CpuMem.SelectedVCpusAtStartup, (long)page_5_CpuMem.SelectedMemoryDynamicMin, (long)page_5_CpuMem.SelectedMemoryDynamicMax, (long)page_5_CpuMem.SelectedMemoryStaticMax, @@ -185,13 +185,14 @@ namespace XenAdmin.Wizards.NewVMWizard base.FinishWizard(); } - protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e) + protected override void OnKeyPress(KeyPressEventArgs e) { if (page_CloudConfigParameters != null && page_CloudConfigParameters.ActiveControl is TextBox && e.KeyChar == (char)Keys.Enter) return; base.OnKeyPress(e); } + protected override void UpdateWizardContent(XenTabPage senderPage) { var prevPageType = senderPage.GetType(); @@ -284,6 +285,10 @@ namespace XenAdmin.Wizards.NewVMWizard AddAfterPage(page_6_Storage, page_6b_LunPerVdi); } } + else if (prevPageType == typeof(Page_CpuMem)) + { + page_8_Finish.CanStartImmediately = CanStartVm(); + } } protected override string WizardPaneHelpID() @@ -291,6 +296,22 @@ namespace XenAdmin.Wizards.NewVMWizard return CurrentStepTabPage is RBACWarningPage ? FormatHelpId("Rbac") : base.WizardPaneHelpID(); } + private bool CanStartVm() + { + var homeHost = page_6_Storage.FullCopySR?.Home(); + + if (homeHost != null) + { + if (homeHost.CpuCount() < page_5_CpuMem.SelectedVCpusMax) + return false; + + if (homeHost.memory_available_calc() < page_5_CpuMem.SelectedMemoryDynamicMin) + return false; + } + + return page_5_CpuMem.CanStartVm; + } + private void ShowXenAppXenDesktopWarning(IXenConnection connection) { if (connection != null && connection.Cache.Hosts.Any(h => h.DesktopFeaturesEnabled() || h.DesktopPlusFeaturesEnabled() || h.DesktopCloudFeaturesEnabled())) diff --git a/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.Designer.cs b/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.Designer.cs index 3b7f90884..dc44896b7 100644 --- a/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.Designer.cs +++ b/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.Designer.cs @@ -29,63 +29,104 @@ namespace XenAdmin.Wizards.NewVMWizard private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Page_CpuMem)); - this.labelVCPUs = new System.Windows.Forms.Label(); - this.label5 = new System.Windows.Forms.Label(); - this.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.ErrorLabel = new System.Windows.Forms.Label(); - this.ErrorPanel = new System.Windows.Forms.Panel(); - this.spinnerDynMin = new XenAdmin.Controls.Ballooning.MemorySpinner(); - this.spinnerDynMax = new XenAdmin.Controls.Ballooning.MemorySpinner(); - this.spinnerStatMax = new XenAdmin.Controls.Ballooning.MemorySpinner(); - this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this.vCPUWarningLabel = new System.Windows.Forms.Label(); - this.initialVCPUWarningLabel = new System.Windows.Forms.Label(); - this.comboBoxInitialVCPUs = new System.Windows.Forms.ComboBox(); - this.labelInitialVCPUs = new System.Windows.Forms.Label(); - this.labelInvalidVCPUWarning = new System.Windows.Forms.Label(); - this.comboBoxTopology = new XenAdmin.Controls.CPUTopologyComboBox(); - this.labelTopology = new System.Windows.Forms.Label(); - this.comboBoxVCPUs = new System.Windows.Forms.ComboBox(); - this.labelDynMin = new System.Windows.Forms.Label(); - this.labelDynMax = new System.Windows.Forms.Label(); - this.labelStatMax = new System.Windows.Forms.Label(); - this.labelDynMinInfo = new System.Windows.Forms.Label(); - this.labelDynMaxInfo = new System.Windows.Forms.Label(); + this.warningsTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.cpuWarningPictureBox = new System.Windows.Forms.PictureBox(); + this.cpuWarningLabel = new System.Windows.Forms.Label(); + this.memoryWarningLabel = new System.Windows.Forms.Label(); + this.memoryPictureBox = new System.Windows.Forms.PictureBox(); this.labelStatMaxInfo = new System.Windows.Forms.Label(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); - this.ErrorPanel.SuspendLayout(); + this.labelDynMaxInfo = new System.Windows.Forms.Label(); + this.labelDynMinInfo = new System.Windows.Forms.Label(); + this.labelStatMax = new System.Windows.Forms.Label(); + this.labelDynMax = new System.Windows.Forms.Label(); + this.labelDynMin = new System.Windows.Forms.Label(); + this.spinnerDynMin = new XenAdmin.Controls.Ballooning.MemorySpinner(); + this.comboBoxVCPUs = new System.Windows.Forms.ComboBox(); + this.labelTopology = new System.Windows.Forms.Label(); + this.spinnerDynMax = new XenAdmin.Controls.Ballooning.MemorySpinner(); + this.labelVCPUs = new System.Windows.Forms.Label(); + this.spinnerStatMax = new XenAdmin.Controls.Ballooning.MemorySpinner(); + this.label5 = new System.Windows.Forms.Label(); + this.comboBoxTopology = new XenAdmin.Controls.CPUTopologyComboBox(); + this.labelInitialVCPUs = new System.Windows.Forms.Label(); + this.comboBoxInitialVCPUs = new System.Windows.Forms.ComboBox(); + this.initialVCPUWarningLabel = new System.Windows.Forms.Label(); + this.vCPUWarningLabel = new System.Windows.Forms.Label(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.pictureBoxTopology = new System.Windows.Forms.PictureBox(); + this.labelTopologyWarning = new System.Windows.Forms.Label(); + this.warningsTableLayoutPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.cpuWarningPictureBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.memoryPictureBox)).BeginInit(); this.tableLayoutPanel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTopology)).BeginInit(); this.SuspendLayout(); // - // labelVCPUs + // warningsTableLayoutPanel // - resources.ApplyResources(this.labelVCPUs, "labelVCPUs"); - this.labelVCPUs.Name = "labelVCPUs"; + resources.ApplyResources(this.warningsTableLayoutPanel, "warningsTableLayoutPanel"); + this.tableLayoutPanel1.SetColumnSpan(this.warningsTableLayoutPanel, 4); + this.warningsTableLayoutPanel.Controls.Add(this.pictureBoxTopology, 0, 2); + this.warningsTableLayoutPanel.Controls.Add(this.cpuWarningPictureBox, 0, 0); + this.warningsTableLayoutPanel.Controls.Add(this.cpuWarningLabel, 1, 0); + this.warningsTableLayoutPanel.Controls.Add(this.memoryWarningLabel, 1, 4); + this.warningsTableLayoutPanel.Controls.Add(this.memoryPictureBox, 0, 4); + this.warningsTableLayoutPanel.Controls.Add(this.labelTopologyWarning, 1, 2); + this.warningsTableLayoutPanel.Name = "warningsTableLayoutPanel"; // - // label5 + // cpuWarningPictureBox // - resources.ApplyResources(this.label5, "label5"); - this.tableLayoutPanel1.SetColumnSpan(this.label5, 4); - this.label5.Name = "label5"; + this.cpuWarningPictureBox.Image = global::XenAdmin.Properties.Resources._000_Alert2_h32bit_16; + resources.ApplyResources(this.cpuWarningPictureBox, "cpuWarningPictureBox"); + this.cpuWarningPictureBox.Name = "cpuWarningPictureBox"; + this.cpuWarningPictureBox.TabStop = false; // - // pictureBox1 + // cpuWarningLabel // - this.pictureBox1.Image = global::XenAdmin.Properties.Resources._000_Alert2_h32bit_16; - resources.ApplyResources(this.pictureBox1, "pictureBox1"); - this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.TabStop = false; + resources.ApplyResources(this.cpuWarningLabel, "cpuWarningLabel"); + this.cpuWarningLabel.Name = "cpuWarningLabel"; // - // ErrorLabel + // memoryWarningLabel // - resources.ApplyResources(this.ErrorLabel, "ErrorLabel"); - this.ErrorLabel.Name = "ErrorLabel"; + resources.ApplyResources(this.memoryWarningLabel, "memoryWarningLabel"); + this.memoryWarningLabel.Name = "memoryWarningLabel"; // - // ErrorPanel + // memoryPictureBox // - this.ErrorPanel.Controls.Add(this.ErrorLabel); - this.ErrorPanel.Controls.Add(this.pictureBox1); - resources.ApplyResources(this.ErrorPanel, "ErrorPanel"); - this.ErrorPanel.Name = "ErrorPanel"; + this.memoryPictureBox.Image = global::XenAdmin.Properties.Resources._000_Alert2_h32bit_16; + resources.ApplyResources(this.memoryPictureBox, "memoryPictureBox"); + this.memoryPictureBox.Name = "memoryPictureBox"; + this.memoryPictureBox.TabStop = false; + // + // labelStatMaxInfo + // + resources.ApplyResources(this.labelStatMaxInfo, "labelStatMaxInfo"); + this.labelStatMaxInfo.Name = "labelStatMaxInfo"; + // + // labelDynMaxInfo + // + resources.ApplyResources(this.labelDynMaxInfo, "labelDynMaxInfo"); + this.labelDynMaxInfo.Name = "labelDynMaxInfo"; + // + // labelDynMinInfo + // + resources.ApplyResources(this.labelDynMinInfo, "labelDynMinInfo"); + this.labelDynMinInfo.Name = "labelDynMinInfo"; + // + // labelStatMax + // + resources.ApplyResources(this.labelStatMax, "labelStatMax"); + this.labelStatMax.Name = "labelStatMax"; + // + // labelDynMax + // + resources.ApplyResources(this.labelDynMax, "labelDynMax"); + this.labelDynMax.Name = "labelDynMax"; + // + // labelDynMin + // + resources.ApplyResources(this.labelDynMin, "labelDynMin"); + this.labelDynMin.Name = "labelDynMin"; // // spinnerDynMin // @@ -95,6 +136,19 @@ namespace XenAdmin.Wizards.NewVMWizard this.spinnerDynMin.Name = "spinnerDynMin"; this.spinnerDynMin.SpinnerValueChanged += new System.EventHandler(this.memory_ValueChanged); // + // comboBoxVCPUs + // + this.comboBoxVCPUs.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxVCPUs.FormattingEnabled = true; + resources.ApplyResources(this.comboBoxVCPUs, "comboBoxVCPUs"); + this.comboBoxVCPUs.Name = "comboBoxVCPUs"; + this.comboBoxVCPUs.SelectedIndexChanged += new System.EventHandler(this.vCPU_ValueChanged); + // + // labelTopology + // + resources.ApplyResources(this.labelTopology, "labelTopology"); + this.labelTopology.Name = "labelTopology"; + // // spinnerDynMax // resources.ApplyResources(this.spinnerDynMax, "spinnerDynMax"); @@ -103,6 +157,11 @@ namespace XenAdmin.Wizards.NewVMWizard this.spinnerDynMax.Name = "spinnerDynMax"; this.spinnerDynMax.SpinnerValueChanged += new System.EventHandler(this.memory_ValueChanged); // + // labelVCPUs + // + resources.ApplyResources(this.labelVCPUs, "labelVCPUs"); + this.labelVCPUs.Name = "labelVCPUs"; + // // spinnerStatMax // resources.ApplyResources(this.spinnerStatMax, "spinnerStatMax"); @@ -111,63 +170,11 @@ namespace XenAdmin.Wizards.NewVMWizard this.spinnerStatMax.Name = "spinnerStatMax"; this.spinnerStatMax.SpinnerValueChanged += new System.EventHandler(this.memory_ValueChanged); // - // tableLayoutPanel1 + // label5 // - resources.ApplyResources(this.tableLayoutPanel1, "tableLayoutPanel1"); - this.tableLayoutPanel1.Controls.Add(this.vCPUWarningLabel, 2, 1); - this.tableLayoutPanel1.Controls.Add(this.initialVCPUWarningLabel, 2, 4); - this.tableLayoutPanel1.Controls.Add(this.comboBoxInitialVCPUs, 1, 4); - this.tableLayoutPanel1.Controls.Add(this.labelInitialVCPUs, 0, 4); - this.tableLayoutPanel1.Controls.Add(this.labelInvalidVCPUWarning, 1, 3); - this.tableLayoutPanel1.Controls.Add(this.comboBoxTopology, 1, 2); - this.tableLayoutPanel1.Controls.Add(this.label5, 0, 0); - this.tableLayoutPanel1.Controls.Add(this.spinnerStatMax, 1, 8); - this.tableLayoutPanel1.Controls.Add(this.labelVCPUs, 0, 1); - this.tableLayoutPanel1.Controls.Add(this.spinnerDynMax, 1, 7); - this.tableLayoutPanel1.Controls.Add(this.labelTopology, 0, 2); - this.tableLayoutPanel1.Controls.Add(this.comboBoxVCPUs, 1, 1); - this.tableLayoutPanel1.Controls.Add(this.spinnerDynMin, 1, 6); - this.tableLayoutPanel1.Controls.Add(this.labelDynMin, 0, 6); - this.tableLayoutPanel1.Controls.Add(this.labelDynMax, 0, 7); - this.tableLayoutPanel1.Controls.Add(this.labelStatMax, 0, 8); - this.tableLayoutPanel1.Controls.Add(this.labelDynMinInfo, 3, 6); - this.tableLayoutPanel1.Controls.Add(this.labelDynMaxInfo, 3, 7); - this.tableLayoutPanel1.Controls.Add(this.labelStatMaxInfo, 3, 8); - this.tableLayoutPanel1.Name = "tableLayoutPanel1"; - // - // vCPUWarningLabel - // - resources.ApplyResources(this.vCPUWarningLabel, "vCPUWarningLabel"); - this.tableLayoutPanel1.SetColumnSpan(this.vCPUWarningLabel, 2); - this.vCPUWarningLabel.ForeColor = System.Drawing.Color.Red; - this.vCPUWarningLabel.Name = "vCPUWarningLabel"; - // - // initialVCPUWarningLabel - // - resources.ApplyResources(this.initialVCPUWarningLabel, "initialVCPUWarningLabel"); - this.tableLayoutPanel1.SetColumnSpan(this.initialVCPUWarningLabel, 2); - this.initialVCPUWarningLabel.ForeColor = System.Drawing.Color.Red; - this.initialVCPUWarningLabel.Name = "initialVCPUWarningLabel"; - // - // comboBoxInitialVCPUs - // - this.comboBoxInitialVCPUs.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxInitialVCPUs.FormattingEnabled = true; - resources.ApplyResources(this.comboBoxInitialVCPUs, "comboBoxInitialVCPUs"); - this.comboBoxInitialVCPUs.Name = "comboBoxInitialVCPUs"; - this.comboBoxInitialVCPUs.SelectedIndexChanged += new System.EventHandler(this.comboBoxInitialVCPUs_SelectedIndexChanged); - // - // labelInitialVCPUs - // - resources.ApplyResources(this.labelInitialVCPUs, "labelInitialVCPUs"); - this.labelInitialVCPUs.Name = "labelInitialVCPUs"; - // - // labelInvalidVCPUWarning - // - resources.ApplyResources(this.labelInvalidVCPUWarning, "labelInvalidVCPUWarning"); - this.tableLayoutPanel1.SetColumnSpan(this.labelInvalidVCPUWarning, 3); - this.labelInvalidVCPUWarning.ForeColor = System.Drawing.Color.Red; - this.labelInvalidVCPUWarning.Name = "labelInvalidVCPUWarning"; + resources.ApplyResources(this.label5, "label5"); + this.tableLayoutPanel1.SetColumnSpan(this.label5, 4); + this.label5.Name = "label5"; // // comboBoxTopology // @@ -178,89 +185,113 @@ namespace XenAdmin.Wizards.NewVMWizard this.comboBoxTopology.Name = "comboBoxTopology"; this.comboBoxTopology.SelectedIndexChanged += new System.EventHandler(this.comboBoxTopology_SelectedIndexChanged); // - // labelTopology + // labelInitialVCPUs // - resources.ApplyResources(this.labelTopology, "labelTopology"); - this.labelTopology.Name = "labelTopology"; + resources.ApplyResources(this.labelInitialVCPUs, "labelInitialVCPUs"); + this.labelInitialVCPUs.Name = "labelInitialVCPUs"; // - // comboBoxVCPUs + // comboBoxInitialVCPUs // - this.comboBoxVCPUs.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxVCPUs.FormattingEnabled = true; - resources.ApplyResources(this.comboBoxVCPUs, "comboBoxVCPUs"); - this.comboBoxVCPUs.Name = "comboBoxVCPUs"; - this.comboBoxVCPUs.SelectedIndexChanged += new System.EventHandler(this.vCPU_ValueChanged); + this.comboBoxInitialVCPUs.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxInitialVCPUs.FormattingEnabled = true; + resources.ApplyResources(this.comboBoxInitialVCPUs, "comboBoxInitialVCPUs"); + this.comboBoxInitialVCPUs.Name = "comboBoxInitialVCPUs"; + this.comboBoxInitialVCPUs.SelectedIndexChanged += new System.EventHandler(this.comboBoxInitialVCPUs_SelectedIndexChanged); // - // labelDynMin + // initialVCPUWarningLabel // - resources.ApplyResources(this.labelDynMin, "labelDynMin"); - this.labelDynMin.Name = "labelDynMin"; + resources.ApplyResources(this.initialVCPUWarningLabel, "initialVCPUWarningLabel"); + this.tableLayoutPanel1.SetColumnSpan(this.initialVCPUWarningLabel, 2); + this.initialVCPUWarningLabel.ForeColor = System.Drawing.Color.Red; + this.initialVCPUWarningLabel.Name = "initialVCPUWarningLabel"; // - // labelDynMax + // vCPUWarningLabel // - resources.ApplyResources(this.labelDynMax, "labelDynMax"); - this.labelDynMax.Name = "labelDynMax"; + resources.ApplyResources(this.vCPUWarningLabel, "vCPUWarningLabel"); + this.tableLayoutPanel1.SetColumnSpan(this.vCPUWarningLabel, 2); + this.vCPUWarningLabel.ForeColor = System.Drawing.Color.Red; + this.vCPUWarningLabel.Name = "vCPUWarningLabel"; // - // labelStatMax + // tableLayoutPanel1 // - resources.ApplyResources(this.labelStatMax, "labelStatMax"); - this.labelStatMax.Name = "labelStatMax"; + resources.ApplyResources(this.tableLayoutPanel1, "tableLayoutPanel1"); + this.tableLayoutPanel1.Controls.Add(this.vCPUWarningLabel, 2, 1); + this.tableLayoutPanel1.Controls.Add(this.initialVCPUWarningLabel, 2, 3); + this.tableLayoutPanel1.Controls.Add(this.comboBoxInitialVCPUs, 1, 3); + this.tableLayoutPanel1.Controls.Add(this.labelInitialVCPUs, 0, 3); + this.tableLayoutPanel1.Controls.Add(this.comboBoxTopology, 1, 2); + this.tableLayoutPanel1.Controls.Add(this.label5, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.spinnerStatMax, 1, 7); + this.tableLayoutPanel1.Controls.Add(this.labelVCPUs, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.spinnerDynMax, 1, 6); + this.tableLayoutPanel1.Controls.Add(this.labelTopology, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.comboBoxVCPUs, 1, 1); + this.tableLayoutPanel1.Controls.Add(this.spinnerDynMin, 1, 5); + this.tableLayoutPanel1.Controls.Add(this.labelDynMin, 0, 5); + this.tableLayoutPanel1.Controls.Add(this.labelDynMax, 0, 6); + this.tableLayoutPanel1.Controls.Add(this.labelStatMax, 0, 7); + this.tableLayoutPanel1.Controls.Add(this.labelDynMinInfo, 3, 5); + this.tableLayoutPanel1.Controls.Add(this.labelDynMaxInfo, 3, 6); + this.tableLayoutPanel1.Controls.Add(this.labelStatMaxInfo, 3, 7); + this.tableLayoutPanel1.Controls.Add(this.warningsTableLayoutPanel, 0, 8); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; // - // labelDynMinInfo + // pictureBoxTopology // - resources.ApplyResources(this.labelDynMinInfo, "labelDynMinInfo"); - this.labelDynMinInfo.Name = "labelDynMinInfo"; + this.pictureBoxTopology.Image = global::XenAdmin.Properties.Resources._000_Alert2_h32bit_16; + resources.ApplyResources(this.pictureBoxTopology, "pictureBoxTopology"); + this.pictureBoxTopology.Name = "pictureBoxTopology"; + this.pictureBoxTopology.TabStop = false; // - // labelDynMaxInfo + // labelTopologyWarning // - resources.ApplyResources(this.labelDynMaxInfo, "labelDynMaxInfo"); - this.labelDynMaxInfo.Name = "labelDynMaxInfo"; - // - // labelStatMaxInfo - // - resources.ApplyResources(this.labelStatMaxInfo, "labelStatMaxInfo"); - this.labelStatMaxInfo.Name = "labelStatMaxInfo"; + resources.ApplyResources(this.labelTopologyWarning, "labelTopologyWarning"); + this.labelTopologyWarning.Name = "labelTopologyWarning"; // // Page_CpuMem // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.Controls.Add(this.tableLayoutPanel1); - this.Controls.Add(this.ErrorPanel); this.Name = "Page_CpuMem"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); - this.ErrorPanel.ResumeLayout(false); - this.ErrorPanel.PerformLayout(); + this.warningsTableLayoutPanel.ResumeLayout(false); + this.warningsTableLayoutPanel.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.cpuWarningPictureBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.memoryPictureBox)).EndInit(); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTopology)).EndInit(); this.ResumeLayout(false); } #endregion - private System.Windows.Forms.Label labelVCPUs; - private System.Windows.Forms.Label label5; - private System.Windows.Forms.PictureBox pictureBox1; - private System.Windows.Forms.Label ErrorLabel; - private System.Windows.Forms.Panel ErrorPanel; - private XenAdmin.Controls.Ballooning.MemorySpinner spinnerDynMin; - private XenAdmin.Controls.Ballooning.MemorySpinner spinnerDynMax; - private XenAdmin.Controls.Ballooning.MemorySpinner spinnerStatMax; + private System.Windows.Forms.TableLayoutPanel warningsTableLayoutPanel; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; - private System.Windows.Forms.Label labelTopology; - private Controls.CPUTopologyComboBox comboBoxTopology; - private System.Windows.Forms.ComboBox comboBoxVCPUs; + private System.Windows.Forms.Label vCPUWarningLabel; + private System.Windows.Forms.Label initialVCPUWarningLabel; private System.Windows.Forms.ComboBox comboBoxInitialVCPUs; private System.Windows.Forms.Label labelInitialVCPUs; - private System.Windows.Forms.Label labelInvalidVCPUWarning; + private Controls.CPUTopologyComboBox comboBoxTopology; + private System.Windows.Forms.Label label5; + private Controls.Ballooning.MemorySpinner spinnerStatMax; + private System.Windows.Forms.Label labelVCPUs; + private Controls.Ballooning.MemorySpinner spinnerDynMax; + private System.Windows.Forms.Label labelTopology; + private System.Windows.Forms.ComboBox comboBoxVCPUs; + private Controls.Ballooning.MemorySpinner spinnerDynMin; private System.Windows.Forms.Label labelDynMin; private System.Windows.Forms.Label labelDynMax; private System.Windows.Forms.Label labelStatMax; private System.Windows.Forms.Label labelDynMinInfo; private System.Windows.Forms.Label labelDynMaxInfo; private System.Windows.Forms.Label labelStatMaxInfo; - private System.Windows.Forms.Label vCPUWarningLabel; - private System.Windows.Forms.Label initialVCPUWarningLabel; + private System.Windows.Forms.PictureBox cpuWarningPictureBox; + private System.Windows.Forms.Label cpuWarningLabel; + private System.Windows.Forms.Label memoryWarningLabel; + private System.Windows.Forms.PictureBox memoryPictureBox; + private System.Windows.Forms.PictureBox pictureBoxTopology; + private System.Windows.Forms.Label labelTopologyWarning; } } diff --git a/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.cs b/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.cs index ae33e16bc..bfd0c846b 100644 --- a/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.cs +++ b/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.cs @@ -41,21 +41,27 @@ namespace XenAdmin.Wizards.NewVMWizard { public partial class Page_CpuMem : XenTabPage { - private VM Template; + private VM _template; // number of spinners to show - enum MemoryMode + private enum MemoryMode { JustMemory = 1, MinimumAndMaximum = 2, MinimumMaximumAndStaticMax = 3 } - MemoryMode memoryMode = MemoryMode.JustMemory; - double memoryRatio = 0.0; // the permitted ratio of dynamic_min / static_max - bool initialising = true; - private bool isVcpuHotplugSupported; - private int minVCPUs; + private MemoryMode _memoryMode = MemoryMode.JustMemory; + + private double _memoryRatio; // the permitted ratio of dynamic_min / static_max + private bool _initializing = true; + private bool _isVCpuHotplugSupported; + private int _minVCpus; + private long _maxVCpus; + private long _maxMemTotal; + private long _maxMemFree; + private long _prevVCpusMax; + public VM SelectedTemplate { private get; set; } // Please note that the comboBoxVCPUs control can represent two different VM properties, depending whether the VM supports vCPU hotplug or not: // When vCPU hotplug is not supported, comboBoxVCPUs represents the initial number of vCPUs (VCPUs_at_startup). In this case we will also set the VM property VCPUs_max to the same value. @@ -66,72 +72,90 @@ namespace XenAdmin.Wizards.NewVMWizard InitializeComponent(); } - public override string Text + public override string Text => Messages.NEWVMWIZARD_CPUMEMPAGE_NAME; + + public override string PageTitle => Messages.NEWVMWIZARD_CPUMEMPAGE_TITLE; + + public override string HelpID => "CPU&Memory"; + + public double SelectedMemoryDynamicMin => spinnerDynMin.Value; + + public double SelectedMemoryDynamicMax => _memoryMode == MemoryMode.JustMemory ? spinnerDynMin.Value : spinnerDynMax.Value; + + public bool CanStartVm => _maxVCpus > 0 && SelectedVCpusMax <= _maxVCpus && _maxMemFree > 0 && SelectedMemoryDynamicMin <= _maxMemFree && _maxMemTotal > 0 && SelectedMemoryDynamicMin <= _maxMemTotal; + + public double SelectedMemoryStaticMax => + _memoryMode == MemoryMode.JustMemory ? spinnerDynMin.Value : + _memoryMode == MemoryMode.MinimumAndMaximum ? spinnerDynMax.Value : + spinnerStatMax.Value; + + public long SelectedVCpusMax => comboBoxVCPUs.SelectedItem == null ? -1 : (long)comboBoxVCPUs.SelectedItem; + + public long SelectedVCpusAtStartup { - get { return Messages.NEWVMWIZARD_CPUMEMPAGE_NAME; } + get + { + if (_isVCpuHotplugSupported) + return comboBoxInitialVCPUs.SelectedItem == null ? -1 : (long)comboBoxInitialVCPUs.SelectedItem; + + return comboBoxVCPUs.SelectedItem == null ? -1 : (long)comboBoxVCPUs.SelectedItem; + } } - public override string PageTitle - { - get { return Messages.NEWVMWIZARD_CPUMEMPAGE_TITLE; } - } - - public override string HelpID - { - get { return "CPU&Memory"; } - } + public long SelectedCoresPerSocket => comboBoxTopology.CoresPerSocket; protected override void PageLoadedCore(PageLoadedDirection direction) { - if (SelectedTemplate == Template) + if (SelectedTemplate == _template) return; - initialising = true; + _initializing = true; - Template = SelectedTemplate; - if (Template.SupportsBallooning() && !Helpers.FeatureForbidden(Template, Host.RestrictDMC)) - memoryMode = Template.memory_dynamic_max == Template.memory_static_max ? MemoryMode.MinimumAndMaximum : MemoryMode.MinimumMaximumAndStaticMax; + _template = SelectedTemplate; + if (_template.SupportsBallooning() && !Helpers.FeatureForbidden(_template, Host.RestrictDMC)) + _memoryMode = _template.memory_dynamic_max == _template.memory_static_max ? MemoryMode.MinimumAndMaximum : MemoryMode.MinimumMaximumAndStaticMax; else - memoryMode = MemoryMode.JustMemory; + _memoryMode = MemoryMode.JustMemory; - memoryRatio = VMMemoryControlsEdit.GetMemoryRatio(Template); + _memoryRatio = VMMemoryControlsEdit.GetMemoryRatio(_template); FreeSpinnerLimits(); - if (memoryMode == MemoryMode.JustMemory) + if (_memoryMode == MemoryMode.JustMemory) { - spinnerDynMin.Initialize(Template.memory_static_max, Template.memory_static_max); + spinnerDynMin.Initialize(_template.memory_static_max, _template.memory_static_max); labelDynMin.Text = Messages.MEMORY_COLON; } else { labelDynMin.Text = Messages.DYNAMIC_MIN_COLON; - spinnerDynMin.Initialize(Template.memory_dynamic_min, Template.memory_static_max); + spinnerDynMin.Initialize(_template.memory_dynamic_min, _template.memory_static_max); FreeSpinnerLimits(); // same as CA-33831 - spinnerDynMax.Initialize(Template.memory_dynamic_max, Template.memory_static_max); - if (memoryMode == MemoryMode.MinimumMaximumAndStaticMax) + spinnerDynMax.Initialize(_template.memory_dynamic_max, _template.memory_static_max); + if (_memoryMode == MemoryMode.MinimumMaximumAndStaticMax) { FreeSpinnerLimits(); - spinnerStatMax.Initialize(Template.memory_static_max, Template.memory_static_max); + spinnerStatMax.Initialize(_template.memory_static_max, _template.memory_static_max); } } - labelDynMaxInfo.Visible = labelDynMax.Visible = spinnerDynMax.Visible = memoryMode == MemoryMode.MinimumAndMaximum || memoryMode == MemoryMode.MinimumMaximumAndStaticMax; - labelStatMaxInfo.Visible = labelStatMax.Visible = spinnerStatMax.Visible = memoryMode == MemoryMode.MinimumMaximumAndStaticMax; + labelDynMaxInfo.Visible = labelDynMax.Visible = spinnerDynMax.Visible = _memoryMode == MemoryMode.MinimumAndMaximum || _memoryMode == MemoryMode.MinimumMaximumAndStaticMax; + labelStatMaxInfo.Visible = labelStatMax.Visible = spinnerStatMax.Visible = _memoryMode == MemoryMode.MinimumMaximumAndStaticMax; - isVcpuHotplugSupported = Template.SupportsVcpuHotplug(); - minVCPUs = Template.MinVCPUs(); + _isVCpuHotplugSupported = _template.SupportsVcpuHotplug(); + _minVCpus = _template.MinVCPUs(); - _prevVCPUsMax = Template.VCPUs_max; // we use variable in RefreshCurrentVCPUs for checking if VcpusAtStartup and VcpusMax were equal before VcpusMax changed + _prevVCpusMax = _template.VCPUs_max; // we use variable in RefreshCurrentVCPUs for checking if VcpusAtStartup and VcpusMax were equal before VcpusMax changed label5.Text = GetRubric(); - InitialiseVcpuControls(); - + InitialiseVCpuControls(); SetSpinnerLimitsAndIncrement(); + ValidateMemorySettings(); + ValidateVCpuSettings(); + ValidateInitialVCpuSettings(); + OnPageUpdated(); - ValuesUpdated(); - - initialising = false; + _initializing = false; } public override void SelectDefaultControl() @@ -139,27 +163,27 @@ namespace XenAdmin.Wizards.NewVMWizard comboBoxVCPUs.Select(); } - private void InitialiseVcpuControls() + private void InitialiseVCpuControls() { - labelVCPUs.Text = isVcpuHotplugSupported + labelVCPUs.Text = _isVCpuHotplugSupported ? Messages.VM_CPUMEMPAGE_MAX_VCPUS_LABEL : Messages.VM_CPUMEMPAGE_VCPUS_LABEL; labelInitialVCPUs.Text = Messages.VM_CPUMEMPAGE_INITIAL_VCPUS_LABEL; - labelInitialVCPUs.Visible = comboBoxInitialVCPUs.Visible = isVcpuHotplugSupported; + labelInitialVCPUs.Visible = comboBoxInitialVCPUs.Visible = _isVCpuHotplugSupported; - comboBoxTopology.Populate(Template.VCPUs_at_startup, Template.VCPUs_max, Template.GetCoresPerSocket(), Template.MaxCoresPerSocket()); - PopulateVCPUs(Template.MaxVCPUsAllowed(), isVcpuHotplugSupported ? Template.VCPUs_max : Template.VCPUs_at_startup); + comboBoxTopology.Populate(_template.VCPUs_at_startup, _template.VCPUs_max, _template.GetCoresPerSocket(), _template.MaxCoresPerSocket()); + PopulateVCpus(_template.MaxVCPUsAllowed(), _isVCpuHotplugSupported ? _template.VCPUs_max : _template.VCPUs_at_startup); - if (isVcpuHotplugSupported) - PopulateVCPUsAtStartup(Template.VCPUs_max, Template.VCPUs_at_startup); + if (_isVCpuHotplugSupported) + PopulateVCpusAtStartup(_template.VCPUs_max, _template.VCPUs_at_startup); } - private void PopulateVCPUComboBox(ComboBox comboBox, long min, long max, long currentValue, Predicate isValid) + private void PopulateVCpuComboBox(ComboBox comboBox, long min, long max, long currentValue, Predicate isValid) { comboBox.BeginUpdate(); comboBox.Items.Clear(); - for (long i = min; i <= max; ++i) + for (var i = min; i <= max; ++i) { if (i == currentValue || isValid(i)) comboBox.Items.Add(i); @@ -170,43 +194,41 @@ namespace XenAdmin.Wizards.NewVMWizard comboBox.EndUpdate(); } - private void PopulateVCPUs(long maxVCPUs, long currentVCPUs) + private void PopulateVCpus(long maxVCpus, long currentVCpus) { - PopulateVCPUComboBox(comboBoxVCPUs, 1, maxVCPUs, currentVCPUs, i => comboBoxTopology.IsValidVCPU(i)); + PopulateVCpuComboBox(comboBoxVCPUs, 1, maxVCpus, currentVCpus, i => comboBoxTopology.IsValidVCPU(i)); } - private void PopulateVCPUsAtStartup(long max, long currentValue) + private void PopulateVCpusAtStartup(long max, long currentValue) { - PopulateVCPUComboBox(comboBoxInitialVCPUs, 1, max, currentValue, i => true); + PopulateVCpuComboBox(comboBoxInitialVCPUs, 1, max, currentValue, i => true); } private string GetRubric() { - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); sb.Append(Messages.NEWVMWIZARD_CPUMEMPAGE_RUBRIC); // add hotplug text - if (isVcpuHotplugSupported) + if (_isVCpuHotplugSupported) sb.Append(Messages.VM_CPUMEMPAGE_RUBRIC_HOTPLUG); return sb.ToString(); } - public VM SelectedTemplate { private get; set; } - // Return the larger of the template's MaxMemAllowed and the template's static max, // to avoid crashes in the spinners (CA-40041). private long MaxMemAllowed { get { - long msm = Template.memory_static_max; - long mma = Template.MaxMemAllowed(); + var msm = _template.memory_static_max; + var mma = _template.MaxMemAllowed(); return (msm > mma ? msm : mma); } } private void FreeSpinnerLimits() { - long maxMemAllowed = MaxMemAllowed; + var maxMemAllowed = MaxMemAllowed; spinnerDynMin.SetRange(0, maxMemAllowed); spinnerDynMax.SetRange(0, maxMemAllowed); spinnerStatMax.SetRange(0, maxMemAllowed); @@ -214,29 +236,29 @@ namespace XenAdmin.Wizards.NewVMWizard private void SetSpinnerLimitsAndIncrement() { - spinnerDynMin.Increment = spinnerDynMax.Increment = spinnerStatMax.Increment = VMMemoryControlsEdit.CalcIncrement(Template.memory_static_max, spinnerDynMin.Units); - - long maxMemAllowed = MaxMemAllowed; - double min = Template.memory_static_min; - if (memoryMode == MemoryMode.JustMemory) + spinnerDynMin.Increment = spinnerDynMax.Increment = spinnerStatMax.Increment = VMMemoryControlsEdit.CalcIncrement(_template.memory_static_max, spinnerDynMin.Units); + + var maxMemAllowed = MaxMemAllowed; + double min = _template.memory_static_min; + if (_memoryMode == MemoryMode.JustMemory) { spinnerDynMin.SetRange(min, maxMemAllowed); ShowMemoryMinMaxInformation(labelDynMinInfo, min, maxMemAllowed); return; } - long min2 = (long)(SelectedMemoryStaticMax * memoryRatio); + var min2 = (long)(SelectedMemoryStaticMax * _memoryRatio); if (min < min2) min = min2; - double max = SelectedMemoryDynamicMax; + var max = SelectedMemoryDynamicMax; if (max < min) max = min; spinnerDynMin.SetRange(min, max); ShowMemoryMinMaxInformation(labelDynMinInfo, min, max); spinnerDynMax.SetRange(SelectedMemoryDynamicMin, - memoryMode == MemoryMode.MinimumAndMaximum ? maxMemAllowed : SelectedMemoryStaticMax); + _memoryMode == MemoryMode.MinimumAndMaximum ? maxMemAllowed : SelectedMemoryStaticMax); ShowMemoryMinMaxInformation(labelDynMaxInfo, SelectedMemoryDynamicMin, - memoryMode == MemoryMode.MinimumAndMaximum ? maxMemAllowed : SelectedMemoryStaticMax); + _memoryMode == MemoryMode.MinimumAndMaximum ? maxMemAllowed : SelectedMemoryStaticMax); spinnerStatMax.SetRange(SelectedMemoryDynamicMax, maxMemAllowed); ShowMemoryMinMaxInformation(labelStatMaxInfo, SelectedMemoryDynamicMax, maxMemAllowed); @@ -249,159 +271,174 @@ namespace XenAdmin.Wizards.NewVMWizard spinnerStatMax.Enabled = false; } - public double SelectedMemoryDynamicMin - { - get - { - return spinnerDynMin.Value; - } - } - - public double SelectedMemoryDynamicMax - { - get - { - return memoryMode == MemoryMode.JustMemory ? spinnerDynMin.Value : spinnerDynMax.Value; - } - } - - public double SelectedMemoryStaticMax - { - get - { - return - memoryMode == MemoryMode.JustMemory ? spinnerDynMin.Value : - memoryMode == MemoryMode.MinimumAndMaximum ? spinnerDynMax.Value : - spinnerStatMax.Value; - } - } - - public long SelectedVcpusMax - { - get - { - return (long)comboBoxVCPUs.SelectedItem; - } - } - - public long SelectedVcpusAtStartup - { - get - { - return isVcpuHotplugSupported ? (long)comboBoxInitialVCPUs.SelectedItem : (long)comboBoxVCPUs.SelectedItem; - } - } - - public long SelectedCoresPerSocket - { - get - { - return comboBoxTopology.CoresPerSocket; - } - } - public override List> PageSummary { get { - List> sum = new List>(); + var sum = new List>(); - if (isVcpuHotplugSupported) + if (_isVCpuHotplugSupported) { - sum.Add(new KeyValuePair(Messages.NEWVMWIZARD_CPUMEMPAGE_MAX_VCPUS, SelectedVcpusMax.ToString())); - sum.Add(new KeyValuePair(Messages.NEWVMWIZARD_CPUMEMPAGE_INITIAL_VCPUS, SelectedVcpusAtStartup.ToString())); + sum.Add(new KeyValuePair(Messages.NEWVMWIZARD_CPUMEMPAGE_MAX_VCPUS, SelectedVCpusMax.ToString())); + sum.Add(new KeyValuePair(Messages.NEWVMWIZARD_CPUMEMPAGE_INITIAL_VCPUS, SelectedVCpusAtStartup.ToString())); } else { - sum.Add(new KeyValuePair(Messages.NEWVMWIZARD_CPUMEMPAGE_VCPUS, SelectedVcpusAtStartup.ToString())); + sum.Add(new KeyValuePair(Messages.NEWVMWIZARD_CPUMEMPAGE_VCPUS, SelectedVCpusAtStartup.ToString())); } sum.Add(new KeyValuePair(Messages.NEWVMWIZARD_CPUMEMPAGE_TOPOLOGY, comboBoxTopology.Text)); - if (memoryMode == MemoryMode.JustMemory) + if (_memoryMode == MemoryMode.JustMemory) sum.Add(new KeyValuePair(Messages.MEMORY, Util.MemorySizeStringSuitableUnits(SelectedMemoryStaticMax, false))); else { sum.Add(new KeyValuePair(Messages.DYNAMIC_MIN, Util.MemorySizeStringSuitableUnits(SelectedMemoryDynamicMin, false))); sum.Add(new KeyValuePair(Messages.DYNAMIC_MAX, Util.MemorySizeStringSuitableUnits(SelectedMemoryDynamicMax, false))); - if (memoryMode == MemoryMode.MinimumMaximumAndStaticMax) + if (_memoryMode == MemoryMode.MinimumMaximumAndStaticMax) sum.Add(new KeyValuePair(Messages.STATIC_MAX, Util.MemorySizeStringSuitableUnits(SelectedMemoryStaticMax, false))); } return sum; } } - private void ValuesUpdated() + private void ValidateMemorySettings() { - CheckForError(); - OnPageUpdated(); - } - - private void CheckForError() - { - long max_mem_total = 0; - long max_mem_free = 0; - long max_vcpus = 0; - Host max_mem_total_host = null; - Host max_mem_free_host = null; - Host max_vcpus_host = null; - - foreach (Host host in Connection.Cache.Hosts) + Host maxMemTotalHost = null; + Host maxMemFreeHost = null; + _maxMemTotal = 0; + _maxMemFree = 0; + + foreach (var host in Connection.Cache.Hosts) { - long host_cpus = 0; + var metrics = Connection.Resolve(host.metrics); - foreach (Host_cpu cpu in Connection.Cache.Host_cpus) + if (metrics != null && metrics.memory_total > _maxMemTotal) { - if (cpu.host.opaque_ref.Equals(host.opaque_ref)) - host_cpus++; - } - - Host_metrics metrics = Connection.Resolve(host.metrics); - - if (host_cpus > max_vcpus) - { - max_vcpus = host_cpus; - max_vcpus_host = host; - } - - if (metrics != null && metrics.memory_total > max_mem_total) - { - max_mem_total = metrics.memory_total; - max_mem_total_host = host; + _maxMemTotal = metrics.memory_total; + maxMemTotalHost = host; } // The available memory of a server is taken to be the current memory_free, // plus however much we can squeeze down the existing VMs. This assumes // that the overhead won't increase when we create the new VM, so it // has false negatives. - long memory_free = host.memory_available_calc(); + var memoryFree = host.memory_available_calc(); - if (metrics != null && memory_free > max_mem_free) + if (metrics != null && memoryFree > _maxMemFree) { - max_mem_free = memory_free; - max_mem_free_host = host; + _maxMemFree = memoryFree; + maxMemFreeHost = host; } } - if (max_mem_total_host != null && SelectedMemoryDynamicMin > max_mem_total) + if (maxMemTotalHost != null && SelectedMemoryDynamicMin > _maxMemTotal) { - ErrorPanel.Visible = true; - ErrorLabel.Text = string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN1, Helpers.GetName(max_mem_total_host).Ellipsise(50), Util.MemorySizeStringSuitableUnits(max_mem_total, false)); + ShowMemoryWarning(string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN_TOTAL, Util.MemorySizeStringSuitableUnits(_maxMemTotal, false))); } - else if (max_mem_free_host != null && SelectedMemoryDynamicMin > max_mem_free) + else if (maxMemFreeHost != null && SelectedMemoryDynamicMin > _maxMemFree) { - ErrorPanel.Visible = true; - ErrorLabel.Text = string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN2, Helpers.GetName(max_mem_free_host).Ellipsise(50), Util.MemorySizeStringSuitableUnits(max_mem_free, false)); - } - else if (max_vcpus_host != null && SelectedVcpusMax > max_vcpus) - { - ErrorPanel.Visible = true; - ErrorLabel.Text = string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_VCPUSWARN, Helpers.GetName(max_vcpus_host).Ellipsise(50), max_vcpus); + ShowMemoryWarning(string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN_FREE, Util.MemorySizeStringSuitableUnits(_maxMemFree, false))); } else { - ErrorPanel.Visible = false; + ShowMemoryWarning(); } } + private void ValidateVCpuSettings() + { + Host maxVCpusHost = null; + _maxVCpus = 0; + + var warnings = new List(); + + foreach (var host in Connection.Cache.Hosts) + { + long hostCpus = 0; + + foreach (var cpu in Connection.Cache.Host_cpus) + { + if (cpu.host.opaque_ref.Equals(host.opaque_ref)) + hostCpus++; + } + + if (hostCpus > _maxVCpus) + { + _maxVCpus = hostCpus; + maxVCpusHost = host; + } + } + + if (maxVCpusHost != null && SelectedVCpusMax > _maxVCpus) + { + var isStandAloneHost = Helpers.GetPool(maxVCpusHost.Connection) == null; + if (isStandAloneHost) + { + warnings.Add(string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_VCPUSWARN_STANDALONE_HOST, SelectedVCpusMax, _maxVCpus)); + } + else + { + warnings.Add(string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_VCPUSWARN_POOL, SelectedVCpusMax, _maxVCpus)); + } + } + + if (SelectedVCpusMax > VM.MAX_VCPUS_FOR_NON_TRUSTED_VMS) + { + warnings.Add(string.Format(Messages.VCPUS_UNTRUSTED_VM_WARNING, VM.MAX_VCPUS_FOR_NON_TRUSTED_VMS, BrandManager.BrandConsole)); + } + + ShowCpuWarning(string.Join("\n\n", warnings)); + + if (SelectedVCpusMax < _minVCpus) + { + vCPUWarningLabel.Text = string.Format(Messages.VM_CPUMEMPAGE_VCPU_MIN_WARNING, _minVCpus); + vCPUWarningLabel.Visible = true; + } + else + { + vCPUWarningLabel.Visible = false; + } + } + + private void ValidateInitialVCpuSettings() + { + if (SelectedVCpusAtStartup < _minVCpus) + { + initialVCPUWarningLabel.Text = string.Format(Messages.VM_CPUMEMPAGE_VCPU_MIN_WARNING, _minVCpus); + initialVCPUWarningLabel.Visible = true; + } + else + { + initialVCPUWarningLabel.Visible = false; + } + } + + private void ValidateTopologySettings() + { + if (comboBoxVCPUs.SelectedItem != null) + ShowTopologyWarning(VM.ValidVCPUConfiguration((long)comboBoxVCPUs.SelectedItem, comboBoxTopology.CoresPerSocket)); + } + + private void ShowMemoryWarning(string text = null) + { + var show = !string.IsNullOrEmpty(text); + memoryWarningLabel.Text = show ? text : null; + memoryPictureBox.Visible = memoryWarningLabel.Visible = show; + } + + private void ShowTopologyWarning(string text = null) + { + var show = !string.IsNullOrEmpty(text); + labelTopologyWarning.Text = show ? text : null; + pictureBoxTopology.Visible = labelTopologyWarning.Visible = show; + } + + private void ShowCpuWarning(string text = null) + { + var show = !string.IsNullOrEmpty(text); + cpuWarningLabel.Text = show ? text : null; + cpuWarningPictureBox.Visible = cpuWarningLabel.Visible = show; + } + private void ShowMemoryMinMaxInformation(Label label, double min, double max) { label.Text = string.Format( @@ -415,55 +452,27 @@ namespace XenAdmin.Wizards.NewVMWizard return Util.MemorySizeStringSuitableUnits(numberOfBytes, true); } + #region Control event handlers + private void vCPU_ValueChanged(object sender, EventArgs e) { comboBoxTopology.Update((long)comboBoxVCPUs.SelectedItem); - ValuesUpdated(); - ValidateVCPUSettings(); - RefreshCurrentVCPUs(); + ValidateVCpuSettings(); + RefreshCurrentVCpus(); + OnPageUpdated(); } private void memory_ValueChanged(object sender, EventArgs e) { - if (initialising) + if (_initializing) return; SetSpinnerLimitsAndIncrement(); - ValuesUpdated(); - } - - private void ValidateVCPUSettings() - { - if (comboBoxVCPUs.SelectedItem != null && SelectedVcpusMax < minVCPUs) - { - vCPUWarningLabel.Text = string.Format(Messages.VM_CPUMEMPAGE_VCPU_MIN_WARNING, minVCPUs); - vCPUWarningLabel.Visible = true; - } - else - { - vCPUWarningLabel.Visible = false; - } - - if (comboBoxInitialVCPUs.SelectedItem != null && SelectedVcpusAtStartup < minVCPUs) - { - initialVCPUWarningLabel.Text = string.Format(Messages.VM_CPUMEMPAGE_VCPU_MIN_WARNING, minVCPUs); - initialVCPUWarningLabel.Visible = true; - } - else - { - initialVCPUWarningLabel.Visible = false; - } + ValidateMemorySettings(); + OnPageUpdated(); } - private void ValidateTopologySettings() - { - if (comboBoxVCPUs.SelectedItem != null) - labelInvalidVCPUWarning.Text = VM.ValidVCPUConfiguration((long)comboBoxVCPUs.SelectedItem, comboBoxTopology.CoresPerSocket); - } - - private long _prevVCPUsMax; - - private void RefreshCurrentVCPUs() + private void RefreshCurrentVCpus() { // refresh comboBoxInitialVCPUs if it's visible and populated if (comboBoxInitialVCPUs.Visible && comboBoxInitialVCPUs.Items.Count > 0) @@ -472,15 +481,15 @@ namespace XenAdmin.Wizards.NewVMWizard // So if VcpusMax is decreased below VcpusAtStartup, then VcpusAtStartup is decreased to that number too // If VcpusAtStartup and VcpusMax are equal, and VcpusMax is changed, then VcpusAtStartup is changed to match // But if the numbers are unequal, and VcpusMax is changed but is still higher than VcpusAtStartup, then VcpusAtStartup is unchanged - var newValue = SelectedVcpusAtStartup; + var newValue = SelectedVCpusAtStartup; - if (SelectedVcpusMax < SelectedVcpusAtStartup) - newValue = SelectedVcpusMax; - else if (SelectedVcpusAtStartup == _prevVCPUsMax && SelectedVcpusMax != _prevVCPUsMax) - newValue = SelectedVcpusMax; + if (SelectedVCpusMax < SelectedVCpusAtStartup) + newValue = SelectedVCpusMax; + else if (SelectedVCpusAtStartup == _prevVCpusMax && SelectedVCpusMax != _prevVCpusMax) + newValue = SelectedVCpusMax; - PopulateVCPUsAtStartup(SelectedVcpusMax, newValue); - _prevVCPUsMax = SelectedVcpusMax; + PopulateVCpusAtStartup(SelectedVCpusMax, newValue); + _prevVCpusMax = SelectedVCpusMax; } } @@ -491,7 +500,9 @@ namespace XenAdmin.Wizards.NewVMWizard private void comboBoxInitialVCPUs_SelectedIndexChanged(object sender, EventArgs e) { - ValidateVCPUSettings(); + ValidateInitialVCpuSettings(); } + + #endregion } } diff --git a/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.resx b/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.resx index 530564546..702989fd1 100644 --- a/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.resx +++ b/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.resx @@ -117,47 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Left - - + True - - NoControl + + + GrowAndShrink - - - 3, 47 - - - 95, 13 - - - 1 - - - &Number of vCPUs: - - - MiddleLeft - - - labelVCPUs - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 8 - - - True + + 2 4 @@ -171,14 +140,15 @@ NoControl + - 185, 40 + 185, 38 327, 27 - 21 + 2 MiddleLeft @@ -208,13 +178,13 @@ NoControl - 185, 113 + 185, 92 327, 27 - 20 + 7 MiddleLeft @@ -235,7 +205,7 @@ 1 - 129, 116 + 129, 95 50, 21 @@ -265,7 +235,7 @@ NoControl - 3, 120 + 3, 99 120, 13 @@ -276,9 +246,6 @@ Initial number of v&CPUs: - - MiddleLeft - labelInitialVCPUs @@ -291,44 +258,11 @@ 3 - - True - - - Fill - - - NoControl - - - 129, 94 - - - 3, 0, 3, 6 - - - 383, 13 - - - 13 - - - labelInvalidVCPUWarning - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 4 - Tahoma, 8pt - 129, 70 + 129, 68 250, 21 @@ -340,379 +274,28 @@ comboBoxTopology - XenAdmin.Controls.CPUTopologyComboBox, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + XenAdmin.Controls.CPUTopologyComboBox, [XenCenter_No_Space], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null tableLayoutPanel1 - 5 + 4 - + True - - GrowAndShrink - - - 126, 212 - - - 0, 0, 0, 0 - - - 97, 26 - - - 12 - - - spinnerStatMax - - - XenAdmin.Controls.Ballooning.MemorySpinner, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null - - - tableLayoutPanel1 - - - 7 - - - True - - - GrowAndShrink - - - 126, 186 - - - 0, 0, 0, 0 - - - 97, 26 - - - 10 - - - spinnerDynMax - - - XenAdmin.Controls.Ballooning.MemorySpinner, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null - - - tableLayoutPanel1 - - - 9 - - - Left - - - True - - - NoControl - - - 3, 74 - - - 54, 13 - - - 3 - - - &Topology: - - - MiddleLeft - - - labelTopology - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 10 - - - 129, 43 - - - 50, 21 - - - 2 - - - comboBoxVCPUs - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 11 - - - True - - - GrowAndShrink - - - 126, 160 - - - 0, 0, 0, 0 - - - 97, 26 - - - 8 - - - spinnerDynMin - - - XenAdmin.Controls.Ballooning.MemorySpinner, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null - - - tableLayoutPanel1 - - - 12 - - - Left - - - True - - - 3, 166 - - - 90, 13 - - - 7 - - - &Minimum memory: - - - labelDynMin - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 13 - - - Left - - - True - - - 3, 192 - - - 93, 13 - - - 9 - - - Ma&ximum memory: - - - labelDynMax - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 14 - - - Left - - - True - - - 3, 218 - - - 83, 13 - - - 11 - - - &Static maximum: - - - labelStatMax - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 15 - - - Left - - - True - - - 226, 166 - - - 155, 13 - - - 14 - - - Minimum maximum placeholder. - - - labelDynMinInfo - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 16 - - - Left - - - True - - - 226, 192 - - - 155, 13 - - - 15 - - - Minimum maximum placeholder. - - - labelDynMaxInfo - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 17 - - - Left - - - True - - - 226, 218 - - - 155, 13 - - - 16 - - - Minimum maximum placeholder. - - - labelStatMaxInfo - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tableLayoutPanel1 - - - 18 - - - Fill - - - 0, 0 - - - 10 - - - 515, 255 - - - 0 - - - tableLayoutPanel1 - - - System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 0 - - - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="vCPUWarningLabel" Row="1" RowSpan="1" Column="2" ColumnSpan="2" /><Control Name="initialVCPUWarningLabel" Row="4" RowSpan="1" Column="2" ColumnSpan="2" /><Control Name="comboBoxInitialVCPUs" Row="4" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="labelInitialVCPUs" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="labelInvalidVCPUWarning" Row="3" RowSpan="1" Column="1" ColumnSpan="3" /><Control Name="comboBoxTopology" Row="2" RowSpan="1" Column="1" ColumnSpan="3" /><Control Name="label5" Row="0" RowSpan="1" Column="0" ColumnSpan="4" /><Control Name="spinnerStatMax" Row="8" RowSpan="1" Column="1" ColumnSpan="2" /><Control Name="labelVCPUs" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="spinnerDynMax" Row="7" RowSpan="1" Column="1" ColumnSpan="2" /><Control Name="labelTopology" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="comboBoxVCPUs" Row="1" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="spinnerDynMin" Row="6" RowSpan="1" Column="1" ColumnSpan="2" /><Control Name="labelDynMin" Row="6" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="labelDynMax" Row="7" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="labelStatMax" Row="8" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="labelDynMinInfo" Row="6" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="labelDynMaxInfo" Row="7" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="labelStatMaxInfo" Row="8" RowSpan="1" Column="3" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,AutoSize,0,Absolute,41,Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,Absolute,20,AutoSize,0,AutoSize,0,AutoSize,0,Absolute,20" /></TableLayoutSettings> - Top + + NoControl + 3, 0 - 3, 0, 3, 14 + 3, 0, 3, 12 509, 26 @@ -733,89 +316,623 @@ tableLayoutPanel1 + 5 + + + True + + + GrowAndShrink + + + 126, 191 + + + 0, 0, 0, 0 + + + 97, 26 + + + 15 + + + spinnerStatMax + + + XenAdmin.Controls.Ballooning.MemorySpinner, [XenCenter_No_Space], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + + + tableLayoutPanel1 + + 6 - + + Left + + + True + + NoControl - - 3, 6 + + 3, 45 - - 16, 16 + + 95, 13 - - AutoSize - - - 0 - - - pictureBox1 - - - System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - ErrorPanel - - + 1 - - Top, Bottom, Left, Right + + &Number of vCPUs: - - NoControl + + labelVCPUs - - 25, 6 - - - 487, 106 - - - 0 - - - ErrorLabel - - + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - ErrorPanel + + tableLayoutPanel1 - + + 7 + + + True + + + GrowAndShrink + + + 126, 165 + + + 0, 0, 0, 0 + + + 97, 26 + + + 12 + + + spinnerDynMax + + + XenAdmin.Controls.Ballooning.MemorySpinner, [XenCenter_No_Space], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + + + tableLayoutPanel1 + + + 8 + + + Left + + + True + + + NoControl + + + 3, 72 + + + 54, 13 + + + 3 + + + &Topology: + + + labelTopology + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 9 + + + 129, 41 + + + 50, 21 + + + 1 + + + comboBoxVCPUs + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 10 + + + True + + + GrowAndShrink + + + 126, 139 + + + 0, 0, 0, 0 + + + 97, 26 + + + 9 + + + spinnerDynMin + + + XenAdmin.Controls.Ballooning.MemorySpinner, [XenCenter_No_Space], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + + + tableLayoutPanel1 + + + 11 + + + Left + + + True + + + NoControl + + + 3, 145 + + + 90, 13 + + + 8 + + + &Minimum memory: + + + labelDynMin + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 12 + + + Left + + + True + + + NoControl + + + 3, 171 + + + 93, 13 + + + 11 + + + Ma&ximum memory: + + + labelDynMax + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 13 + + + Left + + + True + + + NoControl + + + 3, 197 + + + 83, 13 + + + 14 + + + &Static maximum: + + + labelStatMax + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 14 + + + Left + + + True + + + NoControl + + + 226, 145 + + + 155, 13 + + + 10 + + + Minimum maximum placeholder. + + + labelDynMinInfo + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 15 + + + Left + + + True + + + NoControl + + + 226, 171 + + + 155, 13 + + + 13 + + + Minimum maximum placeholder. + + + labelDynMaxInfo + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 16 + + + Left + + + True + + + NoControl + + + 226, 197 + + + 155, 13 + + + 16 + + + Minimum maximum placeholder. + + + labelStatMaxInfo + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 17 + + + Fill + + + 0, 0 + + + 9 + + + 515, 367 + + 0 - - Bottom + + tableLayoutPanel1 - - 0, 255 + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 515, 112 - - - 1 - - - False - - - ErrorPanel - - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - + $this - + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="vCPUWarningLabel" Row="1" RowSpan="1" Column="2" ColumnSpan="2" /><Control Name="initialVCPUWarningLabel" Row="3" RowSpan="1" Column="2" ColumnSpan="2" /><Control Name="comboBoxInitialVCPUs" Row="3" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="labelInitialVCPUs" Row="3" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="comboBoxTopology" Row="2" RowSpan="1" Column="1" ColumnSpan="3" /><Control Name="label5" Row="0" RowSpan="1" Column="0" ColumnSpan="4" /><Control Name="spinnerStatMax" Row="7" RowSpan="1" Column="1" ColumnSpan="2" /><Control Name="labelVCPUs" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="spinnerDynMax" Row="6" RowSpan="1" Column="1" ColumnSpan="2" /><Control Name="labelTopology" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="comboBoxVCPUs" Row="1" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="spinnerDynMin" Row="5" RowSpan="1" Column="1" ColumnSpan="2" /><Control Name="labelDynMin" Row="5" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="labelDynMax" Row="6" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="labelStatMax" Row="7" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="labelDynMinInfo" Row="5" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="labelDynMaxInfo" Row="6" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="labelStatMaxInfo" Row="7" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="warningsTableLayoutPanel" Row="8" RowSpan="1" Column="0" ColumnSpan="4" /></Controls><Columns Styles="AutoSize,0,AutoSize,0,Absolute,41,Percent,100" /><Rows Styles="AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,Absolute,20,AutoSize,0,AutoSize,0,AutoSize,0,AutoSize,0,Absolute,20" /></TableLayoutSettings> + + + NoControl + + + 3, 31 + + + 16, 16 + + + 4 + + + False + + + pictureBoxTopology + + + System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + warningsTableLayoutPanel + + + 0 + + + NoControl + + + 3, 3 + + + 16, 16 + + + 0 + + + False + + + cpuWarningPictureBox + + + System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + warningsTableLayoutPanel + + 1 + + Left + + + True + + + NoControl + + + 25, 4 + + + 0, 13 + + + 0 + + + False + + + cpuWarningLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + warningsTableLayoutPanel + + + 2 + + + Left + + + True + + + NoControl + + + 25, 60 + + + 0, 13 + + + 2 + + + False + + + memoryWarningLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + warningsTableLayoutPanel + + + 3 + + + NoControl + + + 3, 59 + + + 16, 16 + + + 1 + + + False + + + memoryPictureBox + + + System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + warningsTableLayoutPanel + + + 4 + + + Left + + + True + + + 25, 32 + + + 0, 13 + + + 1 + + + False + + + labelTopologyWarning + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + warningsTableLayoutPanel + + + 5 + + + Top + + + 0, 237 + + + 0, 20, 0, 0 + + + 5 + + + 515, 78 + + + 17 + + + warningsTableLayoutPanel + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 18 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="pictureBoxTopology" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="cpuWarningPictureBox" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="cpuWarningLabel" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="memoryWarningLabel" Row="4" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="memoryPictureBox" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="labelTopologyWarning" Row="2" RowSpan="1" Column="1" ColumnSpan="1" /></Controls><Columns Styles="AutoSize,0,Percent,100" /><Rows Styles="AutoSize,0,Absolute,6,AutoSize,0,Absolute,6,AutoSize,0" /></TableLayoutSettings> + True @@ -829,6 +946,6 @@ Page_CpuMem - XenAdmin.Controls.XenTabPage, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + XenAdmin.Controls.XenTabPage, [XenCenter_No_Space], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null \ No newline at end of file diff --git a/XenAdmin/Wizards/NewVMWizard/Page_Finish.Designer.cs b/XenAdmin/Wizards/NewVMWizard/Page_Finish.Designer.cs index a39b2c7cc..08a21f4cb 100644 --- a/XenAdmin/Wizards/NewVMWizard/Page_Finish.Designer.cs +++ b/XenAdmin/Wizards/NewVMWizard/Page_Finish.Designer.cs @@ -31,22 +31,16 @@ namespace XenAdmin.Wizards.NewVMWizard System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Page_Finish)); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); - this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.AutoStartCheckBox = new System.Windows.Forms.CheckBox(); this.SummaryGridView = new XenAdmin.Controls.DataGridViewEx.DataGridViewEx(); this.PropertyColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ValueColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.label1 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.SummaryGridView)).BeginInit(); + this.tableLayoutPanel1.SuspendLayout(); this.SuspendLayout(); // - // richTextBox1 - // - resources.ApplyResources(this.richTextBox1, "richTextBox1"); - this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.richTextBox1.Name = "richTextBox1"; - this.richTextBox1.ReadOnly = true; - this.richTextBox1.TabStop = false; - // // AutoStartCheckBox // resources.ApplyResources(this.AutoStartCheckBox, "AutoStartCheckBox"); @@ -57,9 +51,9 @@ namespace XenAdmin.Wizards.NewVMWizard // // SummaryGridView // - resources.ApplyResources(this.SummaryGridView, "SummaryGridView"); this.SummaryGridView.BackgroundColor = System.Drawing.SystemColors.Control; this.SummaryGridView.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None; + this.SummaryGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; this.SummaryGridView.ColumnHeadersVisible = false; this.SummaryGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.PropertyColumn, @@ -72,6 +66,7 @@ namespace XenAdmin.Wizards.NewVMWizard dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.ControlText; dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.False; this.SummaryGridView.DefaultCellStyle = dataGridViewCellStyle1; + resources.ApplyResources(this.SummaryGridView, "SummaryGridView"); this.SummaryGridView.Name = "SummaryGridView"; this.SummaryGridView.ReadOnly = true; dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Control; @@ -94,26 +89,38 @@ namespace XenAdmin.Wizards.NewVMWizard this.ValueColumn.Name = "ValueColumn"; this.ValueColumn.ReadOnly = true; // + // tableLayoutPanel1 + // + resources.ApplyResources(this.tableLayoutPanel1, "tableLayoutPanel1"); + this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.AutoStartCheckBox, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.SummaryGridView, 0, 1); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + // + // label1 + // + resources.ApplyResources(this.label1, "label1"); + this.label1.Name = "label1"; + // // Page_Finish // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; - this.Controls.Add(this.SummaryGridView); - this.Controls.Add(this.AutoStartCheckBox); - this.Controls.Add(this.richTextBox1); + this.Controls.Add(this.tableLayoutPanel1); this.Name = "Page_Finish"; ((System.ComponentModel.ISupportInitialize)(this.SummaryGridView)).EndInit(); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); this.ResumeLayout(false); - this.PerformLayout(); } #endregion - - private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.CheckBox AutoStartCheckBox; private XenAdmin.Controls.DataGridViewEx.DataGridViewEx SummaryGridView; private System.Windows.Forms.DataGridViewTextBoxColumn PropertyColumn; private System.Windows.Forms.DataGridViewTextBoxColumn ValueColumn; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Label label1; } } diff --git a/XenAdmin/Wizards/NewVMWizard/Page_Finish.cs b/XenAdmin/Wizards/NewVMWizard/Page_Finish.cs index e670b1c70..4271cc524 100644 --- a/XenAdmin/Wizards/NewVMWizard/Page_Finish.cs +++ b/XenAdmin/Wizards/NewVMWizard/Page_Finish.cs @@ -40,54 +40,47 @@ namespace XenAdmin.Wizards.NewVMWizard public Page_Finish() { InitializeComponent(); - richTextBox1.Text = Messages.NEWVMWIZARD_FINISHPAGE; } - public override string Text - { - get { return Messages.NEWVMWIZARD_FINISHPAGE_NAME; } - } + public override string Text => Messages.NEWVMWIZARD_FINISHPAGE_NAME; - public override string PageTitle - { - get { return Messages.NEWVMWIZARD_FINISHPAGE_TITLE; } - } + public override string PageTitle => Messages.NEWVMWIZARD_FINISHPAGE_TITLE; - public override string HelpID - { - get { return "Finish"; } - } + public override string HelpID => "Finish"; public override string NextText(bool isLastPage) { return Messages.NEWVMWIZARD_FINISHPAGE_CREATE; } - public bool StartImmediately + public bool StartImmediately => AutoStartCheckBox.Checked; + + private bool _canStartImmediately = true; + + public bool CanStartImmediately { - get - { - return AutoStartCheckBox.Checked; - } + get => _canStartImmediately; + set => _canStartImmediately = AutoStartCheckBox.Checked = AutoStartCheckBox.Enabled = value; } protected override void PageLoadedCore(PageLoadedDirection direction) { SummaryGridView.Rows.Clear(); - if (SummaryRetreiver == null) + if (SummaryRetriever == null) return; - var entries = SummaryRetreiver.Invoke(); - foreach (KeyValuePair pair in entries) + var entries = SummaryRetriever.Invoke(); + foreach (var pair in entries) SummaryGridView.Rows.Add(pair.Key, pair.Value); } public override void SelectDefaultControl() { - AutoStartCheckBox.Select(); + if(CanStartImmediately) + AutoStartCheckBox.Select(); } - public Func>> SummaryRetreiver { private get; set; } + public Func>> SummaryRetriever { private get; set; } } } diff --git a/XenAdmin/Wizards/NewVMWizard/Page_Finish.resx b/XenAdmin/Wizards/NewVMWizard/Page_Finish.resx index 9dad32568..401cdccfc 100644 --- a/XenAdmin/Wizards/NewVMWizard/Page_Finish.resx +++ b/XenAdmin/Wizards/NewVMWizard/Page_Finish.resx @@ -112,50 +112,23 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Top, Left, Right - - - - 4, 4 - - - 508, 86 - - - - 0 - - - - - - richTextBox1 - - - System.Windows.Forms.RichTextBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 2 - - - Bottom, Left - + True + 3, 288 + + + 3, 10, 3, 3 + 172, 17 @@ -169,18 +142,15 @@ AutoStartCheckBox - System.Windows.Forms.CheckBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - $this + tableLayoutPanel1 1 - - Top, Bottom, Left, Right - - + True @@ -189,17 +159,20 @@ 5 - + True Value + + Fill + - 4, 97 + 3, 44 - 508, 142 + 509, 231 3 @@ -208,15 +181,81 @@ SummaryGridView - XenAdmin.Controls.DataGridViewEx.DataGridViewEx, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + XenAdmin.Controls.DataGridViewEx.DataGridViewEx, [XenCenter_No_Space], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null - $this + tableLayoutPanel1 + 2 + + + 1 + + + True + + + Fill + + + 3, 0 + + + 3, 0, 3, 15 + + + 509, 26 + + 0 - + + All the necessary information has been collected and the wizard is ready to provision the new virtual machine using the settings shown below. + + + label1 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 0 + + + Fill + + + 0, 0 + + + 3 + + + 515, 308 + + + 4 + + + tableLayoutPanel1 + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="label1" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="AutoStartCheckBox" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="SummaryGridView" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,Percent,100,AutoSize,0" /></TableLayoutSettings> + + True @@ -229,18 +268,18 @@ PropertyColumn - System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ValueColumn - System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Page_Finish - XenAdmin.Controls.XenTabPage, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + XenAdmin.Controls.XenTabPage, [XenCenter_No_Space], Version=0.0.0.0, Culture=neutral, PublicKeyToken=null \ No newline at end of file diff --git a/XenAdmin/XenAdmin.csproj b/XenAdmin/XenAdmin.csproj index e12652cc9..949ca5501 100755 --- a/XenAdmin/XenAdmin.csproj +++ b/XenAdmin/XenAdmin.csproj @@ -1370,11 +1370,11 @@ Component - + UserControl - - CPUMemoryEditPage.cs + + CpuMemoryEditPage.cs UserControl @@ -2619,8 +2619,8 @@ VMHAEditPage.cs Designer - - CPUMemoryEditPage.cs + + CpuMemoryEditPage.cs Designer @@ -5599,12 +5599,12 @@ BootOptionsEditPage.cs - - CPUMemoryEditPage.cs + + CpuMemoryEditPage.cs Designer - - CPUMemoryEditPage.cs + + CpuMemoryEditPage.cs Designer diff --git a/XenModel/Actions/OvfActions/Import.cs b/XenModel/Actions/OvfActions/Import.cs index c0a52d5c3..d1b8ed94b 100644 --- a/XenModel/Actions/OvfActions/Import.cs +++ b/XenModel/Actions/OvfActions/Import.cs @@ -490,20 +490,23 @@ namespace XenAdmin.Actions.OvfActions if (rasds != null && rasds.Length > 0) { //The default memory unit is MB (2^20), however, the RASD may contain a different - //one with format Bytes*memoryBase^memoryPower (Bytes being a literal string) + //one with format byte*memoryBase^memoryPower (byte being a literal string) - double memoryPower = 20.0; double memoryBase = 2.0; - + double memoryPower = 20.0; + foreach (RASD_Type rasd in rasds) { - if (rasd.AllocationUnits.Value.ToLower().StartsWith("bytes")) + if (rasd.AllocationUnits.Value.ToLower().StartsWith("byte")) { string[] a1 = rasd.AllocationUnits.Value.Split('*', '^'); + if (a1.Length == 3) { - memoryBase = Convert.ToDouble(a1[1]); - memoryPower = Convert.ToDouble(a1[2]); + if (!double.TryParse(a1[1].Trim(), out memoryBase)) + memoryBase = 2.0; + if (!double.TryParse(a1[2].Trim(), out memoryPower)) + memoryPower = 20.0; } } diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index 70d5ea7bd..0cde5af43 100755 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -10630,15 +10630,6 @@ namespace XenAdmin { } } - /// - /// Looks up a localized string similar to Home Server:. - /// - public static string CPM_SUMMARY_KEY_HOME_SERVER { - get { - return ResourceManager.GetString("CPM_SUMMARY_KEY_HOME_SERVER", resourceCulture); - } - } - /// /// Looks up a localized string similar to Template:. /// @@ -10693,15 +10684,6 @@ namespace XenAdmin { } } - /// - /// Looks up a localized string similar to Unset. - /// - public static string CPM_SUMMARY_UNSET { - get { - return ResourceManager.GetString("CPM_SUMMARY_UNSET", resourceCulture); - } - } - /// /// Looks up a localized string similar to Pl&ace all virtual disks on the same SR:. /// @@ -11149,24 +11131,6 @@ namespace XenAdmin { } } - /// - /// Looks up a localized string similar to CPU and Memory. - /// - public static string CPU_AND_MEMORY { - get { - return ResourceManager.GetString("CPU_AND_MEMORY", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {0} vCPU(s) & {1} MB RAM. - /// - public static string CPU_AND_MEMORY_SUB { - get { - return ResourceManager.GetString("CPU_AND_MEMORY_SUB", resourceCulture); - } - } - /// /// Looks up a localized string similar to {0} vCPU(s). /// @@ -17382,16 +17346,7 @@ namespace XenAdmin { } /// - /// Looks up a localized string similar to Target:. - /// - public static string FINISH_PAGE_TARGET { - get { - return ResourceManager.GetString("FINISH_PAGE_TARGET", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {0} target:. + /// Looks up a localized string similar to Home server:. /// public static string FINISH_PAGE_TARGET_FOR_VM { get { @@ -20783,6 +20738,15 @@ namespace XenAdmin { } } + /// + /// Looks up a localized string similar to The appliance contains {0} VM(s) with more than {1} vCPUs. Where a VM may be running actively hostile privileged code {2} recommends that the vCPU limit is set to {1} to prevent impact on system availability.. + /// + public static string IMPORT_VM_CPUS_COUNT_UNTRUSTED_WARNING { + get { + return ResourceManager.GetString("IMPORT_VM_CPUS_COUNT_UNTRUSTED_WARNING", resourceCulture); + } + } + /// /// Looks up a localized string similar to Import VM from.... /// @@ -20873,6 +20837,24 @@ namespace XenAdmin { } } + /// + /// Looks up a localized string similar to The imported appliance requires a minimum of {0} vCPUs, while the number of physical CPUs in the selected server is {1}. You will not be able to start the appliance on the selected server.. + /// + public static string IMPORT_WIZARD_CPUS_COUNT_MISMATCH_HOST { + get { + return ResourceManager.GetString("IMPORT_WIZARD_CPUS_COUNT_MISMATCH_HOST", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The imported appliance requires a minimum of {0} vCPUs, while the maximum number of physical CPUs in the pool is {1}. You will not be able to start the appliance on the selected pool.. + /// + public static string IMPORT_WIZARD_CPUS_COUNT_MISMATCH_POOL { + get { + return ResourceManager.GetString("IMPORT_WIZARD_CPUS_COUNT_MISMATCH_POOL", resourceCulture); + } + } + /// /// Looks up a localized string similar to &Import to:. /// @@ -20927,6 +20909,24 @@ namespace XenAdmin { } } + /// + /// Looks up a localized string similar to The imported appliance requires a minimum of {0} of memory, while the available memory on the server is {1}. You will not be able to start the VM on the selected server.. + /// + public static string IMPORT_WIZARD_INSUFFICIENT_MEMORY_HOST { + get { + return ResourceManager.GetString("IMPORT_WIZARD_INSUFFICIENT_MEMORY_HOST", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The imported appliance requires a minimum of {0} of memory, while the maximum available memory on the pool is {1}. You will not be able to start the VM on the selected pool.. + /// + public static string IMPORT_WIZARD_INSUFFICIENT_MEMORY_POOL { + get { + return ResourceManager.GetString("IMPORT_WIZARD_INSUFFICIENT_MEMORY_POOL", resourceCulture); + } + } + /// /// Looks up a localized string similar to Map the virtual network interfaces in the VMs you are importing to networks in the destination pool or standalone server.. /// @@ -26842,28 +26842,20 @@ namespace XenAdmin { } /// - /// Looks up a localized string similar to The amount of memory allocated to the new VM is greater than the amount of physical memory on any server in the pool. - /// - ///Server '{0}' has {1} of physical memory in total. - /// - ///You will not be able to start this VM without increasing the amount of physical memory on one of the servers in the pool.. + /// Looks up a localized string similar to The amount of memory allocated to the new VM is greater than the amount of physical memory available on any server in the pool ({0}).. /// - public static string NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN1 { + public static string NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN_FREE { get { - return ResourceManager.GetString("NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN1", resourceCulture); + return ResourceManager.GetString("NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN_FREE", resourceCulture); } } /// - /// Looks up a localized string similar to The amount of memory allocated to the new VM is greater than the amount of physical memory available on any server in the pool. - /// - ///Server '{0}' has {1} of physical memory available. - /// - ///You will not be able to start this VM without freeing some space on one of the servers.. + /// Looks up a localized string similar to The amount of memory allocated to the new VM is greater than the amount of physical memory on any server in the pool ({0}).. /// - public static string NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN2 { + public static string NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN_TOTAL { get { - return ResourceManager.GetString("NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN2", resourceCulture); + return ResourceManager.GetString("NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN_TOTAL", resourceCulture); } } @@ -26877,7 +26869,7 @@ namespace XenAdmin { } /// - /// Looks up a localized string similar to Specify the number of virtual CPUs, their topology, and the amount of memory that will be allocated to the new virtual machine. . + /// Looks up a localized string similar to Specify the number of vCPUs, their topology, and the amount of memory that will be allocated to the new virtual machine. . /// public static string NEWVMWIZARD_CPUMEMPAGE_RUBRIC { get { @@ -26913,26 +26905,20 @@ namespace XenAdmin { } /// - /// Looks up a localized string similar to The number of vCPUs given to the new VM is greater than the number of physical CPUs on any server in the pool. - /// - ///Server '{0}' has {1} physical CPUs. - /// - ///Performance of this VM will be greatly reduced if it is started with this many vCPUs.. + /// Looks up a localized string similar to You have specified {0} vCPUs, but none of the pool servers have more than {1} physical CPUs. You will not be able to start the VM.. /// - public static string NEWVMWIZARD_CPUMEMPAGE_VCPUSWARN { + public static string NEWVMWIZARD_CPUMEMPAGE_VCPUSWARN_POOL { get { - return ResourceManager.GetString("NEWVMWIZARD_CPUMEMPAGE_VCPUSWARN", resourceCulture); + return ResourceManager.GetString("NEWVMWIZARD_CPUMEMPAGE_VCPUSWARN_POOL", resourceCulture); } } /// - /// Looks up a localized string similar to All the necessary information has been collected and the wizard is ready to provision the new virtual machine using the settings shown below. - /// - ///Review these settings, then click Previous if you need to change anything. Otherwise, click Create Now to create the new VM. It may take several minutes to create the new VM.. + /// Looks up a localized string similar to You have specified {0} vCPUs, but the server has only {1} physical CPUs. You will not be able to start the VM.. /// - public static string NEWVMWIZARD_FINISHPAGE { + public static string NEWVMWIZARD_CPUMEMPAGE_VCPUSWARN_STANDALONE_HOST { get { - return ResourceManager.GetString("NEWVMWIZARD_FINISHPAGE", resourceCulture); + return ResourceManager.GetString("NEWVMWIZARD_CPUMEMPAGE_VCPUSWARN_STANDALONE_HOST", resourceCulture); } } @@ -38557,13 +38543,11 @@ namespace XenAdmin { } /// - /// Looks up a localized string similar to The number of VCPUs is greater than the number of physical CPUs on the host server. This will significantly reduce VM performance. - /// - ///To optimize VM performance, you should reduce the number of VCPUs to less than or equal to the number of physical CPUs.. + /// Looks up a localized string similar to You have selected more than {0} vCPUs for the new VM. Where a VM may be running actively hostile privileged code {1} recommends that the vCPU limit is set to {0} to prevent impact on system availability.. /// - public static string VCPUS_MORE_THAN_PCPUS { + public static string VCPUS_UNTRUSTED_VM_WARNING { get { - return ResourceManager.GetString("VCPUS_MORE_THAN_PCPUS", resourceCulture); + return ResourceManager.GetString("VCPUS_UNTRUSTED_VM_WARNING", resourceCulture); } } @@ -39215,6 +39199,24 @@ namespace XenAdmin { } } + /// + /// Looks up a localized string similar to The amount of physical memory allocated to this VM is greater than the total memory of its home server.. + /// + public static string VM_CPUMEMPAGE_INSUFFICIENT_MEMORY_HOST { + get { + return ResourceManager.GetString("VM_CPUMEMPAGE_INSUFFICIENT_MEMORY_HOST", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The amount of physical memory allocated to this VM is greater than the total memory of any server in the pool.. + /// + public static string VM_CPUMEMPAGE_INSUFFICIENT_MEMORY_POOL { + get { + return ResourceManager.GetString("VM_CPUMEMPAGE_INSUFFICIENT_MEMORY_POOL", resourceCulture); + } + } + /// /// Looks up a localized string similar to Maximum number of &vCPUs:. /// @@ -39252,7 +39254,16 @@ namespace XenAdmin { } /// - /// Looks up a localized string similar to It is recommended to allocate at least {0} vCPUs for this VM. + /// Looks up a localized string similar to The VM's home server does not have enough physical CPUs to start the VM. The VM will start on another server.. + /// + public static string VM_CPUMEMPAGE_VCPU_HOME_HOST_WARNING { + get { + return ResourceManager.GetString("VM_CPUMEMPAGE_VCPU_HOME_HOST_WARNING", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to It is recommended to allocate at least {0} vCPUs for this VM.. /// public static string VM_CPUMEMPAGE_VCPU_MIN_WARNING { get { @@ -39261,7 +39272,7 @@ namespace XenAdmin { } /// - /// Looks up a localized string similar to More vCPUs than physical CPUs may lead to reduced VM performance. + /// Looks up a localized string similar to There are no servers with enough physical CPUs to start the VM.. /// public static string VM_CPUMEMPAGE_VCPU_WARNING { get { diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index c97ee1872..1a60e290f 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -3811,9 +3811,6 @@ This action cannot be undone. Are you sure you want to continue? Destination: - - Home Server: - Template: @@ -3832,9 +3829,6 @@ This action cannot be undone. Are you sure you want to continue? Network not found - - Unset - Pl&ace all virtual disks on the same SR: @@ -3988,12 +3982,6 @@ For optimal performance and reliability during VM migration, ensure that the net CPU - - CPU and Memory - - - {0} vCPU(s) & {1} MB RAM - {0} vCPU(s) @@ -6086,11 +6074,8 @@ Would you like to eject these ISOs before continuing? {0} storage: - - Target: - - {0} target: + Home server: Finish @@ -7251,6 +7236,9 @@ This might result in failure to migrate VMs to this server during the RPU or to Configure storage for the new VM + + The appliance contains {0} VM(s) with more than {1} vCPUs. Where a VM may be running actively hostile privileged code {2} recommends that the vCPU limit is set to {1} to prevent impact on system availability. + Import VM from... @@ -7281,6 +7269,12 @@ This might result in failure to migrate VMs to this server during the RPU or to Place &all imported virtual disks on this target SR: + + The imported appliance requires a minimum of {0} vCPUs, while the number of physical CPUs in the selected server is {1}. You will not be able to start the appliance on the selected server. + + + The imported appliance requires a minimum of {0} vCPUs, while the maximum number of physical CPUs in the pool is {1}. You will not be able to start the appliance on the selected pool. + &Import to: @@ -7299,6 +7293,12 @@ This might result in failure to migrate VMs to this server during the RPU or to Failed to uncompress file {0}. Please see the logs for more information. + + The imported appliance requires a minimum of {0} of memory, while the available memory on the server is {1}. You will not be able to start the VM on the selected server. + + + The imported appliance requires a minimum of {0} of memory, while the maximum available memory on the pool is {1}. You will not be able to start the VM on the selected pool. + Map the virtual network interfaces in the VMs you are importing to networks in the destination pool or standalone server. @@ -9349,25 +9349,17 @@ When you configure an NFS storage repository, you simply provide the host name o (min = {0}, max = {1}) - - The amount of memory allocated to the new VM is greater than the amount of physical memory on any server in the pool. - -Server '{0}' has {1} of physical memory in total. - -You will not be able to start this VM without increasing the amount of physical memory on one of the servers in the pool. + + The amount of memory allocated to the new VM is greater than the amount of physical memory available on any server in the pool ({0}). - - The amount of memory allocated to the new VM is greater than the amount of physical memory available on any server in the pool. - -Server '{0}' has {1} of physical memory available. - -You will not be able to start this VM without freeing some space on one of the servers. + + The amount of memory allocated to the new VM is greater than the amount of physical memory on any server in the pool ({0}). CPU && Memory - Specify the number of virtual CPUs, their topology, and the amount of memory that will be allocated to the new virtual machine. + Specify the number of vCPUs, their topology, and the amount of memory that will be allocated to the new virtual machine. Allocate processor and memory resources @@ -9378,17 +9370,11 @@ You will not be able to start this VM without freeing some space on one of the s vCPUs - - The number of vCPUs given to the new VM is greater than the number of physical CPUs on any server in the pool. - -Server '{0}' has {1} physical CPUs. - -Performance of this VM will be greatly reduced if it is started with this many vCPUs. + + You have specified {0} vCPUs, but none of the pool servers have more than {1} physical CPUs. You will not be able to start the VM. - - All the necessary information has been collected and the wizard is ready to provision the new virtual machine using the settings shown below. - -Review these settings, then click Previous if you need to change anything. Otherwise, click Create Now to create the new VM. It may take several minutes to create the new VM. + + You have specified {0} vCPUs, but the server has only {1} physical CPUs. You will not be able to start the VM. &Create Now @@ -13326,10 +13312,8 @@ To start a {0} trial, click the button below. The vCPUs can only be changed when the VM is shut down. - - The number of VCPUs is greater than the number of physical CPUs on the host server. This will significantly reduce VM performance. - -To optimize VM performance, you should reduce the number of VCPUs to less than or equal to the number of physical CPUs. + + You have selected more than {0} vCPUs for the new VM. Where a VM may be running actively hostile privileged code {1} recommends that the vCPU limit is set to {0} to prevent impact on system availability. VDI @@ -13547,6 +13531,12 @@ To optimize VM performance, you should reduce the number of VCPUs to less than o Initial number of v&CPUs: + + The amount of physical memory allocated to this VM is greater than the total memory of its home server. + + + The amount of physical memory allocated to this VM is greater than the total memory of any server in the pool. + Maximum number of &vCPUs: @@ -13559,11 +13549,14 @@ To optimize VM performance, you should reduce the number of VCPUs to less than o If the initial number of vCPUs is set lower than the maximum number, more vCPUs can be added to the virtual machine while it is running. + + The VM's home server does not have enough physical CPUs to start the VM. The VM will start on another server. + - It is recommended to allocate at least {0} vCPUs for this VM + It is recommended to allocate at least {0} vCPUs for this VM. - More vCPUs than physical CPUs may lead to reduced VM performance + There are no servers with enough physical CPUs to start the VM. &Number of vCPUs: diff --git a/XenModel/XenAPI-Extensions/VM.cs b/XenModel/XenAPI-Extensions/VM.cs index f47e3e244..9ca30ef7a 100644 --- a/XenModel/XenAPI-Extensions/VM.cs +++ b/XenModel/XenAPI-Extensions/VM.cs @@ -59,6 +59,8 @@ namespace XenAPI public const long DEFAULT_MEM_MIN_IMG_IMPORT = 256 * Util.BINARY_MEGA; public const int DEFAULT_CORES_PER_SOCKET = 1; public const long MAX_SOCKETS = 16; // current hard limit in Xen: CA-198276 + // CP-41825: > 32 vCPUs is only supported for trusted VMs + public const long MAX_VCPUS_FOR_NON_TRUSTED_VMS = 32; private XmlDocument xdRecommendations = null; public const int MAX_ALLOWED_VTPMS = 1; @@ -477,16 +479,6 @@ namespace XenAPI other_config = SetDictionaryKey(other_config, "auto_poweron", value.ToString().ToLower()); } - public bool GetIgnoreExcessiveVcpus() - { - return BoolKey(other_config, "ignore_excessive_vcpus"); - } - - public void SetIgnoreExcessiveVcpus(bool value) - { - other_config = SetDictionaryKey(other_config, "ignore_excessive_vcpus", value.ToString().ToLower()); - } - public string IsOnSharedStorage() { foreach (XenRef vbdRef in VBDs) diff --git a/XenModel/XenModel.csproj b/XenModel/XenModel.csproj index 3a6a9a7e8..bf8641373 100755 --- a/XenModel/XenModel.csproj +++ b/XenModel/XenModel.csproj @@ -170,6 +170,11 @@ + + True + True + Messages.resx + True @@ -202,11 +207,6 @@ - - True - True - Messages.resx - From ff869c8ade7cb55a5e0568f9a47cdf2ef2424aaf Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Thu, 27 Apr 2023 01:42:26 +0100 Subject: [PATCH 6/8] CA-375805: Fixed various issues when an unprivileged user tries to add a disk to a VM: - Adding a disk on local SR to an HA protected VM was crashing. - The user could not plug the disk to the VM even after providing credentials on the role elevation dialog. - The user had to enter credentials for each of the sub-actions involved in adding a disk. Signed-off-by: Konstantina Chremmou --- XenAdmin/Dialogs/AttachDiskDialog.cs | 2 +- XenAdmin/Dialogs/NewDiskDialog.cs | 21 ++++++---------- ...lugAction.cs => VbdCreateAndPlugAction.cs} | 25 ++++++++----------- XenModel/Actions/VM/CreateCdDriveAction.cs | 16 ++++++------ XenModel/XenModel.csproj | 2 +- 5 files changed, 29 insertions(+), 37 deletions(-) rename XenModel/Actions/VBD/{VbdSaveAndPlugAction.cs => VbdCreateAndPlugAction.cs} (76%) diff --git a/XenAdmin/Dialogs/AttachDiskDialog.cs b/XenAdmin/Dialogs/AttachDiskDialog.cs index 49d19c7f9..f50e4b7a4 100644 --- a/XenAdmin/Dialogs/AttachDiskDialog.cs +++ b/XenAdmin/Dialogs/AttachDiskDialog.cs @@ -242,7 +242,7 @@ namespace XenAdmin.Dialogs vbd.unpluggable = true; // Try to hot plug the VBD. - var action = new VbdSaveAndPlugAction(TheVM, vbd, TheVDI.Name(), null, false); + var action = new VbdCreateAndPlugAction(TheVM, vbd, TheVDI.Name(), false); action.ShowUserInstruction += Action_ShowUserInstruction; action.RunAsync(); }); diff --git a/XenAdmin/Dialogs/NewDiskDialog.cs b/XenAdmin/Dialogs/NewDiskDialog.cs index 51d53966f..e00eb234b 100644 --- a/XenAdmin/Dialogs/NewDiskDialog.cs +++ b/XenAdmin/Dialogs/NewDiskDialog.cs @@ -150,6 +150,7 @@ namespace XenAdmin.Dialogs } SR sr = srPicker.SR; + var actions = new List(); if (!sr.shared && _vm != null && _vm.HaPriorityIsRestart()) { @@ -160,32 +161,26 @@ namespace XenAdmin.Dialogs return; } - new HAUnprotectVMAction(_vm).RunSync(_vm.Connection.Session); + actions.Add(new HAUnprotectVMAction(_vm)); } if (_vm != null) { //note that this action alters the Device - var action = new CreateDiskAction(Disk, Device, _vm); - using (var dialog = new ActionProgressDialog(action, ProgressBarStyle.Blocks)) - dialog.ShowDialog(); - if (!action.Succeeded) - return; + actions.Add(new CreateDiskAction(Disk, Device, _vm)); // Now try to plug the VBD. - var plugAction = new VbdSaveAndPlugAction(_vm, Device, Disk.Name(), _vm.Connection.Session, false); + var plugAction = new VbdCreateAndPlugAction(_vm, Device, Disk.Name(), false); plugAction.ShowUserInstruction += PlugAction_ShowUserInstruction; - plugAction.RunAsync(); + actions.Add(plugAction); } else { - var action = new CreateDiskAction(Disk); - using (var dialog = new ActionProgressDialog(action, ProgressBarStyle.Marquee)) - dialog.ShowDialog(); - if (!action.Succeeded) - return; + actions.Add(new CreateDiskAction(Disk)); } + new MultipleAction(connection, "", "", "", actions, true, true, true).RunAsync(); + DialogResult = DialogResult.OK; Close(); } diff --git a/XenModel/Actions/VBD/VbdSaveAndPlugAction.cs b/XenModel/Actions/VBD/VbdCreateAndPlugAction.cs similarity index 76% rename from XenModel/Actions/VBD/VbdSaveAndPlugAction.cs rename to XenModel/Actions/VBD/VbdCreateAndPlugAction.cs index 299ef2332..a54320365 100644 --- a/XenModel/Actions/VBD/VbdSaveAndPlugAction.cs +++ b/XenModel/Actions/VBD/VbdCreateAndPlugAction.cs @@ -35,9 +35,9 @@ using XenAPI; namespace XenAdmin.Actions { /// - /// Saves changes on a VBD, then tries to plug the VBD into a VM. + /// Creates a VBD, then tries to plug it into a VM. /// - public class VbdSaveAndPlugAction : AsyncAction + public class VbdCreateAndPlugAction : AsyncAction { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); @@ -48,24 +48,21 @@ namespace XenAdmin.Actions /// public event Action ShowUserInstruction; - public VbdSaveAndPlugAction(VM vm, VBD vbd, string vdiName, Session session, bool suppress) + public VbdCreateAndPlugAction(VM vm, VBD vbd, string vdiName, bool suppress) : base(vm.Connection, string.Format(Messages.ATTACHING_VIRTUAL_DISK, vdiName, vm.Name()), "", suppress) { VM = vm; this.vbd = vbd; - // Preserve existing session if provided. - if (session != null) - this.Session = session; - ApiMethodsToRoleCheck.Add("vbd.async_plug"); - ApiMethodsToRoleCheck.Add("vbd.set_userdevice"); + ApiMethodsToRoleCheck.Add("vbd.create"); + + if (VM.IsHVM() || !vbd.empty) + ApiMethodsToRoleCheck.AddRange("vbd.get_allowed_operations", "vbd.async_plug"); } protected override void Run() { - // First, save changes to the VBD. - - string vbdServerRef = vbd.SaveChanges(Session, null, null); + string vbdServerRef = VBD.create(Session, vbd); if (!VM.IsHVM() && vbd.empty) { @@ -79,13 +76,13 @@ namespace XenAdmin.Actions { log.DebugFormat("Attempting to hot plug VBD {0}.", vbd.uuid); - this.RelatedTask = XenAPI.VBD.async_plug(Session, vbdServerRef); + RelatedTask = VBD.async_plug(Session, vbdServerRef); PollToCompletion(); - this.Description = Messages.ATTACHDISKWIZARD_ATTACHED; + Description = Messages.ATTACHDISKWIZARD_ATTACHED; } else { - VM vm = this.Connection.Resolve(vbd.VM); + VM vm = Connection.Resolve(vbd.VM); if (vm != null && vm.power_state != vm_power_state.Halted) { if (vbd.type == vbd_type.CD) diff --git a/XenModel/Actions/VM/CreateCdDriveAction.cs b/XenModel/Actions/VM/CreateCdDriveAction.cs index 4e1b14133..301eadcfc 100644 --- a/XenModel/Actions/VM/CreateCdDriveAction.cs +++ b/XenModel/Actions/VM/CreateCdDriveAction.cs @@ -49,42 +49,42 @@ namespace XenAdmin.Actions #region RBAC Dependencies ApiMethodsToRoleCheck.Add("vm.assert_agile"); - ApiMethodsToRoleCheck.AddRange(XenAPI.Role.CommonSessionApiList); + ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList); #endregion } protected override void Run() { VBD cdrom = VM.FindVMCDROM(); + if (cdrom == null) { Description = Messages.NEW_DVD_DRIVE_CREATING; - // could not find a cd, try and make one if (VM.VBDs.Count >= VM.MaxVBDsAllowed()) { throw new Exception(Messages.CDDRIVE_MAX_ALLOWED_VBDS); } - List allowedDevices = new List(XenAPI.VM.get_allowed_VBD_devices(Session, VM.opaque_ref)); + var allowedDevices = new List(VM.get_allowed_VBD_devices(Session, VM.opaque_ref)); if (allowedDevices == null || allowedDevices.Count == 0) { throw new Exception(Messages.CDDRIVE_MAX_ALLOWED_VBDS); } - XenAPI.VBD cdDrive = new XenAPI.VBD + VBD cdDrive = new VBD { - VM = new XenAPI.XenRef(VM.opaque_ref), + VM = new XenRef(VM.opaque_ref), bootable = false, device = "", userdevice = allowedDevices.Contains("3") ? "3" : allowedDevices[0], empty = true, - type = XenAPI.vbd_type.CD, - mode = XenAPI.vbd_mode.RO + type = vbd_type.CD, + mode = vbd_mode.RO }; - var cdCreate = new VbdSaveAndPlugAction(VM, cdDrive, Messages.DVD_DRIVE, Session, true); + var cdCreate = new VbdCreateAndPlugAction(VM, cdDrive, Messages.DVD_DRIVE, true); cdCreate.ShowUserInstruction += msg => ShowUserInstruction?.Invoke(msg); cdCreate.RunSync(Session); Description = Messages.NEW_DVD_DRIVE_DONE; diff --git a/XenModel/XenModel.csproj b/XenModel/XenModel.csproj index bf8641373..bdf71c636 100755 --- a/XenModel/XenModel.csproj +++ b/XenModel/XenModel.csproj @@ -138,7 +138,7 @@ - + From d61de95061c460dbb1a5cde45f253ac4046d457a Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Tue, 13 Jun 2023 13:06:34 +0100 Subject: [PATCH 7/8] Refactoring: user camelcase for local variables; made checks a bit more efficient. Signed-off-by: Konstantina Chremmou --- XenAdmin/Dialogs/PropertiesDialog.cs | 141 +++++++++++++-------------- 1 file changed, 68 insertions(+), 73 deletions(-) diff --git a/XenAdmin/Dialogs/PropertiesDialog.cs b/XenAdmin/Dialogs/PropertiesDialog.cs index b9016dc21..ad061a860 100755 --- a/XenAdmin/Dialogs/PropertiesDialog.cs +++ b/XenAdmin/Dialogs/PropertiesDialog.cs @@ -114,25 +114,15 @@ namespace XenAdmin.Dialogs { var pool = Helpers.GetPoolOfOne(connection); - bool is_host = _xenObjectCopy is Host; - bool is_vm = _xenObjectCopy is VM && !((VM)_xenObjectCopy).is_a_snapshot; - bool is_sr = _xenObjectCopy is SR; - - bool is_pool = _xenObjectCopy is Pool; - bool is_vdi = _xenObjectCopy is VDI; - bool is_network = _xenObjectCopy is XenAPI.Network; - - bool is_hvm = is_vm && ((VM)_xenObjectCopy).IsHVM(); - bool is_template = is_vm && ((VM)_xenObjectCopy).is_a_template; - bool is_in_pool = Helpers.GetPool(_xenObjectCopy.Connection) != null; - - bool is_pool_or_standalone = is_pool || (is_host && !is_in_pool); - - bool wlb_enabled = (Helpers.WlbEnabledAndConfigured(_xenObjectCopy.Connection)); - - bool is_VM_appliance = _xenObjectCopy is VM_appliance; - - bool is_VMSS = _xenObjectCopy is VMSS; + bool isHost = _xenObjectCopy is Host; + bool isVm = _xenObjectCopy is VM vm && !vm.is_a_snapshot; + bool isSr = _xenObjectCopy is SR; + bool isPool = _xenObjectCopy is Pool; + bool isVdi = _xenObjectCopy is VDI; + bool isNetwork = _xenObjectCopy is XenAPI.Network; + bool isPoolOrStandalone = isPool || (isHost && Helpers.GetPool(_xenObjectCopy.Connection) == null); + bool isVmAppliance = _xenObjectCopy is VM_appliance; + bool isVmss = _xenObjectCopy is VMSS; ContentPanel.SuspendLayout(); verticalTabs.BeginUpdate(); @@ -143,10 +133,10 @@ namespace XenAdmin.Dialogs ShowTab(GeneralEditPage = new GeneralEditPage()); - if (!is_VM_appliance) + if (!isVmAppliance) ShowTab(CustomFieldsEditPage = new CustomFieldsDisplayPage {AutoScroll = true}); - if (is_vm) + if (isVm) { ShowTab(VCpuMemoryEditPage = new CPUMemoryEditPage()); ShowTab(StartupOptionsEditPage = new BootOptionsEditPage()); @@ -155,7 +145,7 @@ namespace XenAdmin.Dialogs ShowTab(VMHAEditPage); } - if (is_vm || is_host || is_sr) + if (isVm || isHost || isSr) { if (Helpers.FeatureForbidden(_xenObjectCopy, Host.RestrictAlerts)) { @@ -174,7 +164,7 @@ namespace XenAdmin.Dialogs } } - if (is_pool_or_standalone) + if (isPoolOrStandalone) { if (Helpers.FeatureForbidden(_xenObjectCopy, Host.RestrictAlerts)) { @@ -192,81 +182,86 @@ namespace XenAdmin.Dialogs } } - if (is_host) + if (isHost) { ShowTab(hostMultipathPage1 = new HostMultipathPage()); ShowTab(LogDestinationEditPage = new LogDestinationEditPage()); } - - if (is_host || is_pool) + + if (isHost || isPool) ShowTab(HostPowerONEditPage = new HostPowerONEditPage()); - if ((is_pool_or_standalone && Helpers.VGpuCapability(_xenObjectCopy.Connection)) - || (is_host && ((Host)_xenObjectCopy).CanEnableDisableIntegratedGpu())) + if ((isPoolOrStandalone && Helpers.VGpuCapability(_xenObjectCopy.Connection)) + || (isHost && ((Host)_xenObjectCopy).CanEnableDisableIntegratedGpu())) { ShowTab(PoolGpuEditPage = new PoolGpuEditPage()); } - if (is_pool_or_standalone && !Helpers.FeatureForbidden(_xenObjectCopy.Connection, Host.RestrictSslLegacySwitch) && !Helpers.StockholmOrGreater(connection)) + if (isPoolOrStandalone && !Helpers.FeatureForbidden(_xenObjectCopy.Connection, Host.RestrictSslLegacySwitch) && !Helpers.StockholmOrGreater(connection)) ShowTab(SecurityEditPage = new SecurityEditPage()); - if (is_pool_or_standalone && !Helpers.FeatureForbidden(_xenObjectCopy.Connection, Host.RestrictIGMPSnooping) && Helpers.GetCoordinator(pool).vSwitchNetworkBackend()) + if (isPoolOrStandalone && !Helpers.FeatureForbidden(_xenObjectCopy.Connection, Host.RestrictIGMPSnooping) && Helpers.GetCoordinator(pool).vSwitchNetworkBackend()) ShowTab(NetworkOptionsEditPage = new NetworkOptionsEditPage()); - if (is_pool_or_standalone && !Helpers.FeatureForbidden(_xenObjectCopy.Connection, Host.RestrictCorosync)) + if (isPoolOrStandalone && !Helpers.FeatureForbidden(_xenObjectCopy.Connection, Host.RestrictCorosync)) ShowTab(ClusteringEditPage = new ClusteringEditPage()); - if (is_pool && Helpers.Post82X(_xenObjectCopy.Connection) && Helpers.XapiEqualOrGreater_22_33_0(_xenObjectCopy.Connection)) + if (isPool && Helpers.Post82X(_xenObjectCopy.Connection) && Helpers.XapiEqualOrGreater_22_33_0(_xenObjectCopy.Connection)) ShowTab(_poolAdvancedEditPage = new PoolAdvancedEditPage()); - if (is_network) + if (isNetwork) ShowTab(editNetworkPage = new EditNetworkPage()); - if (is_vm && !wlb_enabled) - ShowTab(HomeServerPage = new HomeServerEditPage()); - - if (is_vm && ((VM)_xenObjectCopy).CanHaveGpu()) + if (isVm) { - if (Helpers.FeatureForbidden(_xenObjectCopy, Host.RestrictGpu)) + var theVm = (VM)_xenObjectCopy; + + if (!Helpers.WlbEnabledAndConfigured(_xenObjectCopy.Connection)) + ShowTab(HomeServerPage = new HomeServerEditPage()); + + if (theVm.CanHaveGpu()) { - GpuUpsellEditPage = new UpsellPage + if (Helpers.FeatureForbidden(_xenObjectCopy, Host.RestrictGpu)) { - Image = Images.StaticImages._000_GetMemoryInfo_h32bit_16, - Text = Messages.GPU, - BlurbText = Messages.UPSELL_BLURB_GPU - }; - ShowTab(GpuUpsellEditPage); + GpuUpsellEditPage = new UpsellPage + { + Image = Images.StaticImages._000_GetMemoryInfo_h32bit_16, + Text = Messages.GPU, + BlurbText = Messages.UPSELL_BLURB_GPU + }; + ShowTab(GpuUpsellEditPage); + } + else + { + if(Helpers.GpusAvailable(connection)) + ShowTab(GpuEditPage = new GpuEditPage()); + } } - else + + if (theVm.IsHVM()) { - if(Helpers.GpusAvailable(connection)) - ShowTab(GpuEditPage = new GpuEditPage()); + if (!theVm.is_a_template && !Helpers.FeatureForbidden(_xenObjectCopy, Host.RestrictUsbPassthrough) && + pool.Connection.Cache.Hosts.Any(host => host.PUSBs.Count > 0)) + { + usbEditPage = new USBEditPage(); + usbEditPage.Populated += EditPage_Populated; + ShowTab(usbEditPage); + } + + ShowTab(VMAdvancedEditPage = new VMAdvancedEditPage()); + } + + if (Helpers.ContainerCapability(_xenObjectCopy.Connection)) + { + if (theVm.CanBeEnlightened()) + ShowTab(VMEnlightenmentEditPage = new VMEnlightenmentEditPage()); + + if (theVm.CanHaveCloudConfigDrive()) + ShowTab(CloudConfigParametersPage = new Page_CloudConfigParameters()); } } - if (is_hvm && !is_template && !Helpers.FeatureForbidden(_xenObjectCopy, Host.RestrictUsbPassthrough) && - pool.Connection.Cache.Hosts.Any(host => host.PUSBs.Count > 0)) - { - usbEditPage = new USBEditPage(); - usbEditPage.Populated += EditPage_Populated; - ShowTab(usbEditPage); - } - - if (is_hvm) - { - ShowTab(VMAdvancedEditPage = new VMAdvancedEditPage()); - } - - if (is_vm && Helpers.ContainerCapability(_xenObjectCopy.Connection)) - { - if (((VM)_xenObjectCopy).CanBeEnlightened()) - ShowTab(VMEnlightenmentEditPage = new VMEnlightenmentEditPage()); - - if (((VM)_xenObjectCopy).CanHaveCloudConfigDrive()) - ShowTab(CloudConfigParametersPage = new Page_CloudConfigParameters()); - } - - if (is_VMSS) + if (isVmss) { ShowTab(newVMSSVMsPage1 = new NewVMGroupVMsPage {Pool = pool}); ShowTab(newPolicyVMSSTypePage1 = new NewPolicySnapshotTypePage()); @@ -275,16 +270,16 @@ namespace XenAdmin.Dialogs ShowTab(newPolicySnapshotFrequencyPage1); } - if (is_VM_appliance) + if (isVmAppliance) { ShowTab(newVMApplianceVMsPage1 = new NewVMGroupVMsPage { Pool = pool }); ShowTab(newVmApplianceVmOrderAndDelaysPage1 = new NewVMApplianceVMOrderAndDelaysPage { Pool = pool }); } - if (is_sr && ((SR)_xenObjectCopy).SupportsReadCaching() && !Helpers.FeatureForbidden(_xenObjectCopy, Host.RestrictReadCaching)) + if (isSr && ((SR)_xenObjectCopy).SupportsReadCaching() && !Helpers.FeatureForbidden(_xenObjectCopy, Host.RestrictReadCaching)) ShowTab(SrReadCachingEditPage = new SrReadCachingEditPage()); - if (is_vdi) + if (isVdi) { ShowTab(vdiSizeLocation = new VDISizeLocationPage()); From 6de8eb90bd9bba9590ae9b9e9a2bbce1e2f50fc1 Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Tue, 13 Jun 2023 15:26:34 +0100 Subject: [PATCH 8/8] Fixed script that broke the build. Signed-off-by: Konstantina Chremmou --- scripts/re-branding.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/re-branding.sh b/scripts/re-branding.sh index 32858a131..5ac10f534 100644 --- a/scripts/re-branding.sh +++ b/scripts/re-branding.sh @@ -49,7 +49,7 @@ rebranding_global() -e "s#\[XenCenter_No_Space\]#${BRANDING_BRAND_CONSOLE_NO_SPACE}#g" \ -e "s#xencenter\/current-release\/#${BRANDING_HELP_PATH}#g" \ -e "s#\[Xc updates url\]#${XC_UPDATES_URL}#g" \ - -e "s#\[Cfu url\]#${CFU_URL}#g" \ + -e "s#\[Cfu url\]#${CFU_URL}#g" \ $1 }