Repository: ceph/go-ceph
Pull request #608 (2021-10-30 09:13:01)

rbd: export image name
Signed-off-by: Seena Fallah <seenafallah@gmail.com>

## Checklist
- [x] Added tests for features and functional changes
- [x] Public functions and types are documented
- [x] Standard formatting is applied to Go code


nixpanic: Thanks for the PR!

Could you explain why you need this detail to be public? I would be more comfortable to add a `Image.GetName()` function, which prevents changing the `Image.name` of the object and getting things out of sync. Is that an alternative that works for you too?
clwluvw: > Thanks for the PR!
> 
> Could you explain why you need this detail to be public? I would be more comfortable to add a `Image.GetName()` function, which prevents changing the `Image.name` of the object and getting things out of sync. Is that an alternative that works for you too?

@nixpanic I need it for the programming use case. For example, when I pass an `rbd.Image` to a function I need its name and because the name is not exported I can't get it from the image object.
Yes, it's ok to me. I changed to the PR to return name with`GetName` func.
clwluvw: @nixpanic Seems the failures are not related to my changes 🤔 
phlogistonjohn: @ansiwen do you have any objections to making exceptions to the API stability policy for extremely simple and straightforward changes like this one? I am. However, before I approve and merge I want to give you a chance to reply. Thanks!
nixpanic: > @nixpanic Seems the failures are not related to my changes thinking

No problem, this is a known issue and being addressed by #607
phlogistonjohn: FWIW the go-ceph project uses mergify, so manually force pushing can invalidate existing reviews.
You can request a rebase from mergify by creating a comment like:
```
@Mergifyio rebase
```
mergify[bot]: > rebase

#### ☑️ Nothing to do

<details>

- [X] `-closed` [:pushpin: rebase requirement]
- [ ] `#commits-behind>0` [:pushpin: rebase requirement]


</details>
<!--
DO NOT EDIT
-*- Mergify Payload -*-
{"command": "rebase", "conclusion": "neutral"}
-*- Mergify Payload End -*-
-->

ansiwen: > @ansiwen do you have any objections to making exceptions to the API stability policy for extremely simple and straightforward changes like this one? I am. However, before I approve and merge I want to give you a chance to reply. Thanks!

@phlogistonjohn no objections

ansiwen: @Mergifyio rebase
mergify[bot]: > rebase

#### ✅ Branch has been successfully rebased



<!--
DO NOT EDIT
-*- Mergify Payload -*-
{"command": "rebase", "conclusion": "success"}
-*- Mergify Payload End -*-
-->


Patch:
diff --git a/docs/api-status.json b/docs/api-status.json
index a5baa7b..a6128cd 100644
--- a/docs/api-status.json
+++ b/docs/api-status.json
@@ -1407,6 +1407,10 @@
         "name": "Image.GetId",
         "comment": "GetId returns the internal image ID string.\n\nImplements:\n int rbd_get_id(rbd_image_t image, char *id, size_t id_len);\n"
       },
+      {
+        "name": "Image.GetName",
+        "comment": "GetName returns the image name."
+      },
       {
         "name": "Image.SetSnapshot",
         "comment": "SetSnapshot updates the rbd image (not the Snapshot) such that the snapshot\nis the source of readable data.\n\nImplements:\n int rbd_snap_set(rbd_image_t image, const char *snapname);\n"
diff --git a/rbd/rbd.go b/rbd/rbd.go
index 7d5b1ce..e7cd6c7 100644
--- a/rbd/rbd.go
+++ b/rbd/rbd.go
@@ -951,6 +951,11 @@ func (image *Image) GetId() (string, error) {
 
 }
 
+// GetName returns the image name.
+func (image *Image) GetName() string {
+	return image.name
+}
+
 // SetSnapshot updates the rbd image (not the Snapshot) such that the snapshot
 // is the source of readable data.
 //


Test patch:
diff --git a/rbd/rbd_test.go b/rbd/rbd_test.go
index 6621637..7ab2e38 100644
--- a/rbd/rbd_test.go
+++ b/rbd/rbd_test.go
@@ -1641,6 +1641,14 @@ func TestGetId(t *testing.T) {
 	conn.Shutdown()
 }
 
+func TestGetName(t *testing.T) {
+	image := Image{
+		name: "testImg",
+	}
+	imgName := image.GetName()
+	assert.Equal(t, image.name, imgName)
+}
+
 func TestOpenImageById(t *testing.T) {
 	conn := radosConnect(t)