Skip to content
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

Merged
merged 6 commits into from
May 19, 2020
Merged

Add put/get/delete alert_source APIs. #59

merged 6 commits into from
May 19, 2020

Conversation

sfzeng
Copy link
Collaborator

@sfzeng sfzeng commented May 18, 2020

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:
2020-05-18_161319
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:

dolphin/db/sqlalchemy/api.py Outdated Show resolved Hide resolved
dolphin/db/sqlalchemy/models.py Outdated Show resolved Hide resolved
dolphin/db/sqlalchemy/models.py Outdated Show resolved Hide resolved
dolphin/exception.py Show resolved Hide resolved
dolphin/utils.py Outdated Show resolved Hide resolved
dolphin/api/v1/alert.py Outdated Show resolved Hide resolved
dolphin/api/v1/alert.py Outdated Show resolved Hide resolved
dolphin/api/v1/alert.py Show resolved Hide resolved
@@ -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",
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

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."
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

'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},
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to auth_key

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."
Copy link
Collaborator

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

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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

@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize import

Copy link
Collaborator Author

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'],
Copy link
Collaborator

@sushanthakumar sushanthakumar May 18, 2020

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

Copy link
Collaborator Author

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):
Copy link
Collaborator

@sushanthakumar sushanthakumar May 18, 2020

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?

Copy link
Collaborator Author

@sfzeng sfzeng May 19, 2020

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)
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

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)
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

raise exc.HTTPBadRequest(explanation=msg)
except exception.InvalidInput as e:
msg = _('Failed to put alert_source: {0}'.format(e))
raise exc.HTTPBadRequest(explanation=msg)
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

kumarashit
kumarashit previously approved these changes May 19, 2020
Copy link
Collaborator

@kumarashit kumarashit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

dolphin/api/v1/alert.py Show resolved Hide resolved
dolphin/utils.py Outdated Show resolved Hide resolved
@sushanthakumar
Copy link
Collaborator

LGTM

"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."
Copy link
Collaborator

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"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

wisererik
wisererik previously approved these changes May 19, 2020
@sushanthakumar
Copy link
Collaborator

LGTM

Copy link
Collaborator

@kumarashit kumarashit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wisererik wisererik merged commit a27aac7 into sodafoundation:master May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants