forked from huaweicloud/huaweicloud-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource.go
82 lines (71 loc) · 2.26 KB
/
resource.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
package main
import (
"encoding/json"
"fmt"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/auth/aksk"
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/bss/v1/resource"
)
func main() {
//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, err := openstack.NewBSSV1(provider, gophercloud.EndpointOpts{})
if err != nil {
fmt.Println("get bss client failed")
fmt.Println(err.Error())
return
}
customerId := ""
pageNo := 1
pageSize := 100
ListResourceDetailPage(sc, customerId, pageNo, pageSize)
}
//查询客户包周期资源列表
func ListResourceDetailPage(client *gophercloud.ServiceClient, customerId string, pageNo int, pageSize int) {
resourceListTmp := resource.ListOpts{
CustomerId: customerId,
//ResourceIds: "2251f59c-b1ef-4398-bfa8-321782f670a5",
//OrderId: "xxxx",
//OnlyMainResource: 1,
//StatusList:"1,2",
PageNo: pageNo,
PageSize: pageSize,
}
resResourceListTmp, err := resource.ListDetail(client, resourceListTmp).Extract()
if err != nil {
fmt.Println("err:", err)
if ue, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode:", ue.ErrorCode())
fmt.Println("Message:", ue.Message())
}
return
}
if resResourceListTmp.ErrorCode == "CBC.0000" {
fmt.Println("ListResourceDetailPage success!")
fmt.Println("ListResourceDetailPage.TotalCount:", resResourceListTmp.TotalCount)
fmt.Println("ListResourceDetailPage.ErrorCode:", resResourceListTmp.ErrorCode)
fmt.Println("ListResourceDetailPage.ErrorMsg:", resResourceListTmp.ErrorMsg)
fmt.Println("ListResourceDetailPage.Data:", len(resResourceListTmp.Data))
b, _ := json.MarshalIndent(resResourceListTmp, "", " ")
fmt.Println(string(b))
return
} else {
fmt.Println("ListResourceDetailPage failed!")
}
}