/
list.go
54 lines (47 loc) · 1.56 KB
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package kubernetes
import (
"github.com/UpCloudLtd/upcloud-cli/v2/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/format"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/output"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/ui"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud/request"
)
// ListCommand creates the "kubernetes list" command
func ListCommand() commands.Command {
return &listCommand{
BaseCommand: commands.New("list", "List current Kubernetes clusters", "upctl kubernetes list"),
}
}
type listCommand struct {
*commands.BaseCommand
}
// ExecuteWithoutArguments implements commands.NoArgumentCommand
func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) {
svc := exec.All()
clusters, err := svc.GetKubernetesClusters(exec.Context(), &request.GetKubernetesClustersRequest{})
if err != nil {
return nil, err
}
rows := []output.TableRow{}
for _, cluster := range clusters {
rows = append(rows, output.TableRow{
cluster.UUID,
cluster.Name,
cluster.Network,
cluster.NetworkCIDR,
cluster.Zone,
cluster.State,
})
}
return output.Table{
Columns: []output.TableColumn{
{Key: "uuid", Header: "UUID", Colour: ui.DefaultUUUIDColours},
{Key: "name", Header: "Name"},
{Key: "network", Header: "Network UUID", Colour: ui.DefaultUUUIDColours},
{Key: "network_cidr", Header: "Network CIDR", Colour: ui.DefaultAddressColours},
{Key: "zone", Header: "Zone"},
{Key: "state", Header: "Operational state", Format: format.KubernetesClusterState},
},
Rows: rows,
}, nil
}