Modifying opts and model structs with stricter types
diff --git a/openstack/networking/v2/networks/requests.go b/openstack/networking/v2/networks/requests.go
index 73b8a1f..4f1037e 100644
--- a/openstack/networking/v2/networks/requests.go
+++ b/openstack/networking/v2/networks/requests.go
@@ -23,7 +23,7 @@
SortDir string
}
-type NetworkOpts struct {
+type networkOpts struct {
AdminStateUp bool
Name string
Shared *bool
@@ -98,7 +98,9 @@
return &n, nil
}
-func Create(c *gophercloud.ServiceClient, opts NetworkOpts) (*NetworkCreateResult, error) {
+type CreateOpts networkOpts
+
+func Create(c *gophercloud.ServiceClient, opts CreateOpts) (*NetworkCreateResult, error) {
// Define structures
type network struct {
AdminStateUp bool `json:"admin_state_up"`
@@ -144,13 +146,14 @@
return res.Network, nil
}
-func Update(c *gophercloud.ServiceClient, networkID string, opts NetworkOpts) (*Network, error) {
+type UpdateOpts networkOpts
+
+func Update(c *gophercloud.ServiceClient, networkID string, opts UpdateOpts) (*Network, error) {
// Define structures
type network struct {
- AdminStateUp bool `json:"admin_state_up"`
- Name string `json:"name"`
- Shared *bool `json:"shared,omitempty"`
- TenantID *string `json:"tenant_id,omitempty"`
+ AdminStateUp bool `json:"admin_state_up"`
+ Name string `json:"name"`
+ Shared *bool `json:"shared,omitempty"`
}
type request struct {
@@ -167,10 +170,6 @@
Shared: opts.Shared,
}}
- if opts.TenantID != "" {
- reqBody.Network.TenantID = &opts.TenantID
- }
-
// Send request to API
var res response
_, err := perigee.Request("PUT", GetURL(c, networkID), perigee.Options{
diff --git a/openstack/networking/v2/networks/requests_test.go b/openstack/networking/v2/networks/requests_test.go
index b4332b0..b637b50 100644
--- a/openstack/networking/v2/networks/requests_test.go
+++ b/openstack/networking/v2/networks/requests_test.go
@@ -84,7 +84,7 @@
expected := []Network{
Network{
Status: "ACTIVE",
- Subnets: []interface{}{"54d6f61d-db07-451c-9ab3-b9609b6b6f0b"},
+ Subnets: []string{"54d6f61d-db07-451c-9ab3-b9609b6b6f0b"},
Name: "private-network",
ProviderPhysicalNetwork: "",
AdminStateUp: true,
@@ -97,7 +97,7 @@
},
Network{
Status: "ACTIVE",
- Subnets: []interface{}{"08eae331-0402-425a-923c-34f7cfe39c1b"},
+ Subnets: []string{"08eae331-0402-425a-923c-34f7cfe39c1b"},
Name: "private",
ProviderPhysicalNetwork: "",
AdminStateUp: true,
@@ -156,7 +156,7 @@
th.AssertNoErr(t, err)
th.AssertEquals(t, n.Status, "ACTIVE")
- th.AssertDeepEquals(t, n.Subnets, []interface{}{"54d6f61d-db07-451c-9ab3-b9609b6b6f0b"})
+ th.AssertDeepEquals(t, n.Subnets, []string{"54d6f61d-db07-451c-9ab3-b9609b6b6f0b"})
th.AssertEquals(t, n.Name, "private-network")
th.AssertEquals(t, n.ProviderPhysicalNetwork, "")
th.AssertEquals(t, n.ProviderNetworkType, "local")
@@ -217,12 +217,12 @@
`)
})
- options := NetworkOpts{Name: "sample_network", AdminStateUp: true}
+ options := CreateOpts{Name: "sample_network", AdminStateUp: true}
n, err := Create(ServiceClient(), options)
th.AssertNoErr(t, err)
th.AssertEquals(t, n.Status, "ACTIVE")
- th.AssertDeepEquals(t, n.Subnets, []interface{}{})
+ th.AssertDeepEquals(t, n.Subnets, []string{})
th.AssertEquals(t, n.Name, "net1")
th.AssertEquals(t, n.AdminStateUp, true)
th.AssertEquals(t, n.TenantID, "9bacb3c5d39d41a79512987f338cf177")
@@ -259,7 +259,7 @@
})
shared := true
- options := NetworkOpts{Name: "sample_network", AdminStateUp: true, Shared: &shared, TenantID: "12345"}
+ options := CreateOpts{Name: "sample_network", AdminStateUp: true, Shared: &shared, TenantID: "12345"}
_, err := Create(ServiceClient(), options)
th.AssertNoErr(t, err)
}
@@ -306,7 +306,7 @@
})
shared := true
- options := NetworkOpts{Name: "new_network_name", AdminStateUp: false, Shared: &shared}
+ options := UpdateOpts{Name: "new_network_name", AdminStateUp: false, Shared: &shared}
n, err := Update(ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", options)
th.AssertNoErr(t, err)
diff --git a/openstack/networking/v2/networks/results.go b/openstack/networking/v2/networks/results.go
index 1f4b809..78bdff5 100644
--- a/openstack/networking/v2/networks/results.go
+++ b/openstack/networking/v2/networks/results.go
@@ -12,17 +12,26 @@
}
type Network struct {
- Status string `mapstructure:"status" json:"status"`
- Subnets []interface{} `mapstructure:"subnets" json:"subnets"`
- Name string `mapstructure:"name" json:"name"`
- AdminStateUp bool `mapstructure:"admin_state_up" json:"admin_state_up"`
- TenantID string `mapstructure:"tenant_id" json:"tenant_id"`
- Shared bool `mapstructure:"shared" json:"shared"`
- ID string `mapstructure:"id" json:"id"`
- ProviderSegmentationID int `mapstructure:"provider:segmentation_id" json:"provider:segmentation_id"`
- ProviderPhysicalNetwork string `mapstructure:"provider:physical_network" json:"provider:physical_network"`
- ProviderNetworkType string `mapstructure:"provider:network_type" json:"provider:network_type"`
- RouterExternal bool `mapstructure:"router:external" json:"router:external"`
+ // UUID for the network
+ ID string `mapstructure:"id" json:"id"`
+ // Human-readable name for the network. Might not be unique.
+ Name string `mapstructure:"name" json:"name"`
+ // The administrative state of network. If false (down), the network does not forward packets.
+ AdminStateUp bool `mapstructure:"admin_state_up" json:"admin_state_up"`
+ // Indicates whether network is currently operational. Possible values include
+ // `ACTIVE', `DOWN', `BUILD', or `ERROR'. Plug-ins might define additional values.
+ Status string `mapstructure:"status" json:"status"`
+ // Subnets associated with this network.
+ Subnets []string `mapstructure:"subnets" json:"subnets"`
+ // Owner of network. Only admin users can specify a tenant_id other than its own.
+ TenantID string `mapstructure:"tenant_id" json:"tenant_id"`
+ // Specifies whether the network resource can be accessed by any tenant or not.
+ Shared bool `mapstructure:"shared" json:"shared"`
+
+ ProviderSegmentationID int `mapstructure:"provider:segmentation_id" json:"provider:segmentation_id"`
+ ProviderPhysicalNetwork string `mapstructure:"provider:physical_network" json:"provider:physical_network"`
+ ProviderNetworkType string `mapstructure:"provider:network_type" json:"provider:network_type"`
+ RouterExternal bool `mapstructure:"router:external" json:"router:external"`
}
type NetworkCreateResult struct {