blob: 88cbc80ec2d50d0690d1ce4f4f6656246d53e60f [file] [log] [blame]
Joe Topjianc21202d2015-02-27 21:32:58 +00001package tenantnetworks
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Joe Topjianc21202d2015-02-27 21:32:58 +00006)
7
8// A Network represents a nova-network that an instance communicates on
9type Network struct {
10 // CIDR is the IPv4 subnet.
Jon Perritt12395212016-02-24 10:41:17 -060011 CIDR string `json:"cidr"`
Joe Topjianc21202d2015-02-27 21:32:58 +000012
13 // ID is the UUID of the network.
Jon Perritt12395212016-02-24 10:41:17 -060014 ID string `json:"id"`
Joe Topjianc21202d2015-02-27 21:32:58 +000015
16 // Name is the common name that the network has.
Jon Perritt12395212016-02-24 10:41:17 -060017 Name string `json:"label"`
Joe Topjianc21202d2015-02-27 21:32:58 +000018}
19
20// NetworkPage stores a single, only page of Networks
21// results from a List call.
22type NetworkPage struct {
23 pagination.SinglePageBase
24}
25
26// IsEmpty determines whether or not a NetworkPage is empty.
27func (page NetworkPage) IsEmpty() (bool, error) {
28 va, err := ExtractNetworks(page)
29 return len(va) == 0, err
30}
31
32// ExtractNetworks interprets a page of results as a slice of Networks
Jon Perritt31b66462016-02-25 22:25:30 -060033func ExtractNetworks(r pagination.Page) ([]Network, error) {
Jon Perritt12395212016-02-24 10:41:17 -060034 var s struct {
35 Networks []Network `json:"networks"`
Joe Topjianc21202d2015-02-27 21:32:58 +000036 }
Jon Perritt31b66462016-02-25 22:25:30 -060037 err := (r.(NetworkPage)).ExtractInto(&s)
Jon Perritt12395212016-02-24 10:41:17 -060038 return s.Networks, err
Joe Topjianc21202d2015-02-27 21:32:58 +000039}
40
41type NetworkResult struct {
42 gophercloud.Result
43}
44
45// Extract is a method that attempts to interpret any Network resource
46// response as a Network struct.
47func (r NetworkResult) Extract() (*Network, error) {
Jon Perritt12395212016-02-24 10:41:17 -060048 var s struct {
49 Network *Network `json:"network"`
Joe Topjianc21202d2015-02-27 21:32:58 +000050 }
Jon Perritt12395212016-02-24 10:41:17 -060051 err := r.ExtractInto(&s)
52 return s.Network, err
Joe Topjianc21202d2015-02-27 21:32:58 +000053}
54
55// GetResult is the response from a Get operation. Call its Extract method to interpret it
56// as a Network.
57type GetResult struct {
58 NetworkResult
59}