-
Notifications
You must be signed in to change notification settings - Fork 20
/
limits.go
92 lines (76 loc) · 2.66 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
84
85
86
87
88
89
90
91
92
package cmd
import (
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
exoapi "github.com/exoscale/egoscale/v2/api"
)
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"
limitBlockStorageVolumes = "block-storage-volume"
)
type LimitsItemOutput struct {
Resource string `json:"resource"`
Used int64 `json:"used"`
Max int64 `json:"max"`
}
type LimitsOutput []LimitsItemOutput
func (o *LimitsOutput) ToJSON() { output.JSON(o) }
func (o *LimitsOutput) ToText() { output.Text(o) }
func (o *LimitsOutput) ToTable() { output.Table(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(output.TemplateAnnotations(&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",
limitBlockStorageVolumes: "Block Storage Volumes",
}
out := LimitsOutput{}
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, account.CurrentAccount.DefaultZone))
quotas, err := globalstate.EgoscaleClient.ListQuotas(ctx, account.CurrentAccount.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 printOutput(&out, nil)
},
}
func init() {
RootCmd.AddCommand(limitsCmd)
}