diff --git a/.stats.yml b/.stats.yml index 88125fb..52b47b0 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 21 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nirvana-labs%2Fnirvana-32e801f2ca53603409f51b39c415f31f7d678f243df7659e16923f36b08eb343.yml +configured_endpoints: 22 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nirvana-labs%2Fnirvana-103a418ce8e7c594165303b86b52547fae832297c274951cb5025d917622fbc6.yml diff --git a/api.md b/api.md index dba02fb..740ce3a 100644 --- a/api.md +++ b/api.md @@ -82,11 +82,14 @@ Response Types: - volumes.StorageType - volumes.Volume +- volumes.VolumeKind +- volumes.VolumeListResponse Methods: - client.Volumes.New(ctx context.Context, body volumes.VolumeNewParams) (operations.Operation, error) - client.Volumes.Update(ctx context.Context, volumeID string, body volumes.VolumeUpdateParams) (operations.Operation, error) +- client.Volumes.List(ctx context.Context) (volumes.VolumeListResponse, error) - client.Volumes.Delete(ctx context.Context, volumeID string, body volumes.VolumeDeleteParams) (operations.Operation, error) - client.Volumes.Get(ctx context.Context, volumeID string) (volumes.Volume, error) diff --git a/volumes/volume.go b/volumes/volume.go index d884380..a761f9c 100644 --- a/volumes/volume.go +++ b/volumes/volume.go @@ -54,6 +54,14 @@ func (r *VolumeService) Update(ctx context.Context, volumeID string, body Volume return } +// List all volumes +func (r *VolumeService) List(ctx context.Context, opts ...option.RequestOption) (res *VolumeListResponse, err error) { + opts = append(r.Options[:], opts...) + path := "volumes" + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) + return +} + // Delete a Volume. Boot or data volumes can be deleted. func (r *VolumeService) Delete(ctx context.Context, volumeID string, body VolumeDeleteParams, opts ...option.RequestOption) (res *operations.Operation, err error) { opts = append(r.Options[:], opts...) @@ -97,7 +105,9 @@ func (r StorageType) IsKnown() bool { type Volume struct { ID string `json:"id,required"` CreatedAt string `json:"created_at,required"` - Size int64 `json:"size,required"` + // Volume kind. + Kind VolumeKind `json:"kind,required"` + Size int64 `json:"size,required"` // Storage type. Type StorageType `json:"type,required"` UpdatedAt string `json:"updated_at,required"` @@ -108,6 +118,7 @@ type Volume struct { type volumeJSON struct { ID apijson.Field CreatedAt apijson.Field + Kind apijson.Field Size apijson.Field Type apijson.Field UpdatedAt apijson.Field @@ -123,6 +134,43 @@ func (r volumeJSON) RawJSON() string { return r.raw } +// Volume kind. +type VolumeKind string + +const ( + VolumeKindBoot VolumeKind = "boot" + VolumeKindData VolumeKind = "data" +) + +func (r VolumeKind) IsKnown() bool { + switch r { + case VolumeKindBoot, VolumeKindData: + return true + } + return false +} + +type VolumeListResponse struct { + Items []Volume `json:"items,required"` + JSON volumeListResponseJSON `json:"-"` +} + +// volumeListResponseJSON contains the JSON metadata for the struct +// [VolumeListResponse] +type volumeListResponseJSON struct { + Items apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *VolumeListResponse) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r volumeListResponseJSON) RawJSON() string { + return r.raw +} + type VolumeNewParams struct { Size param.Field[int64] `json:"size,required"` VMID param.Field[string] `json:"vm_id,required"` diff --git a/volumes/volume_test.go b/volumes/volume_test.go index 434231e..f125456 100644 --- a/volumes/volume_test.go +++ b/volumes/volume_test.go @@ -69,6 +69,28 @@ func TestVolumeUpdate(t *testing.T) { } } +func TestVolumeList(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := nirvana.NewClient( + option.WithBaseURL(baseURL), + option.WithAuthToken("My Auth Token"), + ) + _, err := client.Volumes.List(context.TODO()) + if err != nil { + var apierr *nirvana.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + func TestVolumeDelete(t *testing.T) { baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {