-
Notifications
You must be signed in to change notification settings - Fork 193
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
Snapshot notify #1554
Snapshot notify #1554
Conversation
Changes for snapshot notification enable and disable option from slcli
API features in this request will be public when FBLOCK-4191 is complete. |
Formatting errors mentioned in softlayer#1554 being resolved.
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.
Thanks for the pull request, just a few changes needed.
- Fix the style checks
- CLI commands here should both use the Click flag option so users can just do
slcli file set-notify-status --enable
- Command storage API calls go in the storage manager
- No need for the **kwargs in the managers.
- Add unit tests for these functions
|
||
if (enabled == ''): | ||
click.echo( | ||
'Snapshots space usage threshold warning flag setting is null. Set to default value enable. For volume %s' |
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.
'Snapshots space usage threshold warning flag setting is null. Set to default value enable. For volume %s' | |
'Snapshots space usage threshold warning flag setting is null. Use `slcli block snapshot-set-notification %s --enable` to enable' |
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.
Addressed
@click.option( | ||
'--notification_flag', | ||
help= | ||
'Enable / disable sending sending notifications for snapshots space usage threshold warning [True|False]', | ||
required=True) |
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.
Click has a flag option, use that here, and set the default to Enable.
@click.option( | |
'--notification_flag', | |
help= | |
'Enable / disable sending sending notifications for snapshots space usage threshold warning [True|False]', | |
required=True) | |
@click.option( | |
'--enable/disable', required=True, default=True, | |
help='Enable / disable sending sending notifications for snapshots space usage threshold warning', | |
) |
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
@environment.pass_env | ||
def cli(env, volume_id, notification_flag): | ||
"""Enables/Disables snapshot space usage threshold warning for a given volume""" | ||
if (notification_flag not in ['True', '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.
This wont be needed when you switch to the click flag
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
@click.option( | ||
'--notification_flag', | ||
help= | ||
'Enable / disable sending sending notifications for snapshots space usage threshold warning [True|False]', | ||
required=True) |
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.
Click has a flag option, use that here, and set the default to Enable.
@click.option( | |
'--notification_flag', | |
help= | |
'Enable / disable sending sending notifications for snapshots space usage threshold warning [True|False]', | |
required=True) | |
@click.option( | |
'--enable/disable', required=True, default=True, | |
help='Enable / disable sending sending notifications for snapshots space usage threshold warning', | |
) |
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
SoftLayer/managers/block.py
Outdated
@@ -102,6 +102,25 @@ def get_block_volume_snapshot_list(self, volume_id, **kwargs): | |||
""" | |||
return self.get_volume_snapshot_list(volume_id, **kwargs) | |||
|
|||
def set_block_volume_snapshot_notification(self, volume_id, notification_flag, **kwargs): |
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.
- Add this to the storage manager, not the block/file managers since the code is exactly the same. The block/file managers inherit from the storage manager, so you shouldn't even need to edit your cli code.
- Don't pass **kwargs into the API, and likely don't even need to accept them in this function unless these methods take in objectMasks or objectFilters, which I'm guessing they wont
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
SoftLayer/managers/file.py
Outdated
@@ -129,7 +129,24 @@ def get_file_volume_snapshot_list(self, volume_id, **kwargs): | |||
:return: Returns a list of snapshots for the specified volume. | |||
""" | |||
return self.get_volume_snapshot_list(volume_id, **kwargs) | |||
def set_file_volume_snapshot_notification(self, volume_id, notification_flag, **kwargs): |
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.
Same comments as the block manager
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
SoftLayer/managers/storage.py
Outdated
@@ -112,6 +112,15 @@ def get_volume_snapshot_list(self, volume_id, **kwargs): | |||
kwargs['mask'] = ','.join(items) | |||
|
|||
return self.client.call('Network_Storage', 'getSnapshots', id=volume_id, **kwargs) | |||
def set_volume_snapshot_notification(self, volume_id, notification_flag, **kwargs): |
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 the **kwargs as its not really needed.
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
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.
Looks good, just a comment.
SoftLayer/managers/block.py
Outdated
:param volume_id: ID of volume. | ||
:param kwargs: | ||
:param notification-flag: Enable/Disable flag for snapshot warning notification. | ||
:return: Enables/Disables snapshot space usage threshold warning for a given volume. |
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 would be good if you specify what type of data this method is returning too:
e.g.
bool
or an object for example SoftLayer_Network_Storage
.
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.
Did not get your recommendation. The return type is a string from an SLCLI perspective. Its a message
SoftLayer/managers/block.py
Outdated
|
||
:param volume_id: ID of volume. | ||
:param kwargs: | ||
:return: Enabled/Disabled snapshot space usage threshold warning for a given volume. |
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 same that above, about specifying what type of data this method is returning.
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.
Did not get your recommendation. The return type is a string from an SLCLI perspective. Its a 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.
I'm a little concerned that it looks like this API is returning and requiring the strings "True"
and "False"
instead of actual boolean values, if that is the case then the API needs to be updated to fix that.
In any case, the python code should just be dealing with the boolean values, and not the strings. Hopefully that makes sense.
Also, please mark the comments as "resolved" when you resolve them, that helps. And make sure you remove the undeeded code in the file/block managers that you moved to the storage manager since those are no longer needed. Thanks.
if enable: | ||
enabled = 'True' | ||
else: | ||
enabled = '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.
This wont work. Just pass the boolean value into the manager/api, otherwise the SL API will interpret it as a string, which PHP will always treat as true. Just pass enable
into the manager function.
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 am in agreement with you. However, this is sort of limitation of code flow between python and PHP. I tried sending the flag but its not properly getting received at the REST end. If required i can demonstrate over a webex.
The current code is test verified over an SLCLI and screenshots are uploaded.
if enable: | |
enabled = 'True' | |
else: | |
enabled = 'False' | |
if enable: | |
enabled = 'True' | |
else: | |
enabled = 'False' |
if enable: | ||
enabled = 'True' | ||
else: | ||
enabled = '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.
This wont work. Just pass the boolean value into the manager/api, otherwise the SL API will interpret it as a string, which PHP will always treat as true. Just pass enable
into the manager function.
Testing Results:
@hariha74 For this API method, I really think you need to make SoftLayer_Network_Storage/setSnapshotNotification accept only a boolean value, and SoftLayer_Network_Storage/getSnapshotNotificationStatus return only a boolean value. Otherwise between the various ways a user can call this API, you are going to have all sorts of strings in this status table and its going to be a mess. You should also make sure the documentation for these methods looks correct. When those API methods are updated to return only a boolean value, I think updating this CLI code to work with that should be pretty straight forward and make everything a lot easier. Let me know if you have any questions. |
I am in agreement as i said earlier. Essentially, the way boolean is interpreted in a PHP ( as True ) is different from a boolean is interpreted in python ( true ). I would recommend to have a webex once to have a deep dive discussion. I am scheduling it for Tuesday ( Monday being a holiday in India ). Thanks again for all your help in analyzing the code and providing your valuable comments. |
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.
Need to fix the code style errors first, but otherwise looks fine. You can check the analysis with tox -e analysis
in your local softlayer-python directory.
Function change to enable or disable notification for snapshot notification