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, cmd *cobra.Command, serverType *hcloud.ServerType) error { cmd.Printf("ID:\t\t\t%d\n", serverType.ID) cmd.Printf("Name:\t\t\t%s\n", serverType.Name) cmd.Printf("Description:\t\t%s\n", serverType.Description) cmd.Printf("Category:\t\t%s\n", serverType.Category) cmd.Printf("Cores:\t\t\t%d\n", serverType.Cores) cmd.Printf("CPU Type:\t\t%s\n", serverType.CPUType) cmd.Printf("Architecture:\t\t%s\n", serverType.Architecture) cmd.Printf("Memory:\t\t\t%.1f GB\n", serverType.Memory) cmd.Printf("Disk:\t\t\t%d GB\n", serverType.Disk) cmd.Printf("Storage Type:\t\t%s\n", serverType.StorageType) pricings, err := fullPricingInfo(s, serverType) if err != nil { cmd.PrintErrf("failed to get prices for Server Type: %v", err) } locations := joinLocationInfo(serverType, pricings) cmd.Printf("Locations:\n") for _, info := range locations { cmd.Printf(" - Location:\t\t%s\n", info.Location.Name) if deprecationText := util.DescribeDeprecation(info); deprecationText != "" { cmd.Print(util.PrefixLines(deprecationText, " ")) } cmd.Printf(" Pricing:\n") cmd.Printf(" Hourly:\t\t%s\n", util.GrossPrice(info.Pricing.Hourly)) cmd.Printf(" Monthly:\t\t%s\n", util.GrossPrice(info.Pricing.Monthly)) cmd.Printf(" Included Traffic:\t%s\n", humanize.IBytes(info.Pricing.IncludedTraffic)) cmd.Printf(" Additional Traffic:\t%s per TB\n", util.GrossPrice(info.Pricing.PerTBTraffic)) cmd.Printf("\n") } 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, _ hcapi2.Client) { t. AddAllowedFields(hcloud.ServerType{}). AddFieldAlias("storagetype", "storage type"). AddFieldFn("memory", output.FieldFn(func(obj interface{}) string { serverType := obj.(*hcloud.ServerType) return fmt.Sprintf("%.1f GB", serverType.Memory) })). AddFieldFn("disk", output.FieldFn(func(obj interface{}) string { serverType := obj.(*hcloud.ServerType) return fmt.Sprintf("%d GB", serverType.Disk) })). AddFieldFn("traffic", func(interface{}) string { return "-" }). AddFieldFn("deprecated", func(obj interface{}) string { serverType := obj.(*hcloud.ServerType) 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 ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.