-
Notifications
You must be signed in to change notification settings - Fork 7
/
results.go
60 lines (51 loc) · 1.92 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
package nics
import (
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
"github.com/opentelekomcloud/gophertelekomcloud/pagination"
)
type FixedIP struct {
SubnetID string `json:"subnet_id"`
IPAddress string `json:"ip_address"`
}
// Nic Manage and perform other operations on Nic, including querying Nics as well as querying Nic.
type Nic struct {
// ID is the unique identifier for the nic.
ID string `json:"port_id"`
// Specifies the ID of the network to which the NIC port belongs.
NetworkID string `json:"net_id"`
// Status indicates whether a nic is currently operational.
Status string `json:"port_state"`
// Specifies the NIC private IP address.
FixedIP []FixedIP `json:"fixed_ips"`
// Specifies the MAC address of the NIC.
MACAddress string `json:"mac_addr"`
}
// NicPage is the page returned by a pager when traversing over a collection of nics.
type NicPage struct {
pagination.LinkedPageBase
}
// NextPageURL is invoked when a paginated collection of nics has reached
// the end of a page and the pager seeks to traverse over a new one. In order
// to do this, it needs to construct the next page's URL.
func (r NicPage) NextPageURL() (string, error) {
var res []golangsdk.Link
err := extract.IntoSlicePtr(r.BodyReader(), &res, "interfaceAttachments_links")
if err != nil {
return "", err
}
return golangsdk.ExtractNextURL(res)
}
// IsEmpty checks whether a NicPage struct is empty.
func (r NicPage) IsEmpty() (bool, error) {
is, err := ExtractNics(r)
return len(is) == 0, err
}
// ExtractNics accepts a Page struct, specifically a NicPage struct,
// and extracts the elements into a slice of Nic structs. In other words,
// a generic collection is mapped into a relevant slice.
func ExtractNics(r pagination.Page) ([]Nic, error) {
var res []Nic
err := extract.IntoSlicePtr(r.(NicPage).BodyReader(), &res, "interfaceAttachments")
return res, err
}