Skip to content

Commit 4957ed0

Browse files
authored
fix: do not print server types locations that are unavailable (deprecation) (#1369)
We do not want to list locations that are now unavailable (deprecation period ended). To retrieve deprecation information, the deprecation column can be used. Server types still in the deprecation period are still listed as part of the location column. ``` ID NAME CORES CPU TYPE ARCHITECTURE MEMORY DISK LOCATION 22 cpx11 2 shared x86 2.0 GB 40 GB ash,hil 23 cpx21 3 shared x86 4.0 GB 80 GB ash,hil 24 cpx31 4 shared x86 8.0 GB 160 GB ash,hil 25 cpx41 8 shared x86 16.0 GB 240 GB ash,hil 26 cpx51 16 shared x86 32.0 GB 360 GB ash,hil 45 cax11 2 shared arm 4.0 GB 40 GB fsn1,nbg1,hel1 93 cax21 4 shared arm 8.0 GB 80 GB fsn1,nbg1,hel1 94 cax31 8 shared arm 16.0 GB 160 GB fsn1,nbg1,hel1 95 cax41 16 shared arm 32.0 GB 320 GB fsn1,nbg1,hel1 96 ccx13 2 dedicated x86 8.0 GB 80 GB fsn1,nbg1,hel1,ash,hil,sin 97 ccx23 4 dedicated x86 16.0 GB 160 GB fsn1,nbg1,hel1,ash,hil,sin 98 ccx33 8 dedicated x86 32.0 GB 240 GB fsn1,nbg1,hel1,ash,hil,sin 99 ccx43 16 dedicated x86 64.0 GB 360 GB fsn1,nbg1,hel1,ash,hil,sin 100 ccx53 32 dedicated x86 128.0 GB 600 GB fsn1,nbg1,hel1,ash,hil,sin 101 ccx63 48 dedicated x86 192.0 GB 960 GB fsn1,nbg1,hel1,ash,hil,sin 108 cpx12 1 shared x86 2.0 GB 40 GB sin 109 cpx22 2 shared x86 4.0 GB 80 GB fsn1,nbg1,hel1,sin 110 cpx32 4 shared x86 8.0 GB 160 GB fsn1,nbg1,hel1,sin 111 cpx42 8 shared x86 16.0 GB 320 GB fsn1,nbg1,hel1,sin 112 cpx52 12 shared x86 24.0 GB 480 GB fsn1,nbg1,hel1,sin 113 cpx62 16 shared x86 32.0 GB 640 GB fsn1,nbg1,hel1,sin 114 cx23 2 shared x86 4.0 GB 40 GB fsn1,nbg1,hel1 115 cx33 4 shared x86 8.0 GB 80 GB fsn1,nbg1,hel1 116 cx43 8 shared x86 16.0 GB 160 GB fsn1,nbg1,hel1 117 cx53 16 shared x86 32.0 GB 320 GB fsn1,nbg1,hel1 ``` ``` NAME LOCATION DEPRECATED cpx11 ash,hil fsn1=2026-01-01,nbg1=2026-01-01,hel1=2026-01-01,sin=2026-01-01 cpx21 ash,hil fsn1=2026-01-01,nbg1=2026-01-01,hel1=2026-01-01,sin=2026-01-01 cpx31 ash,hil fsn1=2026-01-01,nbg1=2026-01-01,hel1=2026-01-01,sin=2026-01-01 cpx41 ash,hil fsn1=2026-01-01,nbg1=2026-01-01,hel1=2026-01-01,sin=2026-01-01 cpx51 ash,hil fsn1=2026-01-01,nbg1=2026-01-01,hel1=2026-01-01,sin=2026-01-01 cax11 fsn1,nbg1,hel1 - cax21 fsn1,nbg1,hel1 - cax31 fsn1,nbg1,hel1 - cax41 fsn1,nbg1,hel1 - ccx13 fsn1,nbg1,hel1,ash,hil,sin - ccx23 fsn1,nbg1,hel1,ash,hil,sin - ccx33 fsn1,nbg1,hel1,ash,hil,sin - ccx43 fsn1,nbg1,hel1,ash,hil,sin - ccx53 fsn1,nbg1,hel1,ash,hil,sin - ccx63 fsn1,nbg1,hel1,ash,hil,sin - cpx12 sin - cpx22 fsn1,nbg1,hel1,sin - cpx32 fsn1,nbg1,hel1,sin - cpx42 fsn1,nbg1,hel1,sin - cpx52 fsn1,nbg1,hel1,sin - cpx62 fsn1,nbg1,hel1,sin - cx23 fsn1,nbg1,hel1 - cx33 fsn1,nbg1,hel1 - cx43 fsn1,nbg1,hel1 - cx53 fsn1,nbg1,hel1 - ```
1 parent d96cd20 commit 4957ed0

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

internal/cmd/servertype/list.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package servertype
22

33
import (
44
"fmt"
5+
"slices"
56
"strings"
67
"time"
78

@@ -34,11 +35,17 @@ var ListCmd = &base.ListCmd[*hcloud.ServerType, schema.ServerType]{
3435
t.
3536
AddAllowedFields(&hcloud.ServerType{}).
3637
AddFieldFn("location", func(serverType *hcloud.ServerType) string {
37-
locationNames := sliceutil.Transform(
38-
serverType.Locations,
39-
func(l hcloud.ServerTypeLocation) string { return l.Location.Name },
38+
now := time.Now()
39+
return strings.Join(
40+
sliceutil.Transform(
41+
slices.DeleteFunc(
42+
slices.Clone(serverType.Locations),
43+
func(l hcloud.ServerTypeLocation) bool { return l.IsDeprecated() && l.UnavailableAfter().Before(now) },
44+
),
45+
func(l hcloud.ServerTypeLocation) string { return l.Location.Name },
46+
),
47+
",",
4048
)
41-
return strings.Join(locationNames, ",")
4249
}).
4350
AddFieldAlias("storagetype", "storage type").
4451
AddFieldFn("memory", func(serverType *hcloud.ServerType) string {

internal/cmd/servertype/list_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ func TestList(t *testing.T) {
2121

2222
cmd := servertype.ListCmd.CobraCommand(fx.State())
2323

24+
serverTypeDeprecation := hcloud.DeprecatableResource{Deprecation: &hcloud.DeprecationInfo{
25+
Announced: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC),
26+
UnavailableAfter: time.Date(2025, 4, 1, 0, 0, 0, 0, time.UTC),
27+
}}
28+
2429
fx.ExpectEnsureToken()
2530
fx.Client.ServerTypeClient.EXPECT().
2631
AllWithOpts(
@@ -41,7 +46,7 @@ func TestList(t *testing.T) {
4146
Disk: 80,
4247
StorageType: hcloud.StorageTypeLocal,
4348
Locations: []hcloud.ServerTypeLocation{
44-
{Location: &hcloud.Location{ID: 1, Name: "fsn1"}},
49+
{Location: &hcloud.Location{ID: 1, Name: "fsn1"}, DeprecatableResource: serverTypeDeprecation},
4550
{Location: &hcloud.Location{ID: 2, Name: "nbg1"}},
4651
{Location: &hcloud.Location{ID: 3, Name: "hel1"}},
4752
},
@@ -51,7 +56,7 @@ func TestList(t *testing.T) {
5156
out, errOut, err := fx.Run(cmd, []string{})
5257

5358
expOut := `ID NAME CORES CPU TYPE ARCHITECTURE MEMORY DISK LOCATION
54-
123 test 2 shared arm 8.0 GB 80 GB fsn1,nbg1,hel1
59+
123 test 2 shared arm 8.0 GB 80 GB nbg1,hel1
5560
`
5661

5762
require.NoError(t, err)

0 commit comments

Comments
 (0)