blob: 741a9593580dcd6b00b9d61c29ef6a0a009fac68 [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 Hannaford79475052014-09-15 17:08:06 +020010type NetworkProvider struct {
11 ProviderSegmentationID int `json:"provider:segmentation_id"`
Jamie Hannaforda7f671a2014-09-11 10:25:08 +020012 ProviderPhysicalNetwork string `json:"provider:physical_network"`
Jamie Hannaford79475052014-09-15 17:08:06 +020013 ProviderNetworkType string `json:"provider:network_type"`
14}
15
16type Network struct {
17 Status string `json:"status"`
18 Subnets []interface{} `json:"subnets"`
19 Name string `json:"name"`
20 AdminStateUp bool `json:"admin_state_up"`
21 TenantID string `json:"tenant_id"`
22 Shared bool `json:"shared"`
23 ID string `json:"id"`
24}
25
26type NetworkResult struct {
27 Network
28 NetworkProvider
29 RouterExternal bool `json:"router:external"`
30}
31
32type NetworkCreateResult struct {
33 Network
34 Segments []NetworkProvider `json:"segments"`
35 PortSecurityEnabled bool `json:"port_security_enabled"`
Jamie Hannaforda7f671a2014-09-11 10:25:08 +020036}
Jamie Hannaford01e14922014-09-11 15:23:49 +020037
38type APIVersion struct {
39 Status string
40 ID string
41}
42
43type APIVersionsList struct {
44 gophercloud.PaginationLinks `json:"links"`
45 Client *gophercloud.ServiceClient
46 APIVersions []APIVersion `json:"versions"`
47}
48
49func (list APIVersionsList) Pager() gophercloud.Pager {
50 return gophercloud.NewLinkPager(list)
51}
52
53func (list APIVersionsList) Concat(other gophercloud.Collection) gophercloud.Collection {
54 return APIVersionsList{
55 Client: list.Client,
56 APIVersions: append(list.APIVersions, ToAPIVersions(other)...),
57 }
58}
59
60func (list APIVersionsList) Service() *gophercloud.ServiceClient {
61 return list.Client
62}
63
64func (list APIVersionsList) Links() gophercloud.PaginationLinks {
65 return list.PaginationLinks
66}
67
68func (list APIVersionsList) Interpret(json interface{}) (gophercloud.LinkCollection, error) {
69 mapped, ok := json.(map[string]interface{})
70 if !ok {
71 return nil, fmt.Errorf("Unexpected JSON response: %#v", json)
72 }
73
74 var result APIVersionsList
75 err := mapstructure.Decode(mapped, &result)
76 if err != nil {
77 return nil, err
78 }
79 return result, nil
80}
81
82func ToAPIVersions(results gophercloud.Collection) []APIVersion {
83 return results.(*APIVersionsList).APIVersions
84}
Jamie Hannafordf14d4562014-09-11 17:46:18 +020085
86type APIResource struct {
87 Name string
88 Collection string
89}
90
91type APIInfoList struct {
92 gophercloud.PaginationLinks `json:"links"`
93 Client *gophercloud.ServiceClient
94 APIResources []APIResource `json:"resources"`
95}
96
97func (list APIInfoList) Pager() gophercloud.Pager {
98 return gophercloud.NewLinkPager(list)
99}
100
101func (list APIInfoList) Concat(other gophercloud.Collection) gophercloud.Collection {
102 return APIInfoList{
103 Client: list.Client,
104 APIResources: append(list.APIResources, ToAPIResource(other)...),
105 }
106}
107
108func (list APIInfoList) Service() *gophercloud.ServiceClient {
109 return list.Client
110}
111
112func (list APIInfoList) Links() gophercloud.PaginationLinks {
113 return list.PaginationLinks
114}
115
116func (list APIInfoList) Interpret(json interface{}) (gophercloud.LinkCollection, error) {
117 mapped, ok := json.(map[string]interface{})
118 if !ok {
119 return nil, fmt.Errorf("Unexpected JSON response: %#v", json)
120 }
121
122 var result APIInfoList
123 err := mapstructure.Decode(mapped, &result)
124 if err != nil {
125 return nil, err
126 }
127 return result, nil
128}
129
130func ToAPIResource(results gophercloud.Collection) []APIResource {
131 return results.(*APIInfoList).APIResources
132}
Jamie Hannaford12bc2472014-09-15 12:14:31 +0200133
134type Extension struct {
135 Updated string `json:"updated"`
136 Name string `json:"name"`
137 Links []interface{} `json:"links"`
138 Namespace string `json:"namespace"`
139 Alias string `json:"alias"`
140 Description string `json:"description"`
141}