Shuffled resources into sub-packages and upgraded to new pagination idiom
diff --git a/openstack/networking/v2/networks/requests.go b/openstack/networking/v2/networks/requests.go
index 06b0fe7..98e70d1 100644
--- a/openstack/networking/v2/networks/requests.go
+++ b/openstack/networking/v2/networks/requests.go
@@ -1,10 +1,24 @@
package networks
import (
+ "strconv"
+
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/openstack/utils"
)
+type ListOpts struct {
+ Status string
+ Name string
+ AdminStateUp *bool
+ TenantID string
+ Shared *bool
+ ID string
+ Page int
+ PerPage int
+}
+
type NetworkOpts struct {
AdminStateUp bool
Name string
@@ -12,12 +26,54 @@
TenantID string
}
-func Get(c *gophercloud.ServiceClient, id string) (*NetworkResult, error) {
- var n NetworkResult
- _, err := perigee.Request("GET", NetworkURL(c, id), perigee.Options{
+func ptrToStr(val *bool) string {
+ if *val == true {
+ return "true"
+ } else if *val == false {
+ return "false"
+ } else {
+ return ""
+ }
+}
+
+func List(c *gophercloud.ServiceClient, opts ListOpts) gophercloud.Pager {
+ // Build query parameters
+ q := make(map[string]string)
+ if opts.Status != "" {
+ q["status"] = opts.Status
+ }
+ if opts.Name != "" {
+ q["name"] = opts.Name
+ }
+ if opts.AdminStateUp != nil {
+ q["admin_state_up"] = ptrToStr(opts.AdminStateUp)
+ }
+ if opts.TenantID != "" {
+ q["tenant_id"] = opts.TenantID
+ }
+ if opts.Shared != nil {
+ q["shared"] = ptrToStr(opts.Shared)
+ }
+ if opts.ID != "" {
+ q["id"] = opts.ID
+ }
+ if opts.Page != 0 {
+ q["page"] = strconv.Itoa(opts.Page)
+ }
+ if opts.PerPage != 0 {
+ q["per_page"] = strconv.Itoa(opts.PerPage)
+ }
+
+ u := ListURL(c) + utils.BuildQuery(q)
+ return gophercloud.NewLinkedPager(c, u)
+}
+
+func Get(c *gophercloud.ServiceClient, id string) (*Network, error) {
+ var n Network
+ _, err := perigee.Request("GET", GetURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
Results: &struct {
- Network *NetworkResult `json:"network"`
+ Network *Network `json:"network"`
}{&n},
OkCodes: []int{200},
})
@@ -73,7 +129,7 @@
return res.Network, nil
}
-func Update(c *gophercloud.ServiceClient, networkID string, opts NetworkOpts) (*NetworkResult, error) {
+func Update(c *gophercloud.ServiceClient, networkID string, opts NetworkOpts) (*Network, error) {
// Define structures
type network struct {
AdminStateUp bool `json:"admin_state_up"`
@@ -86,7 +142,7 @@
Network network `json:"network"`
}
type response struct {
- Network *NetworkResult `json:"network"`
+ Network *Network `json:"network"`
}
// Populate request body
@@ -102,7 +158,7 @@
// Send request to API
var res response
- _, err := perigee.Request("PUT", NetworkURL(c, networkID), perigee.Options{
+ _, err := perigee.Request("PUT", GetURL(c, networkID), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &res,
@@ -114,3 +170,11 @@
return res.Network, nil
}
+
+func Delete(c *gophercloud.ServiceClient, networkID string) error {
+ _, err := perigee.Request("DELETE", DeleteURL(c, networkID), perigee.Options{
+ MoreHeaders: c.Provider.AuthenticatedHeaders(),
+ OkCodes: []int{204},
+ })
+ return err
+}