This repository has been archived by the owner on May 8, 2024. It is now read-only.
forked from huaweicloud/huaweicloud-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quotaset.go
100 lines (79 loc) · 2.3 KB
/
quotaset.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
package main
import (
"fmt"
"encoding/json"
"github.com/gophercloud/gophercloud/functiontest/common"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets"
)
func main() {
fmt.Println("main start...")
//provider, err := common.AuthAKSK()
provider, err := common.AuthToken()
if err != nil {
fmt.Println("get provider client failed")
if ue, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode:", ue.ErrorCode())
fmt.Println("Message:", ue.Message())
}
return
}
sc, err := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{})
if err != nil {
fmt.Println("get compute v2 client failed")
if ue, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode:", ue.ErrorCode())
fmt.Println("Message:", ue.Message())
}
return
}
TestGetQuotaSetLimit(sc)
TestGetQuotaSetDefault(sc)
TestGetQuotaSet(sc)
fmt.Println("main end...")
}
func TestGetQuotaSetLimit(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("Test server get QuotaSetLimit success!")
p, _ := json.MarshalIndent(resp, "", " ")
fmt.Println(string(p))
}
func TestGetQuotaSet(sc *gophercloud.ServiceClient) {
id := "128a7bf965154373a7b73c89eb6b65aa"
resp, err := quotasets.Get(sc, id).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("Test server get QuotaSet success!")
b,_:=json.MarshalIndent(*resp,""," ")
fmt.Println(string(b))
}
func TestGetQuotaSetDefault(sc *gophercloud.ServiceClient) {
id := "128a7bf965154373a7b73c89eb6b65aa"
resp, err := quotasets.GetDefault(sc, id).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("Test server get QuotaSetDefault success!")
p, _ := json.MarshalIndent(resp, "", " ")
fmt.Println(string(p))
}