blob: eabf6bc98054cdbc2a5bfb4bcf1ecd45871127f7 [file] [log] [blame]
Jamie Hannaforda7f671a2014-09-11 10:25:08 +02001package networks
2
Jamie Hannaford01e14922014-09-11 15:23:49 +02003import (
4 "fmt"
5
6 "github.com/mitchellh/mapstructure"
7 "github.com/rackspace/gophercloud"
8)
9
Jamie Hannaforda7f671a2014-09-11 10:25:08 +020010// A Network represents a a virtual layer-2 broadcast domain.
11type Network struct {
12 // Id is the unique identifier for the network.
13 Id string `json:"id"`
14 // Name is the (not necessarily unique) human-readable identifier for the network.
15 Name string `json:"name"`
16 // AdminStateUp is administrative state of the network. If false, network is down.
17 AdminStateUp bool `json:"admin_state_up"`
18 // Status indicates if the network is operational. Possible values: active, down, build, error.
19 Status string `json:"status"`
20 // Subnets are IP address blocks that can be used to assign IP addresses to virtual instances.
21 Subnets []string `json:"subnets"`
22 // Shared indicates whether the network can be accessed by any tenant or not.
23 Shared bool `json:"shared"`
24 // TenantId is the owner of the network. Admins may specify TenantId other than their own.
25 TenantId string `json:"tenant_id"`
26 // RouterExternal indicates if the network is connected to an external router.
27 RouterExternal bool `json:"router:external"`
28 // ProviderPhysicalNetwork is the name of the provider physical network.
29 ProviderPhysicalNetwork string `json:"provider:physical_network"`
30 // ProviderNetworkType is the type of provider network (eg "vlan").
31 ProviderNetworkType string `json:"provider:network_type"`
32 // ProviderSegmentationId is the provider network identifier (such as the vlan id).
33 ProviderSegmentationId string `json:"provider:segmentation_id"`
34}
Jamie Hannaford01e14922014-09-11 15:23:49 +020035
36type APIVersion struct {
37 Status string
38 ID string
39}
40
41type APIVersionsList struct {
42 gophercloud.PaginationLinks `json:"links"`
43 Client *gophercloud.ServiceClient
44 APIVersions []APIVersion `json:"versions"`
45}
46
47func (list APIVersionsList) Pager() gophercloud.Pager {
48 return gophercloud.NewLinkPager(list)
49}
50
51func (list APIVersionsList) Concat(other gophercloud.Collection) gophercloud.Collection {
52 return APIVersionsList{
53 Client: list.Client,
54 APIVersions: append(list.APIVersions, ToAPIVersions(other)...),
55 }
56}
57
58func (list APIVersionsList) Service() *gophercloud.ServiceClient {
59 return list.Client
60}
61
62func (list APIVersionsList) Links() gophercloud.PaginationLinks {
63 return list.PaginationLinks
64}
65
66func (list APIVersionsList) Interpret(json interface{}) (gophercloud.LinkCollection, error) {
67 mapped, ok := json.(map[string]interface{})
68 if !ok {
69 return nil, fmt.Errorf("Unexpected JSON response: %#v", json)
70 }
71
72 var result APIVersionsList
73 err := mapstructure.Decode(mapped, &result)
74 if err != nil {
75 return nil, err
76 }
77 return result, nil
78}
79
80func ToAPIVersions(results gophercloud.Collection) []APIVersion {
81 return results.(*APIVersionsList).APIVersions
82}