forked from huaweicloud/huaweicloud-sdk-go
/
results.go
96 lines (76 loc) · 2.23 KB
/
results.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
package privateips
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
type commonResult struct {
gophercloud.Result
}
type PrivateIp struct {
// Specifies the status of the private IP address. The value can
// be?ACTIVE?or?DOWN.
Status string `json:"status"`
// Specifies the ID of the private IP address.
ID string `json:"id"`
// 功能说明:分配IP的子网标识
SubnetId string `json:"subnet_id"`
// Specifies the tenant ID of the operator.
TenantId string `json:"tenant_id"`
// Specifies the VM using the private IP address. The parameter is
// left blank if it is not used. The value can
// be?network:dhcp,?network:router_interface_distributed, or?compute:xxx?(xxx?specifies
// the AZ name, for example,?compute:aa-bb-cc?indicates that the private IP address is
// used by VM in the?aa-bb-ccAZ). The value range specifies only the type of private IP
// addresses supported by the current service.
DeviceOwner string `json:"device_owner"`
// Specifies the private IP address obtained.
IpAddress string `json:"ip_address"`
}
type CreateResult struct {
commonResult
}
func (r CreateResult) Extract() (*[]PrivateIp, error) {
var list []PrivateIp
err := r.ExtractIntoSlicePtr(&list, "privateips")
return &list, err
}
type DeleteResult struct {
gophercloud.ErrResult
}
type GetResult struct {
commonResult
}
func (r GetResult) Extract() (*PrivateIp, error) {
var entity PrivateIp
err := r.ExtractIntoStructPtr(&entity, "privateip")
return &entity, err
}
type ListResult struct {
commonResult
}
func (r ListResult) Extract() (*[]PrivateIp, error) {
var list []PrivateIp
err := r.ExtractIntoSlicePtr(&list, "privateips")
return &list, err
}
func (r PrivateIpPage) IsEmpty() (bool, error) {
list, err := ExtractPrivateIps(r)
return len(list) == 0, err
}
type PrivateIpPage struct {
pagination.LinkedPageBase
}
func ExtractPrivateIps(r pagination.Page) ([]PrivateIp, error) {
var s struct {
PrivateIps []PrivateIp `json:"privateips"`
}
err := r.(PrivateIpPage).ExtractInto(&s)
return s.PrivateIps, err
}
func (r PrivateIpPage) NextPageURL() (string, error) {
s, err := ExtractPrivateIps(r)
if err != nil {
return "", err
}
return r.WrapNextPageURL(s[len(s)-1].ID)
}