-
Notifications
You must be signed in to change notification settings - Fork 6
/
plans.go
76 lines (65 loc) · 2.03 KB
/
plans.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package database
import (
"sort"
"github.com/UpCloudLtd/upcloud-cli/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/internal/output"
"github.com/UpCloudLtd/upcloud-go-api/v4/upcloud/request"
)
// PlansCommand creates the "database plans" command
func PlansCommand() commands.Command {
return &plansCommand{
BaseCommand: commands.New("plans", "List available plans for given database type", "upctl database plans pg", "upctl database plans mysql"),
}
}
type plansCommand struct {
*commands.BaseCommand
}
// Execute implements commands.MultipleArgumentCommand
func (s *plansCommand) Execute(exec commands.Executor, serviceType string) (output.Output, error) {
svc := exec.All()
dbType, err := svc.GetManagedDatabaseServiceType(&request.GetManagedDatabaseServiceTypeRequest{Type: serviceType})
if err != nil {
return nil, err
}
plans := dbType.ServicePlans
sort.Slice(plans, func(i, j int) bool {
if plans[i].NodeCount != plans[j].NodeCount {
return plans[i].NodeCount < plans[j].NodeCount
}
if plans[i].CoreNumber != plans[j].CoreNumber {
return plans[i].CoreNumber < plans[j].CoreNumber
}
if plans[i].MemoryAmount != plans[j].MemoryAmount {
return plans[i].MemoryAmount < plans[j].MemoryAmount
}
return plans[i].StorageSize < plans[j].StorageSize
})
rows := []output.TableRow{}
for _, plan := range plans {
rows = append(rows, output.TableRow{
plan.Plan,
plan.NodeCount,
plan.CoreNumber,
plan.MemoryAmount / 1024,
plan.StorageSize / 1024,
plan.BackupConfig.Interval,
plan.BackupConfig.MaxCount,
plan.BackupConfig.RecoveryMode,
})
}
return output.MarshaledWithHumanOutput{
Value: plans,
Output: output.Table{
Columns: []output.TableColumn{
{Key: "plan", Header: "Plan"},
{Key: "nodes", Header: "Nodes"},
{Key: "cores", Header: "Cores"},
{Key: "memory", Header: "Memory (GB)"},
{Key: "storage", Header: "Storage (GB)"},
{Key: "bu_interval", Header: "Backup interval"},
{Key: "bu_max_count", Header: "Max backup count"},
},
Rows: rows,
},
}, nil
}