This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
quotas.go
69 lines (65 loc) · 2.05 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
package main
import (
"fmt"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/auth/aksk"
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/as/v1/quotas"
)
func main() {
fmt.Println("main start...")
//AKSK 认证,初始化认证参数。
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}",
}
//初始化provider client。
provider, errAuth := openstack.AuthenticatedClient(opts)
if errAuth != nil {
fmt.Println("Failed to get the provider: ", errAuth)
return
}
//初始化服务 client
sc, errClient := openstack.NewASV1(provider, gophercloud.EndpointOpts{})
if errClient != nil {
fmt.Println("Failed to get the NewASV1 client: ", errClient)
return
}
//开始测试
ListQutas(sc)
ListQutasWithPar(sc)
fmt.Println("main end...")
}
//--------------------------------------查询配额----------------------------------------
func ListQutas(client *gophercloud.ServiceClient) {
result, err := quotas.List(client).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("Qutas: %+v\r\n", result)
fmt.Println("Test Query Qutas success!")
}
//--------------------------------------查询弹性伸缩策略和伸缩实例配额---------------------------------------
func ListQutasWithPar(client *gophercloud.ServiceClient) {
result, err := quotas.ListWithInstances(client, "86f3b2dc-de0f-4e63-84ac-a4fddb713555").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("Qutas: %+v\r\n", result)
fmt.Println("Test Query Qutas of Policy&Instances success!")
}