blob: 61d51b09d7855e21b63006134147bca65af4dbf4 [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}
Jamie Hannafordf14d4562014-09-11 17:46:18 +020083
84type APIResource struct {
85 Name string
86 Collection string
87}
88
89type APIInfoList struct {
90 gophercloud.PaginationLinks `json:"links"`
91 Client *gophercloud.ServiceClient
92 APIResources []APIResource `json:"resources"`
93}
94
95func (list APIInfoList) Pager() gophercloud.Pager {
96 return gophercloud.NewLinkPager(list)
97}
98
99func (list APIInfoList) Concat(other gophercloud.Collection) gophercloud.Collection {
100 return APIInfoList{
101 Client: list.Client,
102 APIResources: append(list.APIResources, ToAPIResource(other)...),
103 }
104}
105
106func (list APIInfoList) Service() *gophercloud.ServiceClient {
107 return list.Client
108}
109
110func (list APIInfoList) Links() gophercloud.PaginationLinks {
111 return list.PaginationLinks
112}
113
114func (list APIInfoList) Interpret(json interface{}) (gophercloud.LinkCollection, error) {
115 mapped, ok := json.(map[string]interface{})
116 if !ok {
117 return nil, fmt.Errorf("Unexpected JSON response: %#v", json)
118 }
119
120 var result APIInfoList
121 err := mapstructure.Decode(mapped, &result)
122 if err != nil {
123 return nil, err
124 }
125 return result, nil
126}
127
128func ToAPIResource(results gophercloud.Collection) []APIResource {
129 return results.(*APIInfoList).APIResources
130}
Jamie Hannaford12bc2472014-09-15 12:14:31 +0200131
132type Extension struct {
133 Updated string `json:"updated"`
134 Name string `json:"name"`
135 Links []interface{} `json:"links"`
136 Namespace string `json:"namespace"`
137 Alias string `json:"alias"`
138 Description string `json:"description"`
139}