github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/bms/v2/nics/results.go (about) 1 package nics 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 6 "github.com/opentelekomcloud/gophertelekomcloud/pagination" 7 ) 8 9 type FixedIP struct { 10 SubnetID string `json:"subnet_id"` 11 IPAddress string `json:"ip_address"` 12 } 13 14 // Nic Manage and perform other operations on Nic, including querying Nics as well as querying Nic. 15 type Nic struct { 16 // ID is the unique identifier for the nic. 17 ID string `json:"port_id"` 18 // Specifies the ID of the network to which the NIC port belongs. 19 NetworkID string `json:"net_id"` 20 // Status indicates whether a nic is currently operational. 21 Status string `json:"port_state"` 22 // Specifies the NIC private IP address. 23 FixedIP []FixedIP `json:"fixed_ips"` 24 // Specifies the MAC address of the NIC. 25 MACAddress string `json:"mac_addr"` 26 } 27 28 // NicPage is the page returned by a pager when traversing over a collection of nics. 29 type NicPage struct { 30 pagination.LinkedPageBase 31 } 32 33 // NextPageURL is invoked when a paginated collection of nics has reached 34 // the end of a page and the pager seeks to traverse over a new one. In order 35 // to do this, it needs to construct the next page's URL. 36 func (r NicPage) NextPageURL() (string, error) { 37 var res []golangsdk.Link 38 39 err := extract.IntoSlicePtr(r.BodyReader(), &res, "interfaceAttachments_links") 40 if err != nil { 41 return "", err 42 } 43 44 return golangsdk.ExtractNextURL(res) 45 } 46 47 // IsEmpty checks whether a NicPage struct is empty. 48 func (r NicPage) IsEmpty() (bool, error) { 49 is, err := ExtractNics(r) 50 return len(is) == 0, err 51 } 52 53 // ExtractNics accepts a Page struct, specifically a NicPage struct, 54 // and extracts the elements into a slice of Nic structs. In other words, 55 // a generic collection is mapped into a relevant slice. 56 func ExtractNics(r pagination.Page) ([]Nic, error) { 57 var res []Nic 58 err := extract.IntoSlicePtr(r.(NicPage).BodyReader(), &res, "interfaceAttachments") 59 return res, err 60 }