-
Notifications
You must be signed in to change notification settings - Fork 20
/
limits.go
83 lines (69 loc) · 2.19 KB
/
limits.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
77
78
79
80
81
82
83
package cmd
import (
"fmt"
"strings"
"github.com/spf13/cobra"
)
const (
limitComputeInstances = "instance"
limitDatabases = "database"
limitElasticIPs = "elastic-ip"
limitIAMAPIKeys = "iam-key"
limitInstanceGPUs = "gpu"
limitInstanceSnapshots = "snapshot"
limitInstanceTemplates = "template"
limitNLB = "network-load-balancer"
limitPrivateNetworks = "private-network"
limitSKSClusters = "sks-cluster"
limitSOSBuckets = "bucket"
)
type LimitsItemOutput struct {
Resource string `json:"resource"`
Used int64 `json:"used"`
Max int64 `json:"max"`
}
type LimitsOutput []LimitsItemOutput
func (o *LimitsOutput) toJSON() { outputJSON(o) }
func (o *LimitsOutput) toText() { outputText(o) }
func (o *LimitsOutput) toTable() { outputTable(o) }
var limitsCmd = &cobra.Command{
Use: "limits",
Short: "Current account limits",
Long: fmt.Sprintf(`This command lists the safety limits currently enforced on your account.
Supported output template annotations: %s`,
strings.Join(outputterTemplateAnnotations(&LimitsOutput{}), ", ")),
RunE: func(cmd *cobra.Command, args []string) error {
resourceLimitLabels := map[string]string{
limitComputeInstances: "Compute instances",
limitDatabases: "Databases",
limitElasticIPs: "Elastic IP addresses",
limitIAMAPIKeys: "IAM API keys",
limitInstanceGPUs: "Compute instance GPUs",
limitInstanceSnapshots: "Compute instance snapshots",
limitInstanceTemplates: "Compute instance templates",
limitNLB: "Network Load Balancers",
limitPrivateNetworks: "Private networks",
limitSKSClusters: "SKS clusters",
limitSOSBuckets: "SOS buckets",
}
out := LimitsOutput{}
quotas, err := cs.ListQuotas(gContext, gCurrentAccount.DefaultZone)
if err != nil {
return err
}
for _, quota := range quotas {
if _, ok := resourceLimitLabels[*quota.Resource]; !ok {
continue
}
out = append(out, LimitsItemOutput{
Resource: resourceLimitLabels[*quota.Resource],
Used: *quota.Usage,
Max: *quota.Limit,
})
}
return output(&out, nil)
},
}
func init() {
RootCmd.AddCommand(limitsCmd)
}