Jamie Hannaford | a7f671a | 2014-09-11 10:25:08 +0200 | [diff] [blame] | 1 | package networks |
| 2 | |
Jamie Hannaford | 4721abc | 2014-09-16 16:29:04 +0200 | [diff] [blame^] | 3 | import ( |
| 4 | "github.com/mitchellh/mapstructure" |
| 5 | "github.com/rackspace/gophercloud" |
| 6 | ) |
| 7 | |
Jamie Hannaford | 7947505 | 2014-09-15 17:08:06 +0200 | [diff] [blame] | 8 | type NetworkProvider struct { |
| 9 | ProviderSegmentationID int `json:"provider:segmentation_id"` |
Jamie Hannaford | a7f671a | 2014-09-11 10:25:08 +0200 | [diff] [blame] | 10 | ProviderPhysicalNetwork string `json:"provider:physical_network"` |
Jamie Hannaford | 7947505 | 2014-09-15 17:08:06 +0200 | [diff] [blame] | 11 | ProviderNetworkType string `json:"provider:network_type"` |
| 12 | } |
| 13 | |
| 14 | type Network struct { |
Jamie Hannaford | 4721abc | 2014-09-16 16:29:04 +0200 | [diff] [blame^] | 15 | Status string `mapstructure:"status" json:"status"` |
| 16 | Subnets []interface{} `mapstructure:"subnets" json:"subnets"` |
| 17 | Name string `mapstructure:"name" json:"name"` |
| 18 | AdminStateUp bool `mapstructure:"admin_state_up" json:"admin_state_up"` |
| 19 | TenantID string `mapstructure:"tenant_id" json:"tenant_id"` |
| 20 | Shared bool `mapstructure:"shared" json:"shared"` |
| 21 | ID string `mapstructure:"id" json:"id"` |
| 22 | ProviderSegmentationID int `mapstructure:"provider:segmentation_id" json:"provider:segmentation_id"` |
| 23 | ProviderPhysicalNetwork string `mapstructure:"provider:physical_network" json:"provider:physical_network"` |
| 24 | ProviderNetworkType string `mapstructure:"provider:network_type" json:"provider:network_type"` |
| 25 | RouterExternal bool `mapstructure:"router:external" json:"router:external"` |
Jamie Hannaford | 7947505 | 2014-09-15 17:08:06 +0200 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | type NetworkCreateResult struct { |
| 29 | Network |
| 30 | Segments []NetworkProvider `json:"segments"` |
| 31 | PortSecurityEnabled bool `json:"port_security_enabled"` |
Jamie Hannaford | a7f671a | 2014-09-11 10:25:08 +0200 | [diff] [blame] | 32 | } |
Jamie Hannaford | 4721abc | 2014-09-16 16:29:04 +0200 | [diff] [blame^] | 33 | |
| 34 | func ExtractNetworks(page gophercloud.Page) ([]Network, error) { |
| 35 | var resp struct { |
| 36 | Networks []Network `mapstructure:"networks" json:"networks"` |
| 37 | } |
| 38 | |
| 39 | err := mapstructure.Decode(page.(gophercloud.LinkedPage).Body, &resp) |
| 40 | if err != nil { |
| 41 | return nil, err |
| 42 | } |
| 43 | |
| 44 | return resp.Networks, nil |
| 45 | } |