Jamie Hannaford | a7f671a | 2014-09-11 10:25:08 +0200 | [diff] [blame] | 1 | package networks |
| 2 | |
Jamie Hannaford | 01e1492 | 2014-09-11 15:23:49 +0200 | [diff] [blame] | 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "github.com/mitchellh/mapstructure" |
| 7 | "github.com/rackspace/gophercloud" |
| 8 | ) |
| 9 | |
Jamie Hannaford | 7947505 | 2014-09-15 17:08:06 +0200 | [diff] [blame^] | 10 | type NetworkProvider struct { |
| 11 | ProviderSegmentationID int `json:"provider:segmentation_id"` |
Jamie Hannaford | a7f671a | 2014-09-11 10:25:08 +0200 | [diff] [blame] | 12 | ProviderPhysicalNetwork string `json:"provider:physical_network"` |
Jamie Hannaford | 7947505 | 2014-09-15 17:08:06 +0200 | [diff] [blame^] | 13 | ProviderNetworkType string `json:"provider:network_type"` |
| 14 | } |
| 15 | |
| 16 | type 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 | |
| 26 | type NetworkResult struct { |
| 27 | Network |
| 28 | NetworkProvider |
| 29 | RouterExternal bool `json:"router:external"` |
| 30 | } |
| 31 | |
| 32 | type NetworkCreateResult struct { |
| 33 | Network |
| 34 | Segments []NetworkProvider `json:"segments"` |
| 35 | PortSecurityEnabled bool `json:"port_security_enabled"` |
Jamie Hannaford | a7f671a | 2014-09-11 10:25:08 +0200 | [diff] [blame] | 36 | } |
Jamie Hannaford | 01e1492 | 2014-09-11 15:23:49 +0200 | [diff] [blame] | 37 | |
| 38 | type APIVersion struct { |
| 39 | Status string |
| 40 | ID string |
| 41 | } |
| 42 | |
| 43 | type APIVersionsList struct { |
| 44 | gophercloud.PaginationLinks `json:"links"` |
| 45 | Client *gophercloud.ServiceClient |
| 46 | APIVersions []APIVersion `json:"versions"` |
| 47 | } |
| 48 | |
| 49 | func (list APIVersionsList) Pager() gophercloud.Pager { |
| 50 | return gophercloud.NewLinkPager(list) |
| 51 | } |
| 52 | |
| 53 | func (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 | |
| 60 | func (list APIVersionsList) Service() *gophercloud.ServiceClient { |
| 61 | return list.Client |
| 62 | } |
| 63 | |
| 64 | func (list APIVersionsList) Links() gophercloud.PaginationLinks { |
| 65 | return list.PaginationLinks |
| 66 | } |
| 67 | |
| 68 | func (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 | |
| 82 | func ToAPIVersions(results gophercloud.Collection) []APIVersion { |
| 83 | return results.(*APIVersionsList).APIVersions |
| 84 | } |
Jamie Hannaford | f14d456 | 2014-09-11 17:46:18 +0200 | [diff] [blame] | 85 | |
| 86 | type APIResource struct { |
| 87 | Name string |
| 88 | Collection string |
| 89 | } |
| 90 | |
| 91 | type APIInfoList struct { |
| 92 | gophercloud.PaginationLinks `json:"links"` |
| 93 | Client *gophercloud.ServiceClient |
| 94 | APIResources []APIResource `json:"resources"` |
| 95 | } |
| 96 | |
| 97 | func (list APIInfoList) Pager() gophercloud.Pager { |
| 98 | return gophercloud.NewLinkPager(list) |
| 99 | } |
| 100 | |
| 101 | func (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 | |
| 108 | func (list APIInfoList) Service() *gophercloud.ServiceClient { |
| 109 | return list.Client |
| 110 | } |
| 111 | |
| 112 | func (list APIInfoList) Links() gophercloud.PaginationLinks { |
| 113 | return list.PaginationLinks |
| 114 | } |
| 115 | |
| 116 | func (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 | |
| 130 | func ToAPIResource(results gophercloud.Collection) []APIResource { |
| 131 | return results.(*APIInfoList).APIResources |
| 132 | } |
Jamie Hannaford | 12bc247 | 2014-09-15 12:14:31 +0200 | [diff] [blame] | 133 | |
| 134 | type 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 | } |