Making return types more consistent :boom:
diff --git a/openstack/networking/v2/networks/requests.go b/openstack/networking/v2/networks/requests.go
index 7b647fe..9a23cc0 100644
--- a/openstack/networking/v2/networks/requests.go
+++ b/openstack/networking/v2/networks/requests.go
@@ -1,9 +1,6 @@
package networks
import (
- "encoding/json"
- "fmt"
-
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
)
@@ -52,12 +49,12 @@
return &ext, nil
}
-func Get(c *gophercloud.ServiceClient, id string) (*Network, error) {
- var n Network
+func Get(c *gophercloud.ServiceClient, id string) (*NetworkResult, error) {
+ var n NetworkResult
_, err := perigee.Request("GET", NetworkURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
Results: &struct {
- Network *Network `json:"network"`
+ Network *NetworkResult `json:"network"`
}{&n},
OkCodes: []int{200},
})
@@ -74,25 +71,7 @@
TenantID string
}
-type NetworkProvider struct {
- ProviderSegmentationID int `json:"provider:segmentation_id"`
- ProviderPhysicalNetwork string `json:"provider:physical_network"`
- ProviderNetworkType string `json:"provider:network_type"`
-}
-
-type NetworkResult struct {
- Status string `json:"status"`
- Subnets []interface{} `json:"subnets"`
- Name string `json:"name"`
- AdminStateUp bool `json:"admin_state_up"`
- TenantID string `json:"tenant_id"`
- Segments []NetworkProvider `json:"segments"`
- Shared bool `json:"shared"`
- PortSecurityEnabled bool `json:"port_security_enabled"`
- ID string `json:"id"`
-}
-
-func Create(c *gophercloud.ServiceClient, opts NetworkOpts) (*NetworkResult, error) {
+func Create(c *gophercloud.ServiceClient, opts NetworkOpts) (*NetworkCreateResult, error) {
// Define structures
type network struct {
AdminStateUp bool `json:"admin_state_up"`
@@ -104,7 +83,7 @@
Network network `json:"network"`
}
type response struct {
- Network *NetworkResult `json:"network"`
+ Network *NetworkCreateResult `json:"network"`
}
// Validate
@@ -123,9 +102,6 @@
reqBody.Network.TenantID = &opts.TenantID
}
- j, _ := json.Marshal(reqBody)
- fmt.Println(string(j))
-
// Send request to API
var res response
_, err := perigee.Request("POST", CreateURL(c), perigee.Options{
@@ -140,3 +116,45 @@
return res.Network, nil
}
+
+func Update(c *gophercloud.ServiceClient, networkID string, opts NetworkOpts) (*NetworkResult, 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"`
+ }
+
+ type request struct {
+ Network network `json:"network"`
+ }
+ type response struct {
+ Network *NetworkResult `json:"network"`
+ }
+
+ // Populate request body
+ reqBody := request{Network: network{
+ AdminStateUp: opts.AdminStateUp,
+ Name: opts.Name,
+ Shared: opts.Shared,
+ }}
+
+ if opts.TenantID != "" {
+ reqBody.Network.TenantID = &opts.TenantID
+ }
+
+ // Send request to API
+ var res response
+ _, err := perigee.Request("PUT", NetworkURL(c, networkID), perigee.Options{
+ MoreHeaders: c.Provider.AuthenticatedHeaders(),
+ ReqBody: &reqBody,
+ Results: &res,
+ OkCodes: []int{200},
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ return res.Network, nil
+}