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 GetStoragePoolVolumes api to get all volumes connected to given s… #111

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,18 @@ func (c *Client) GetSnapshotPolicy(
sps = append(sps, sp)
return sps, nil
}

// GetStoragePoolVolumes returns list of volumes connected to storage pool Storagepool by ID
func (c *Client) GetStoragePoolVolumes(id string) ([]*types.Volume, error) {
defer TimeSpent("GetStoragePoolByID", time.Now())

path := fmt.Sprintf("/api/instances/StoragePool::%s/relationships/Volume", id)
var storagepoolVolumes []*types.Volume
err := c.getJSONWithRetry(
http.MethodGet, path, nil, &storagepoolVolumes)
if err != nil {
return nil, err
}

return storagepoolVolumes, err
}
26 changes: 26 additions & 0 deletions inttests/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,3 +779,29 @@ func TestSetCompressionMethod(t *testing.T) {
err = deleteVolume(t, volID)
assert.Nil(t, err)
}

func TestGetStoragePoolVolumes(t *testing.T) {
name := fmt.Sprintf("%s-%s", testPrefix, "instanceCreated")

poolName := getStoragePoolName(t)
assert.NotNil(t, poolName)

pool := getStoragePool(t)
size := fmt.Sprintf("%d", defaultVolumeSize)

volParams := siotypes.VolumeParam{
VolumeSizeInKb: size,
VolumeType: "ThinProvisioned",
Name: name,
}

volResp, err := C.CreateVolume(&volParams, poolName, "")
assert.Nil(t, err)
assert.NotNil(t, volResp)

volumes, err := C.GetStoragePoolVolumes(pool.StoragePool.ID)
assert.Nil(t, err)
assert.NotNil(t, volumes)

deleteVolume(t, volResp.ID)
}