diff --git a/client.go b/client.go index 4a59746..effe356 100644 --- a/client.go +++ b/client.go @@ -111,6 +111,7 @@ type Client interface { GetFsSnapshots(ctx context.Context) ([]FileSystem, error) GetFsSnapshot(ctx context.Context, snapID string) (FileSystem, error) CreateFsFromSnapshot(ctx context.Context, createParams *FsClone, snapID string) (CreateResponse, error) + GetFsByFilter(ctx context.Context, filter map[string]string) ([]FileSystem, error) CloneVolume(ctx context.Context, createParams *VolumeClone, volID string) (CreateResponse, error) ModifyVolume(ctx context.Context, modifyParams *VolumeModify, volID string) (EmptyResponse, error) ModifyFS(ctx context.Context, modifyParams *FSModify, volID string) (EmptyResponse, error) diff --git a/fs.go b/fs.go index 9857dc5..5bf9f8a 100644 --- a/fs.go +++ b/fs.go @@ -324,3 +324,29 @@ func (c *ClientIMPL) CloneFS(ctx context.Context, &resp) return resp, WrapErr(err) } + +func (c *ClientIMPL) GetFsByFilter(ctx context.Context, filter map[string]string) ([]FileSystem, error) { + var result []FileSystem + err := c.readPaginatedData(func(offset int) (api.RespMeta, error) { + var page []FileSystem + qp := getFSDefaultQueryParams(c) + for k, v := range filter { + qp.RawArg(k, v) + } + qp.Offset(offset).Limit(paginationDefaultPageSize) + meta, err := c.APIClient().Query( + ctx, + RequestConfig{ + Method: "GET", + Endpoint: fsURL, + QueryParams: qp, + }, + &page) + err = WrapErr(err) + if err == nil { + result = append(result, page...) + } + return meta, err + }) + return result, err +} diff --git a/fs_test.go b/fs_test.go index 3e5a2bb..9fcd364 100644 --- a/fs_test.go +++ b/fs_test.go @@ -257,3 +257,14 @@ func TestClientIMPL_CreateFsFromSnapshot(t *testing.T) { assert.Nil(t, err) assert.Equal(t, id, resp.ID) } + +func TestClientIMPL_GetFsByFilter(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + respData := fmt.Sprintf(`[{"id": "%s"}]`, fsID) + httpmock.RegisterResponder("GET", fsMockURL, + httpmock.NewStringResponder(200, respData)) + resp, err := C.GetFsByFilter(context.Background(), nil) + assert.Nil(t, err) + assert.Equal(t, fsID, resp[0].ID) +}