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 | a7f671a | 2014-09-11 10:25:08 +0200 | [diff] [blame] | 10 | // A Network represents a a virtual layer-2 broadcast domain. |
| 11 | type Network struct { |
| 12 | // Id is the unique identifier for the network. |
Jamie Hannaford | d01a3c7 | 2014-09-15 12:51:00 +0200 | [diff] [blame] | 13 | ID string `json:"id"` |
Jamie Hannaford | a7f671a | 2014-09-11 10:25:08 +0200 | [diff] [blame] | 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. |
Jamie Hannaford | d01a3c7 | 2014-09-15 12:51:00 +0200 | [diff] [blame] | 25 | TenantID string `json:"tenant_id"` |
Jamie Hannaford | a7f671a | 2014-09-11 10:25:08 +0200 | [diff] [blame] | 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). |
Jamie Hannaford | d01a3c7 | 2014-09-15 12:51:00 +0200 | [diff] [blame] | 33 | ProviderSegmentationID string `json:"provider:segmentation_id"` |
Jamie Hannaford | a7f671a | 2014-09-11 10:25:08 +0200 | [diff] [blame] | 34 | } |
Jamie Hannaford | 01e1492 | 2014-09-11 15:23:49 +0200 | [diff] [blame] | 35 | |
| 36 | type APIVersion struct { |
| 37 | Status string |
| 38 | ID string |
| 39 | } |
| 40 | |
| 41 | type APIVersionsList struct { |
| 42 | gophercloud.PaginationLinks `json:"links"` |
| 43 | Client *gophercloud.ServiceClient |
| 44 | APIVersions []APIVersion `json:"versions"` |
| 45 | } |
| 46 | |
| 47 | func (list APIVersionsList) Pager() gophercloud.Pager { |
| 48 | return gophercloud.NewLinkPager(list) |
| 49 | } |
| 50 | |
| 51 | func (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 | |
| 58 | func (list APIVersionsList) Service() *gophercloud.ServiceClient { |
| 59 | return list.Client |
| 60 | } |
| 61 | |
| 62 | func (list APIVersionsList) Links() gophercloud.PaginationLinks { |
| 63 | return list.PaginationLinks |
| 64 | } |
| 65 | |
| 66 | func (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 | |
| 80 | func ToAPIVersions(results gophercloud.Collection) []APIVersion { |
| 81 | return results.(*APIVersionsList).APIVersions |
| 82 | } |
Jamie Hannaford | f14d456 | 2014-09-11 17:46:18 +0200 | [diff] [blame] | 83 | |
| 84 | type APIResource struct { |
| 85 | Name string |
| 86 | Collection string |
| 87 | } |
| 88 | |
| 89 | type APIInfoList struct { |
| 90 | gophercloud.PaginationLinks `json:"links"` |
| 91 | Client *gophercloud.ServiceClient |
| 92 | APIResources []APIResource `json:"resources"` |
| 93 | } |
| 94 | |
| 95 | func (list APIInfoList) Pager() gophercloud.Pager { |
| 96 | return gophercloud.NewLinkPager(list) |
| 97 | } |
| 98 | |
| 99 | func (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 | |
| 106 | func (list APIInfoList) Service() *gophercloud.ServiceClient { |
| 107 | return list.Client |
| 108 | } |
| 109 | |
| 110 | func (list APIInfoList) Links() gophercloud.PaginationLinks { |
| 111 | return list.PaginationLinks |
| 112 | } |
| 113 | |
| 114 | func (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 | |
| 128 | func ToAPIResource(results gophercloud.Collection) []APIResource { |
| 129 | return results.(*APIInfoList).APIResources |
| 130 | } |
Jamie Hannaford | 12bc247 | 2014-09-15 12:14:31 +0200 | [diff] [blame] | 131 | |
| 132 | type 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 | } |