Skip to content
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
2 changes: 2 additions & 0 deletions docs/reference/manual/hcloud_server-type_list.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions internal/cmd/datacenter/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func DescribeDatacenter(client hcapi2.Client, datacenter *hcloud.Datacenter, sho
fmt.Fprintf(&sb, "Location:\n")
fmt.Fprint(&sb, util.PrefixLines(location.DescribeLocation(datacenter.Location), " "))

// datacenter.ServerTypes will not be populated anymore after 2026-10-01.
if dst := datacenter.ServerTypes; dst.Available == nil && dst.Supported == nil && dst.AvailableForMigration == nil {
return sb.String()
}

type ServerTypeStatus struct {
ID int64
Available bool
Expand Down
3 changes: 0 additions & 3 deletions internal/cmd/datacenter/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ Location:
City:
Latitude: 0.000000
Longitude: 0.000000

Server Types:
No Server Types
`

require.NoError(t, err)
Expand Down
7 changes: 4 additions & 3 deletions internal/cmd/servertype/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func DescribeServerType(s state.State, serverType *hcloud.ServerType, short bool
for _, info := range locations {

fmt.Fprintf(&sb, " - Location:\t%s\n", info.Location.Name)
fmt.Fprintf(&sb, " Available:\t%s\n", util.YesNo(info.Available))
fmt.Fprintf(&sb, " Recommended:\t%s\n", util.YesNo(info.Recommended))

if deprecationText := util.DescribeDeprecation(info); deprecationText != "" {
fmt.Fprint(&sb, util.PrefixLines(deprecationText, " "))
Expand Down Expand Up @@ -97,16 +99,15 @@ func fullPricingInfo(s state.State, serverType *hcloud.ServerType) ([]hcloud.Ser
}

type locationInfo struct {
Location *hcloud.Location
hcloud.DeprecatableResource
*hcloud.ServerTypeLocation
Pricing hcloud.ServerTypeLocationPricing
}

func joinLocationInfo(serverType *hcloud.ServerType, pricings []hcloud.ServerTypeLocationPricing) []locationInfo {
locations := make([]locationInfo, 0, len(serverType.Locations))

for _, location := range serverType.Locations {
info := locationInfo{Location: location.Location, DeprecatableResource: location.DeprecatableResource}
info := locationInfo{ServerTypeLocation: &location}

for _, pricing := range pricings {
// Pricing endpoint only sets the location name
Expand Down
6 changes: 5 additions & 1 deletion internal/cmd/servertype/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func TestDescribe(t *testing.T) {
{
Location: &hcloud.Location{Name: "fsn1"},
DeprecatableResource: deprecation,
Available: true,
Recommended: false,
},
},
}, nil, nil)
Expand Down Expand Up @@ -112,7 +114,9 @@ Disk: 40 GB
Storage Type: local

Locations:
- Location: fsn1
- Location: fsn1
Available: yes
Recommended: no
Deprecation:
Announced: %s (%s)
Unavailable After: %s (%s)
Expand Down
36 changes: 24 additions & 12 deletions internal/cmd/servertype/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package servertype

import (
"fmt"
"slices"
"strings"
"time"

Expand All @@ -13,7 +12,6 @@ import (
"github.com/hetznercloud/cli/internal/hcapi2"
"github.com/hetznercloud/cli/internal/state"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud/exp/kit/sliceutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud/schema"
)

Expand All @@ -36,16 +34,20 @@ var ListCmd = &base.ListCmd[*hcloud.ServerType, schema.ServerType]{
AddAllowedFields(&hcloud.ServerType{}).
AddFieldFn("location", func(serverType *hcloud.ServerType) string {
now := time.Now()
return strings.Join(
sliceutil.Transform(
slices.DeleteFunc(
slices.Clone(serverType.Locations),
func(l hcloud.ServerTypeLocation) bool { return l.IsDeprecated() && l.UnavailableAfter().Before(now) },
),
func(l hcloud.ServerTypeLocation) string { return l.Location.Name },
),
",",
)
return listLocationNames(serverType, func(l hcloud.ServerTypeLocation) bool {
return l.IsDeprecated() && l.UnavailableAfter().Before(now)
})
}).
AddFieldFn("location_available", func(serverType *hcloud.ServerType) string {
now := time.Now()
return listLocationNames(serverType, func(l hcloud.ServerTypeLocation) bool {
return (l.IsDeprecated() && l.UnavailableAfter().Before(now)) || !l.Available
})
}).
AddFieldFn("location_recommended", func(serverType *hcloud.ServerType) string {
return listLocationNames(serverType, func(l hcloud.ServerTypeLocation) bool {
return !l.Recommended
})
}).
AddFieldAlias("storagetype", "storage type").
AddFieldFn("memory", func(serverType *hcloud.ServerType) string {
Expand Down Expand Up @@ -79,3 +81,13 @@ var ListCmd = &base.ListCmd[*hcloud.ServerType, schema.ServerType]{

Schema: hcloud.SchemaFromServerType,
}

func listLocationNames(serverType *hcloud.ServerType, del func(hcloud.ServerTypeLocation) bool) string {
var locationNames []string
for _, l := range serverType.Locations {
if !del(l) {
locationNames = append(locationNames, l.Location.Name)
}
}
return strings.Join(locationNames, ", ")
}
13 changes: 7 additions & 6 deletions internal/cmd/servertype/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ func TestList(t *testing.T) {
Disk: 80,
StorageType: hcloud.StorageTypeLocal,
Locations: []hcloud.ServerTypeLocation{
{Location: &hcloud.Location{ID: 1, Name: "fsn1"}, DeprecatableResource: serverTypeDeprecation},
{Location: &hcloud.Location{ID: 2, Name: "nbg1"}},
{Location: &hcloud.Location{ID: 3, Name: "hel1"}},
{Location: &hcloud.Location{ID: 1, Name: "fsn1"}, Available: false, Recommended: false,
DeprecatableResource: serverTypeDeprecation},
{Location: &hcloud.Location{ID: 2, Name: "nbg1"}, Available: true, Recommended: false},
{Location: &hcloud.Location{ID: 3, Name: "hel1"}, Available: true, Recommended: true},
},
},
}, nil)

out, errOut, err := fx.Run(cmd, []string{})
out, errOut, err := fx.Run(cmd, []string{"-o=columns=id,name,cores,cpu_type,architecture,memory,disk,location,location_available,location_recommended"})

expOut := `ID NAME CORES CPU TYPE ARCHITECTURE MEMORY DISK LOCATION
123 test 2 shared arm 8.0 GB 80 GB nbg1,hel1
expOut := `ID NAME CORES CPU TYPE ARCHITECTURE MEMORY DISK LOCATION LOCATION AVAILABLE LOCATION RECOMMENDED
123 test 2 shared arm 8.0 GB 80 GB nbg1, hel1 nbg1, hel1 hel1
`

require.NoError(t, err)
Expand Down
Loading