-
Notifications
You must be signed in to change notification settings - Fork 355
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
Add put/get/delete alert_source APIs. #59
Conversation
dolphin/api/v1/router.py
Outdated
@@ -49,6 +50,21 @@ def _setup_routes(self, mapper): | |||
controller=self.resources['access_info'], | |||
action="update", | |||
conditions={"method": ["PUT"]}) | |||
|
|||
self.resources['alert_sources'] = alert.create_resource() | |||
mapper.connect("storages", "/storages/{id}/alert_sources", |
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.
plz don't use underscore in the url. suggest name: alert-source
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.
Fixed
dolphin/api/v1/alert.py
Outdated
auth_enable_str = alert_source.get('auth_enable', None) | ||
engine_id = alert_source.get('engine_id', None) | ||
if not user_name or not auth_enable_str or not engine_id: | ||
msg = "username, auth_enable and engine_id are required if snmp version is SNMPv3." |
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.
First letter should be upper case in message.
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.
Done
… instead of underscore in the url
dolphin/api/schemas/alert.py
Outdated
'version': parameter_types.snmp_version, | ||
'community_string': {'type': 'string', 'minLength': 1, 'maxLength': 255}, | ||
'username': {'type': 'string', 'minLength': 1, 'maxLength': 255}, | ||
'password': {'type': 'string', 'minLength': 1, 'maxLength': 255}, |
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 can change to auth_password or auth_key
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.
Changed to auth_key
dolphin/api/v1/alert.py
Outdated
auth_enabled_str = alert_source.get('auth_enabled', None) | ||
engine_id = alert_source.get('engine_id', None) | ||
if not user_name or not auth_enabled_str or not engine_id: | ||
msg = "If snmp version is SNMPv3, then username, auth_enabled and engine_id are required." |
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.
Few lines looks to be beyond page border
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.
My IDE(Pycharm) shows, all lines are fine, which IDE you used?
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.
Anyway, I cut those long lines.
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.
As per Python coding guidelines, the max char for a line is 79..So maybe you can set the line wrap/length accordingly
dolphin/api/v1/router.py
Outdated
@@ -19,6 +19,7 @@ | |||
from dolphin.api.v1 import access_info | |||
from dolphin.api.v1 import pools | |||
from dolphin.api.v1 import volumes | |||
from dolphin.api.v1 import alert |
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.
Optimize import
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.
Done
@@ -172,3 +172,22 @@ def valid_char(char): | |||
'minimum': 0, 'maximum': 65535 | |||
} | |||
|
|||
boolean = { | |||
'type': ['string'], | |||
'enum': [True, 'True', 'TRUE', 'true', False, 'False', 'FALSE', '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.
Do we really need to support many combinations, lets check the usual practice
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.
I think yes, I check cinder, it used the same way.
return IMPL.alert_source_update(context, storage_id, values) | ||
|
||
|
||
def alert_source_get(context, storage_id): |
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 need to fetch alert source when we want to get storage id from source ip. So we need one alert source get all api with filter, do we have it already?
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 PR only include the user side functuion, that will be done in the next PR, otherwise PR will became too big.
if version.lower() == 'snmpv3': | ||
user_name = alert_source.get('username', None) | ||
auth_enabled_str = alert_source.get('auth_enabled', None) | ||
engine_id = alert_source.get('engine_id', None) |
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.
If user selects v3 and gives just username and enginid, will it be success. Is it better to consider default auth_enabled_str as 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.
In that case, it will failed and the error message will tell the user auth_enabled is required. Cauz IMO, SNMPv3 is mainly for security, if auth is not enabled, then that will not be safe, so we'd better let the user to explicitly enable or disable authentication.
dolphin/api/v1/alert.py
Outdated
else: | ||
alert_source = db.alert_source_create(ctx, alert_source) | ||
except exception.StorageNotFound as e: | ||
msg = (_("Alert source cannot be created or updated for a non-exist storage %s.") % id) |
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.
non-exist can be changed to non-existing
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.
Done
dolphin/api/v1/alert.py
Outdated
raise exc.HTTPBadRequest(explanation=msg) | ||
except exception.InvalidInput as e: | ||
msg = _('Failed to put alert_source: {0}'.format(e)) | ||
raise exc.HTTPBadRequest(explanation=msg) |
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.
Any chance of getting general exception here?
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 test show, those exception will be handled in wsgi level.
…t long lines to be shorter.
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.
LGTM
LGTM |
dolphin/api/v1/alert.py
Outdated
"auth_protocol and auth_key is required." | ||
msg = "If snmp version is SNMPv3 and security_level is " \ | ||
"AuthPriv or AuthNoPriv, auth_protocol and auth_key" \ | ||
" is required." |
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.
just change to "are required"
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.
Done
LGTM |
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.
LGTM
What this PR does / why we need it:
This PR is to add PUT/GET/DELETE alert source APIs.
Which issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close that issue when PR gets merged): fixes #Special notes for your reviewer:
Currently, the alert source is considered as a host with a specific ip, it may be changed to a host list in the future.
For SNMPv3, the security model may looks like as below:
So when snmp version is set as SNMPv3, we need to check those parameters. Check Table 1 from the following link for details about SNMPv3 Security Mechanisms: https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/snmp/configuration/xe-3se/3850/snmp-xe-3se-3850-book/nm-snmp-snmpv3.html
Release note: