-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CP-44171: XenCenter: Add SNMP page #3254
CP-44171: XenCenter: Add SNMP page #3254
Conversation
As we discussed, remember to change UI
See details from CA-384958. |
3534862
to
6bcc4b4
Compare
finished and committed |
6bcc4b4
to
a96c493
Compare
privacy_protocol = _snmpConfiguration.PrivacyProtocol, | ||
} | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some redundant codes for these three if statements. Can we combine these three if statements into one?
{ | ||
{"config", new JavaScriptSerializer().Serialize(configArgObj)} | ||
}; | ||
var resultJson = Host.call_plugin(o.Connection.Session, o.opaque_ref, SnmpXapiConfig.XAPI_SNMP_PLUGIN_NAME, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resultJson
is not used. Can remove it, or record some logs.
authentication_password = _snmpConfiguration.AuthPass, | ||
authentication_protocol = _snmpConfiguration.AuthProtocol, | ||
privacy_password = _snmpConfiguration.PrivacyPass, | ||
privacy_protocol = _snmpConfiguration.PrivacyProtocol, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove trailing comma.
using System.Web.Script.Serialization; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Dynamic; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary packages.
XenModel/Messages.resx
Outdated
<value>Privacy password is invalid</value> | ||
</data> | ||
<data name="SNMP_ALLOW_SECURITY_TITLE" xml:space="preserve"> | ||
<value>Security name is invalid</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security name -> User Name
|
||
public bool Equals(SnmpConfiguration other) | ||
{ | ||
return !(IsSnmpEnabled != other.IsSnmpEnabled || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more clear to use equal than to use not equal. Can be replaced like this:
return (IsSnmpEnabled == other.IsSnmpEnabled &&
IsLogEnabled == other.IsLogEnabled &&
...
public SnmpConfiguration() { } | ||
|
||
|
||
public object Clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used, can be removed. ICloneable needs not to be implemented.
var configArgObj = GetConfigArgObj(); | ||
Dictionary<string, string> configArgDict = new Dictionary<string, string> | ||
{ | ||
{"config", new JavaScriptSerializer().Serialize(configArgObj)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value of config
is a JSON string. Can we use JsonSerializer
to serialize the JSON object?
private GroupBox GeneralConfigureGroupBox; | ||
private TableLayoutPanel GeneralConfigTableLayoutPanel; | ||
|
||
private CheckBox EnableSnmpCheckBox; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The height of EnableSnmpCheckBox
, DebugLogCheckBox
, and SupportV3CheckBox
is different. Please adjust them.
a96c493
to
dd2bcc3
Compare
I have resolved and recommitted the issue you mentioned above. @BengangY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the first comments I have from reading the code (plus the layout tweaks in that patch file I sent you, you can also see it here kc284@4f4a7ff).
I may have some more comments later after I set up a machine and try out the code, but in the mean time you can work on the current stuff.
XenAdmin/Dialogs/PropertiesDialog.cs
Outdated
@@ -317,6 +318,11 @@ private void Build() | |||
dialog.ShowDialog(Program.MainWindow); | |||
} | |||
} | |||
if (isPoolOrStandalone) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The page should not be visible at all for servers that don't have the plugin installed. Showing the error "retrieving the SNMP configuration failed" is misleading, especially for LCM servers where SNMP is not supported. We need a version check. Helpers.NileOrGreater
, for example, excludes LCM servers. However, it is not enough because it does not exclude stream servers where updates have not been installed yet. We need a plugin version check (or a xapi version check as a compromise; we did this for NRPE).
Also, to keep a uniform behaviour with NRPE, the page should not be visible for users that are not pool admins.
XenModel/Messages.resx
Outdated
<value>SNMP configuration</value> | ||
</data> | ||
<data name="SNMP_RETRIEVE_FAILED" xml:space="preserve"> | ||
<value>Failed to retrieve SNMP configuration, please check XenCenter logs.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This contains the product brand, which causes problems for forks that do rebranding. We need to use Failed to retrieve SNMP configuration, please check {0} logs.
and then call it in the code as string.Format(Messages.SNMP_RETRIEVE_FAILED, BrandManager.BrandConsole)
- or a simpler solution is to say Failed to retrieve SNMP configuration, please check the application logs.
The same applies to the other messages below.
XenModel/Messages.resx
Outdated
<value>Failed to retrieve SNMP configuration, please check XenCenter logs.</value> | ||
</data> | ||
<data name="SNMP_UPDATE_ERROR1" xml:space="preserve"> | ||
<value>Common error, please check XenCenter logs for details.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of error is the "common error"? It sounds a bit vague.
|
||
public bool Equals(SnmpConfiguration other) | ||
{ | ||
return (IsSnmpEnabled == other.IsSnmpEnabled && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parentheses are not needed. Missing null check: return other != null && ...
Also, very trivial issue, but could you please leave an empty line between the various class declarations so the code is easier to read (just use VS to auto-format the file).
private readonly IXenObject _clone; | ||
|
||
public SnmpRetrieveAction(IXenObject host, SnmpConfiguration snmpConfiguration, bool suppressHistory) | ||
: base(host.Connection, "Retrieving SNMP configuration", "Retrieving SNMP configuration", suppressHistory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These strings here are shown on the UI, therefore we need to internationalize them, i.e. move them to Messages.resx.
if (SupportV2cCheckBox.Checked) | ||
{ | ||
var communityStr = CommunityTextBox.Text; | ||
if (!RegexCommon.Match(communityStr.Trim()).Success) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we be checking for null first? I.e. if (string.IsNullOrEmpty(communityStr) || !Regex...)
. Same in the other checks below.
} | ||
private void EnableSNMPCheckBox_CheckedChanged(object sender, EventArgs e) | ||
{ | ||
if (EnableSnmpCheckBox.Checked) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if-else block can be replaced with:
DebugLogCheckBox.Enabled = EnableSnmpCheckBox.Checked;
SnmpV2cGroupBox.Enabled = EnableSnmpCheckBox.Checked && SupportV2cCheckBox.Checked;
etc.
{ | ||
get | ||
{ | ||
_invalidParamToolTip.Dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to dispose and reconstruct the tooltip every time, we can make it readonly and just hide/show it and change the text. Also, to decide on which control to show it you can use the Tag, but an alternative way would be to use HelpersGUI.ShowBalloonMessage(). Have a look in file GeneralEditPage.cs
to see how that tooltip is used.
private string _invalidParamToolTipText = ""; | ||
private static readonly Regex RegexCommon = new Regex(@"^[a-zA-Z0-9-.\#@=:_]{6,32}$"); | ||
private static readonly Regex RegexEncryptTextBox = new Regex(@"^([a-zA-Z0-9-.\#@=:_]{8,32}|[*]{8})$"); | ||
private static bool _encryptTextBoxFlag = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting to false
when declaring the field is not needed because it is the default value anyway. Also, why is it static
?
{ | ||
public partial class SnmpEditPage : UserControl, IEditPage | ||
{ | ||
public string SubText => Messages.SNMP_EDIT_PAGE_TEXT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very trivial thing, but since you'll be making changes in this file anyway let's tidy up a bit:
- Sort usings alphabetically.
- Move the constructor after the private fields, and SubText and Image properties after the constructor.
- Move SaveSettings closer to the other IEditPage implementation methods.
- Leave a line between all methods so the code can breath a bit (lack of lines is normally a C++ style).
dd2bcc3
to
ee033f4
Compare
Signed-off-by: Konstantina Chremmou <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the above comment I have made some more changes here kc284@68a9b41 (I also sent you this patch privately), please try it out and let me know what you think.
@@ -317,6 +318,12 @@ private void Build() | |||
dialog.ShowDialog(Program.MainWindow); | |||
} | |||
} | |||
if (isPoolOrStandalone && Helpers.XapiEqualOrGreater_23_18_0(connection) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
23.18.0
is a very early version. In any case, @DeliZhangX mentioned they will be adding a feature flag, so we can now check that one instead of the xapi version (I would also add the Helpers.NileOrGreater
check as an extra safety valve for older servers). See XenModel/XenAPI-Extensions/Host.cs for methods checking the feature flags.
No description provided.