Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DescribeCmd = base.DescribeCmd{ ResourceNameSingular: "datacenter", ShortDescription: "Describe an datacenter", JSONKeyGetByID: "datacenter", JSONKeyGetByName: "datacenters", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Datacenter().Names }, Fetch: func(ctx context.Context, client hcapi2.Client, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { dc, _, err := client.Datacenter().Get(ctx, idOrName) if err != nil { return nil, nil, err } return dc, hcloud.SchemaFromDatacenter(dc), nil }, PrintText: func(ctx context.Context, client hcapi2.Client, cmd *cobra.Command, resource interface{}) error { datacenter := resource.(*hcloud.Datacenter) cmd.Printf("ID:\t\t%d\n", datacenter.ID) cmd.Printf("Name:\t\t%s\n", datacenter.Name) cmd.Printf("Description:\t%s\n", datacenter.Description) cmd.Printf("Location:\n") cmd.Printf(" Name:\t\t%s\n", datacenter.Location.Name) cmd.Printf(" Description:\t%s\n", datacenter.Location.Description) cmd.Printf(" Country:\t%s\n", datacenter.Location.Country) cmd.Printf(" City:\t\t%s\n", datacenter.Location.City) cmd.Printf(" Latitude:\t%f\n", datacenter.Location.Latitude) cmd.Printf(" Longitude:\t%f\n", datacenter.Location.Longitude) cmd.Printf("Server Types:\n") printServerTypes := func(list []*hcloud.ServerType) { for _, t := range list { cmd.Printf(" - ID:\t\t %d\n", t.ID) cmd.Printf(" Name:\t %s\n", client.ServerType().ServerTypeName(t.ID)) cmd.Printf(" Description: %s\n", client.ServerType().ServerTypeDescription(t.ID)) } } cmd.Printf(" Available:\n") if len(datacenter.ServerTypes.Available) > 0 { printServerTypes(datacenter.ServerTypes.Available) } else { cmd.Printf(" No available server types\n") } cmd.Printf(" Supported:\n") if len(datacenter.ServerTypes.Supported) > 0 { printServerTypes(datacenter.ServerTypes.Supported) } else { cmd.Printf(" No supported server types\n") } return nil }, }
View Source
var ListCmd = base.ListCmd{ ResourceNamePlural: "Datacenters", JSONKeyGetByName: "datacenters", DefaultColumns: []string{"id", "name", "description", "location"}, Fetch: func(ctx context.Context, client hcapi2.Client, _ *pflag.FlagSet, listOpts hcloud.ListOpts, sorts []string) ([]interface{}, error) { opts := hcloud.DatacenterListOpts{ListOpts: listOpts} if len(sorts) > 0 { opts.Sort = sorts } datacenters, err := client.Datacenter().AllWithOpts(ctx, opts) var resources []interface{} for _, n := range datacenters { resources = append(resources, n) } return resources, err }, OutputTable: func(_ hcapi2.Client) *output.Table { return output.NewTable(). AddAllowedFields(hcloud.Datacenter{}). AddFieldFn("location", output.FieldFn(func(obj interface{}) string { datacenter := obj.(*hcloud.Datacenter) return datacenter.Location.Name })) }, Schema: func(resources []interface{}) interface{} { dcSchemas := make([]schema.Datacenter, 0, len(resources)) for _, resource := range resources { dc := resource.(*hcloud.Datacenter) dcSchemas = append(dcSchemas, hcloud.SchemaFromDatacenter(dc)) } return dcSchemas }, }
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.