Skip to content

Commit

Permalink
feat: add volume format property (#397) [Backport release-1.x] (#444)
Browse files Browse the repository at this point in the history
This property was previously missing, although it was already used in
VolumeCreateOpts. It's now a string pointer with common values (ext4 and
xfs) available as string constants.

(cherry picked from commit c0940af)

BEGIN_COMMIT_OVERRIDE
feat: add volume format property
END_COMMIT_OVERRIDE
  • Loading branch information
phm07 authored May 22, 2024
1 parent c1aa180 commit 5ff15f8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions hcloud/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ func VolumeFromSchema(s schema.Volume) *Volume {
Name: s.Name,
Location: LocationFromSchema(s.Location),
Size: s.Size,
Format: s.Format,
Status: VolumeStatus(s.Status),
LinuxDevice: s.LinuxDevice,
Protection: VolumeProtection{
Expand Down
1 change: 1 addition & 0 deletions hcloud/schema/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Volume struct {
Status string `json:"status"`
Location Location `json:"location"`
Size int `json:"size"`
Format *string `json:"format"`
Protection VolumeProtection `json:"protection"`
Labels map[string]string `json:"labels"`
LinuxDevice string `json:"linux_device"`
Expand Down
4 changes: 4 additions & 0 deletions hcloud/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ func TestVolumeFromSchema(t *testing.T) {
"name": "db-storage",
"status": "creating",
"server": 2,
"format": "xfs",
"location": {
"id": 1,
"name": "fsn1",
Expand Down Expand Up @@ -1277,6 +1278,9 @@ func TestVolumeFromSchema(t *testing.T) {
if volume.Server != nil && volume.Server.ID != 2 {
t.Errorf("unexpected server ID: %v", volume.Server.ID)
}
if volume.Format == nil || *volume.Format != "xfs" {
t.Errorf("unexpected format: %v", volume.Format)
}
if volume.Location == nil || volume.Location.ID != 1 {
t.Errorf("unexpected location: %v", volume.Location)
}
Expand Down
6 changes: 6 additions & 0 deletions hcloud/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ type Volume struct {
Server *Server
Location *Location
Size int
Format *string
Protection VolumeProtection
Labels map[string]string
LinuxDevice string
Created time.Time
}

const (
VolumeFormatExt4 = "ext4"
VolumeFormatXFS = "xfs"
)

// VolumeProtection represents the protection level of a volume.
type VolumeProtection struct {
Delete bool
Expand Down

0 comments on commit 5ff15f8

Please sign in to comment.