-
Notifications
You must be signed in to change notification settings - Fork 0
/
quotas.go
139 lines (127 loc) · 5.13 KB
/
quotas.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
package main
import (
"fmt"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets"
"github.com/gophercloud/gophercloud/auth/token"
)
func main() {
fmt.Println("main start...")
//Set authentication parameters
tokenOpts := token.TokenOptions{
IdentityEndpoint: "https://iam.xxx.yyy.com/v3",
Username: "{Username}",
Password: "{Password}",
DomainID: "{DomainID}",
ProjectID: "{ProjectID}",
}
//Init provider client
provider, authErr := openstack.AuthenticatedClient(tokenOpts)
if authErr != nil {
fmt.Println("Failed to get the AuthenticatedClient: ", authErr)
return
}
sc, computeV2Err := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{})
if computeV2Err != nil {
fmt.Println("Get compute v2 client failed!", computeV2Err)
if ue, ok := computeV2Err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode:", ue.ErrorCode())
fmt.Println("Message:", ue.Message())
}
return
}
projectID := "{projectID}"
GetQuotaSetLimit(sc)
GetQuotaSetDefault(sc, projectID)
GetQuotaSet(sc, projectID)
fmt.Println("main end...")
}
// GetQuotaSetLimit gets tenant quota limits
func GetQuotaSetLimit(sc *gophercloud.ServiceClient) {
resp, err := quotasets.GetLimits(sc).Extract()
if err != nil {
fmt.Println(err)
if ue, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode", ue.ErrCode)
fmt.Println("ErrMessage", ue.ErrMessage)
}
return
}
fmt.Println("Server get QuotaSetLimit success!")
fmt.Println("maxServerMeta is ",resp.Absolute.MaxImageMeta)
fmt.Println("MaxPersonality is ",resp.Absolute.MaxPersonality)
fmt.Println("MaxPersonalitySize is ",resp.Absolute.MaxPersonalitySize)
fmt.Println("MaxSecurityGroupRules is ",resp.Absolute.MaxSecurityGroupRules)
fmt.Println("MaxSecurityGroups is ",resp.Absolute.MaxSecurityGroups)
fmt.Println("MaxServerGroupMembers is ",resp.Absolute.MaxServerGroupMembers)
fmt.Println("MaxServerGroups is ",resp.Absolute.MaxServerGroups)
fmt.Println("MaxServerMeta is ",resp.Absolute.MaxServerMeta)
fmt.Println("MaxTotalCores is ",resp.Absolute.MaxTotalCores)
fmt.Println("MaxTotalFloatingIps is ",resp.Absolute.MaxTotalFloatingIps)
fmt.Println("MaxTotalInstances is ",resp.Absolute.MaxTotalInstances)
fmt.Println("MaxTotalKeypairs is ",resp.Absolute.MaxTotalKeypairs)
fmt.Println("MaxTotalRAMSize is ",resp.Absolute.MaxTotalRAMSize)
fmt.Println("TotalCoresUsed is ",resp.Absolute.TotalCoresUsed)
fmt.Println("TotalFloatingIpsUsed is ",resp.Absolute.TotalFloatingIpsUsed)
fmt.Println("TotalInstancesUsed is ",resp.Absolute.TotalInstancesUsed)
fmt.Println("TotalRAMUsed is ",resp.Absolute.TotalRAMUsed)
fmt.Println("TotalSecurityGroupsUsed is ",resp.Absolute.TotalSecurityGroupsUsed)
fmt.Println("TotalServerGroupsUsed is ",resp.Absolute.TotalServerGroupsUsed)
}
// GetQuotaSet gets tenant quota
func GetQuotaSet(sc *gophercloud.ServiceClient, projectID string) {
resp, err := quotasets.Get(sc, projectID).Extract()
if err != nil {
fmt.Println(err)
if ue, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode", ue.ErrCode)
fmt.Println("ErrMessage", ue.ErrMessage)
}
return
}
fmt.Println("Server get QuotaSet success!")
fmt.Println("ID is ",resp.ID)
fmt.Println("Cores is ",resp.Cores)
fmt.Println("FixedIPs is ",resp.FixedIPs)
fmt.Println("FloatingIPs is ",resp.FloatingIPs)
fmt.Println("InjectedFileContentBytes is ",resp.InjectedFileContentBytes)
fmt.Println("InjectedFiles is ",resp.InjectedFiles)
fmt.Println("Instances is ",resp.Instances)
fmt.Println("KeyPairs is ",resp.KeyPairs)
fmt.Println("MetadataItems is ",resp.MetadataItems)
fmt.Println("RAM is ",resp.RAM)
fmt.Println("SecurityGroupRules is ",resp.SecurityGroupRules)
fmt.Println("SecurityGroups is ",resp.SecurityGroups)
fmt.Println("InjectedFilePathBytes is ",resp.InjectedFilePathBytes)
fmt.Println("ServerGroupMembers is ",resp.ServerGroupMembers)
fmt.Println("ServerGroups is ",resp.ServerGroups)
}
// GetQuotaSetDefault gets default quota
func GetQuotaSetDefault(sc *gophercloud.ServiceClient, projectID string) {
resp, err := quotasets.GetDefault(sc, projectID).Extract()
if err != nil {
fmt.Println(err)
if ue, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode", ue.ErrCode)
fmt.Println("ErrMessage", ue.ErrMessage)
}
return
}
fmt.Println("Server get QuotaSet success!")
fmt.Println("ID is ",resp.ID)
fmt.Println("Cores is ",resp.Cores)
fmt.Println("FixedIPs is ",resp.FixedIPs)
fmt.Println("FloatingIPs is ",resp.FloatingIPs)
fmt.Println("InjectedFileContentBytes is ",resp.InjectedFileContentBytes)
fmt.Println("InjectedFiles is ",resp.InjectedFiles)
fmt.Println("Instances is ",resp.Instances)
fmt.Println("KeyPairs is ",resp.KeyPairs)
fmt.Println("MetadataItems is ",resp.MetadataItems)
fmt.Println("RAM is ",resp.RAM)
fmt.Println("SecurityGroupRules is ",resp.SecurityGroupRules)
fmt.Println("SecurityGroups is ",resp.SecurityGroups)
fmt.Println("InjectedFilePathBytes is ",resp.InjectedFilePathBytes)
fmt.Println("ServerGroupMembers is ",resp.ServerGroupMembers)
fmt.Println("ServerGroups is ",resp.ServerGroups)
}