forked from huaweicloud/huaweicloud-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quotas.go
67 lines (58 loc) · 1.69 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
package main
import (
"fmt"
"github.com/YoungPioneers/huaweicloud-sdk-go"
"github.com/YoungPioneers/huaweicloud-sdk-go/auth/aksk"
"github.com/YoungPioneers/huaweicloud-sdk-go/openstack"
"github.com/YoungPioneers/huaweicloud-sdk-go/openstack/vpc/v1/quotas"
)
func main() {
fmt.Println("main start...")
//AKSK authentication, initialization authentication parameters
opts := aksk.AKSKOptions{
IdentityEndpoint: "https://iam.xxx.yyy.com/v3",
ProjectID: "{ProjectID}",
AccessKey: "your AK string",
SecretKey: "your SK string",
Cloud: "yyy.com",
Region: "xxx",
DomainID: "{domainID}",
}
//Initialization provider client
provider, err := openstack.AuthenticatedClient(opts)
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
}
//Initialization service client
sc, err := openstack.NewVPCV1(provider, gophercloud.EndpointOpts{})
if err != nil {
fmt.Println("get network client failed")
if ue, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode:", ue.ErrorCode())
fmt.Println("Message:", ue.Message())
}
return
}
ListQuota(sc)
fmt.Println("main end...")
}
func ListQuota(client *gophercloud.ServiceClient) {
result, err := quotas.List(client, quotas.ListOpts{
Type: "securityGroup",
}).Extract()
if err != nil {
fmt.Println(err)
if ue, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode:", ue.ErrorCode())
fmt.Println("Message:", ue.Message())
}
return
}
fmt.Printf("quotas: %+v\r\n", result)
fmt.Println("List success!")
}