-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_quota_update.go
executable file
·154 lines (123 loc) · 5.08 KB
/
project_quota_update.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
Copyright © 2022 PlusServer GmbH
*/
package cmd
import (
"context"
"fmt"
"os"
"github.com/spf13/cobra"
)
var quotaCPU, quotaRAM, quotaInstances, quotaKeyPairs, quotaServerGroups, quotaServerGroupMembers, quotaVolumes, quotaGigabytes, quotaBackups, quotaBackupsgigabytes, quotaSnapshots, quotaVolumeGroups int
var quotaNetworks, quotaFloatingIPs, quotaPorts, quotaRBAC, quotaRouters, quotaSecurityGroups, quotaSecurityGroupRules, quotaSubnets int
// listCmd represents the list command
var updateQuotaCmd = &cobra.Command{
Use: "update",
Short: "Update the quotas of the specified project",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println("Please specify the id of the project")
os.Exit(1)
}
if len(args) > 1 {
fmt.Println("Please only specify the id of the project")
os.Exit(1)
}
psOsClient := fetchPsOpenStackClientOrDie()
ctx := context.Background()
resp, err := psOsClient.GetProjectQuota(ctx, args[0])
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
if quotaCPU != 0 {
resp.Compute.Cores = "aCPU
}
if quotaRAM != 0 {
resp.Compute.Ram = "aRAM
}
if quotaInstances != 0 {
resp.Compute.Instances = quotaInstances
}
if quotaKeyPairs != 0 {
resp.Compute.KeyPairs = quotaKeyPairs
}
if quotaServerGroups != 0 {
resp.Compute.ServerGroups = quotaServerGroups
}
if quotaServerGroupMembers != 0 {
resp.Compute.ServerGroupMembers = "aServerGroupMembers
}
if quotaVolumes != 0 {
resp.Volume.Volumes = quotaVolumes
}
if quotaGigabytes != 0 {
resp.Volume.Gigabytes = "aGigabytes
}
if quotaBackups != 0 {
resp.Volume.Backups = quotaBackups
}
if quotaBackupsgigabytes != 0 {
resp.Volume.BackupGigabytes = quotaBackupsgigabytes
}
if quotaSnapshots != 0 {
resp.Volume.Snapshots = "aSnapshots
}
if quotaVolumeGroups != 0 {
resp.Volume.Groups = "aVolumeGroups
}
if quotaNetworks != 0 {
resp.Network.Network = quotaNetworks
}
if quotaFloatingIPs != 0 {
resp.Network.Floatingip = "aFloatingIPs
}
if quotaPorts != 0 {
resp.Network.Port = "aPorts
}
if quotaRBAC != 0 {
resp.Network.RbacPolicy = "aRBAC
}
if quotaRouters != 0 {
resp.Network.Router = quotaRouters
}
if quotaSecurityGroups != 0 {
resp.Network.SecurityGroup = quotaSecurityGroups
}
if quotaSecurityGroupRules != 0 {
resp.Network.SecurityGroupRule = quotaSecurityGroupRules
}
if quotaSubnets != 0 {
resp.Network.Subnet = quotaSubnets
}
resp, err = psOsClient.UpdateProjectQuota(ctx, args[0], *resp)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
printQuota(*resp)
},
}
func init() {
quotaCmd.AddCommand(updateQuotaCmd)
updateQuotaCmd.Flags().IntVar("aCPU, "cpu", 0, "Update the number of CPUs the project can consume")
updateQuotaCmd.Flags().IntVar("aRAM, "ram", 0, "Update the gigabytes of RAM the project can consume")
updateQuotaCmd.Flags().IntVar("aInstances, "instances", 0, "Update the number of instaces the project can start")
updateQuotaCmd.Flags().IntVar("aKeyPairs, "keypair", 0, "Update the number of keypairs the project can create")
updateQuotaCmd.Flags().IntVar("aServerGroups, "servergroups", 0, "Update the number of server groups the project can create")
updateQuotaCmd.Flags().IntVar("aServerGroupMembers, "servergroupmembers", 0, "Update the number of members a server group can contain")
updateQuotaCmd.Flags().IntVar("aVolumes, "volumes", 0, "Update the number of volumes the project can create")
updateQuotaCmd.Flags().IntVar("aGigabytes, "gigabytes", 0, "Update the gigabytes the project can allocate")
updateQuotaCmd.Flags().IntVar("aBackups, "backups", 0, "Update the number of backups the project can create")
updateQuotaCmd.Flags().IntVar("aBackupsgigabytes, "backupgigabytes", 0, "Update the amount of storage backups can allocate")
updateQuotaCmd.Flags().IntVar("aSnapshots, "snapshots", 0, "Update the number of snapshots the project can create")
updateQuotaCmd.Flags().IntVar("aVolumeGroups, "volumegroups", 0, "Update the number of volume groups the project can create")
updateQuotaCmd.Flags().IntVar("aNetworks, "networks", 0, "Update the number of networks the project can create")
updateQuotaCmd.Flags().IntVar("aFloatingIPs, "floatingips", 0, "Update the number of floating ips the project can allocate")
updateQuotaCmd.Flags().IntVar("aPorts, "ports", 0, "Update the number of ports the project can create")
updateQuotaCmd.Flags().IntVar("aRBAC, "rbac", 0, "Update the number of RBAC policies the project can create")
updateQuotaCmd.Flags().IntVar("aRouters, "routers", 0, "Update the number of routers the project can create")
updateQuotaCmd.Flags().IntVar("aSecurityGroups, "securitygroups", 0, "Update the number of security groups the project can create")
updateQuotaCmd.Flags().IntVar("aSecurityGroupRules, "securitygrouprules", 0, "Update the number of rules a security group can contain")
updateQuotaCmd.Flags().IntVar("aSubnets, "subnets", 0, "Update the number of subnets the project can create")
}