Manila: add support for share metadata modification#1656
Manila: add support for share metadata modification#1656jtopjian merged 8 commits intogophercloud:masterfrom
Conversation
2c78f01 to
78507b9
Compare
|
Build failed.
|
|
/test gophercloud-acceptance-test |
|
PTAL @jtopjian @gouthampacha |
|
recheck |
|
Build failed.
|
jtopjian
left a comment
There was a problem hiding this comment.
@gman0 Looks good - just some suggestions for two of the functions.
I think the OpenLab error can be ignored for now. I don't see how this PR would affect the test that is failing.
Please let me know if you have any questions.
|
|
||
| // ShowMetadata retrieves metadata of the specified share. To extract the retrieved | ||
| // metadata from the response, call the Extract method on the ShowMetadataResult. | ||
| func ShowMetadata(client *gophercloud.ServiceClient, id string) (r ShowMetadataResult) { |
There was a problem hiding this comment.
It looks like the Manila code has support to retrieve a single metadata/metadatum: https://github.com/openstack/manila/blob/cec13b8057fa025fa1b1c3bef180687a394d6fd6/manila/api/v1/share_metadata.py#L121
To prevent confusion, let's change this to either Metadata or GetMetadata. Both have been used in Gophercloud before.
There was a problem hiding this comment.
+1 GetMetadata corresponds to this project's idioms...
A GetMetadatum call may be useful too, thanks for pointing that out @jtopjian.. It'll make things faster if you're trying to verify if some metadata key exists, or set to a particular value.
There was a problem hiding this comment.
If that API call is exposed, I agree. The API documentation doesn't have it listed, but that might just mean it's undocumented :)
There was a problem hiding this comment.
Yep! fixing the docs here: https://review.opendev.org/#/c/673112/
| } | ||
|
|
||
| // UnsetMetadata deletes a single key-value pair from the metadata of the specified share. | ||
| func UnsetMetadata(client *gophercloud.ServiceClient, id, key string) (r UnsetMetadataResult) { |
There was a problem hiding this comment.
Because this API call is only for a single piece of metadata/metadatum, let's change this to either UnsetMetadatum or DeleteMetadatum. "Metadatum" is used throughout Gophercloud to denote a single piece of metadata.
gouthampacha
left a comment
There was a problem hiding this comment.
This looks great, just a small comment inline... Thanks for working on this @gman0!
| } | ||
|
|
||
| // SetMetadata sets metadata of the specified share. To extract the updated | ||
| // metadata from the response, call the Extract method on the SetMetadataResult. |
There was a problem hiding this comment.
Worth calling out the difference between SetMetadata and UpdateMetadata, as a comment for future maintainers:
SetMetadata allows adding new metadata items or updating values of existing metadata items; however, UpdateMetadata will drop existing metadata and replace it with new metadata key=value pairs as specified.
|
@jtopjian @gouthampacha thank you guys for the feedback and guidance!! All your comments are addressed in separate commits, I can squash them later if needed once the review is finished. |
|
Build failed.
|
|
recheck |
|
Build succeeded.
|
jtopjian
left a comment
There was a problem hiding this comment.
@gman0 This is looking good. I left a comment about changing the GetMetadatum result and then refactoring 4/5 of the functions as a result (no pun intended) of the change.
Let me know if you have any questions. Also let me know if these suggestions are incorrect and break things - I don't have easy access to a Manila environment so I can't test these out first-hand.
| // GetMetadatumResult contains the response body and error from a GetMetadatum request. | ||
| type GetMetadatumResult struct { | ||
| gophercloud.Result | ||
| key string |
There was a problem hiding this comment.
I understand the purpose of this, but let's use the style that has been previously used here: https://github.com/gophercloud/gophercloud/blob/master/openstack/compute/v2/servers/results.go#L346-L352
This returns a map[string]string so the user/dev can do:
result, err := shares.GetMetadatum(c, shareID, "foo").Extract()
fmt.Println(result["foo"])Once it's updated like this, it looks like GetMetadata, GetMetadatum, SetMetadata, and UpdateMetadata can all share a single result type:
type MetadataResult struct {
gophercloud.Result
}
func (r MetadataResult) Extract() (map[string]string, error) {
...
}Let me know if this makes sense or if you have any questions.
There was a problem hiding this comment.
Actually GetMetadatum would still need a separate result type because it uses meta parent in its JSON response instead of metadata like the other methods use (see example responses for show-metadata VS show-metadata-item). I'll merge the result types for the rest of the methods.
There was a problem hiding this comment.
Should GetMetadatumResult then still return map[string]string like you're suggesting, or rather keep things as they are in this PR and return string? I'm totally fine with either, especially if it's to keep things consistent...although the latter seems a bit more user-friendly by not having to repeat the metadata key.
There was a problem hiding this comment.
Actually GetMetadatum would still need a separate result type because it uses meta parent in its JSON response instead of metadata like the other methods use
Good catch.
Should GetMetadatumResult then still return map[string]string like you're suggesting,
Yes, please.
I agree that it can be more intuitive to have only the value returned, but using this method keeps things consistent with other metadata areas in Gophercloud. In addition, it more closely models the API response (since the API response is a dict/object/hash).
…etadatumResult now returns a map
|
Build succeeded.
|
|
PTAL @jtopjian |
jtopjian
left a comment
There was a problem hiding this comment.
LGTM - thank you for your patience with this!
For #1653
Manila API reference for Share metadata: https://docs.openstack.org/api-ref/shared-file-system/#share-metadata