servertype

package
v1.58.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DescribeCmd = base.DescribeCmd[*hcloud.ServerType]{
	ResourceNameSingular: "Server Type",
	ShortDescription:     "Describe a Server Type",
	NameSuggestions:      func(c hcapi2.Client) func() []string { return c.ServerType().Names },
	Fetch: func(s state.State, _ *cobra.Command, idOrName string) (*hcloud.ServerType, any, error) {
		st, _, err := s.Client().ServerType().Get(s, idOrName)
		if err != nil {
			return nil, nil, err
		}
		return st, hcloud.SchemaFromServerType(st), nil
	},
	PrintText: func(s state.State, _ *cobra.Command, out io.Writer, serverType *hcloud.ServerType) error {
		description, err := DescribeServerType(s, serverType, false)
		if err != nil {
			return err
		}
		fmt.Fprint(out, description)
		return nil
	},
}
View Source
var ListCmd = &base.ListCmd[*hcloud.ServerType, schema.ServerType]{
	ResourceNamePlural: "Server Types",
	JSONKeyGetByName:   "server_types",
	DefaultColumns:     []string{"id", "name", "cores", "cpu_type", "architecture", "memory", "disk", "storage_type"},
	SortOption:         nil,

	Fetch: func(s state.State, _ *pflag.FlagSet, listOpts hcloud.ListOpts, sorts []string) ([]*hcloud.ServerType, error) {
		opts := hcloud.ServerTypeListOpts{ListOpts: listOpts}
		if len(sorts) > 0 {
			opts.Sort = sorts
		}
		return s.Client().ServerType().AllWithOpts(s, opts)
	},

	OutputTable: func(t *output.Table[*hcloud.ServerType], _ hcapi2.Client) {
		t.
			AddAllowedFields(&hcloud.ServerType{}).
			AddFieldAlias("storagetype", "storage type").
			AddFieldFn("memory", func(serverType *hcloud.ServerType) string {
				return fmt.Sprintf("%.1f GB", serverType.Memory)
			}).
			AddFieldFn("disk", func(serverType *hcloud.ServerType) string {
				return fmt.Sprintf("%d GB", serverType.Disk)
			}).
			AddFieldFn("traffic", func(*hcloud.ServerType) string {

				return "-"
			}).
			AddFieldFn("deprecated", func(serverType *hcloud.ServerType) string {
				deprecatedInfos := make([]string, 0, len(serverType.Locations))
				for _, loc := range serverType.Locations {
					if loc.IsDeprecated() {
						deprecatedInfos = append(
							deprecatedInfos,
							fmt.Sprintf("%s=%s", loc.Location.Name, loc.UnavailableAfter().Local().Format(time.DateOnly)),
						)
					}
				}

				if len(deprecatedInfos) > 0 {
					return strings.Join(deprecatedInfos, ",")
				}
				return "-"
			})
	},

	Schema: hcloud.SchemaFromServerType,
}

Functions

func DescribeServerType added in v1.56.0

func DescribeServerType(s state.State, serverType *hcloud.ServerType, short bool) (string, error)

func NewCommand

func NewCommand(s state.State) *cobra.Command

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL