blob: b23395a793f9840cc786dbe5195b4644c42656ec [file] [log] [blame]
Jamie Hannaforda7f671a2014-09-11 10:25:08 +02001package networks
2
Jamie Hannaford4721abc2014-09-16 16:29:04 +02003import (
4 "github.com/mitchellh/mapstructure"
5 "github.com/rackspace/gophercloud"
6)
7
Jamie Hannaford79475052014-09-15 17:08:06 +02008type NetworkProvider struct {
9 ProviderSegmentationID int `json:"provider:segmentation_id"`
Jamie Hannaforda7f671a2014-09-11 10:25:08 +020010 ProviderPhysicalNetwork string `json:"provider:physical_network"`
Jamie Hannaford79475052014-09-15 17:08:06 +020011 ProviderNetworkType string `json:"provider:network_type"`
12}
13
14type Network struct {
Jamie Hannaford4721abc2014-09-16 16:29:04 +020015 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 Hannaford79475052014-09-15 17:08:06 +020026}
27
28type NetworkCreateResult struct {
29 Network
30 Segments []NetworkProvider `json:"segments"`
31 PortSecurityEnabled bool `json:"port_security_enabled"`
Jamie Hannaforda7f671a2014-09-11 10:25:08 +020032}
Jamie Hannaford4721abc2014-09-16 16:29:04 +020033
34func 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}