Finishing documentation
diff --git a/openstack/networking/v2/networks/requests.go b/openstack/networking/v2/networks/requests.go
index 4f1037e..f4fbe97 100644
--- a/openstack/networking/v2/networks/requests.go
+++ b/openstack/networking/v2/networks/requests.go
@@ -9,20 +9,6 @@
"github.com/rackspace/gophercloud/pagination"
)
-type ListOpts struct {
- Status string
- Name string
- AdminStateUp *bool
- TenantID string
- Shared *bool
- ID string
- Page int
- PerPage int
- Limit int
- SortKey string
- SortDir string
-}
-
type networkOpts struct {
AdminStateUp bool
Name string
@@ -40,6 +26,27 @@
}
}
+// ListOpts allows the filtering and sorting of paginated collections through
+// the API. Filtering is achieved by passing in struct field values that map to
+// the network attributes you want to see returned. SortKey allows you to sort
+// by a particular network attribute. SortDir sets the direction, and is either
+// `asc' or `desc'. Marker and Limit are used for pagination.
+type ListOpts struct {
+ Status string
+ Name string
+ AdminStateUp *bool
+ TenantID string
+ Shared *bool
+ ID string
+ Marker string
+ Limit int
+ SortKey string
+ SortDir string
+}
+
+// List returns a Pager which allows you to iterate over a collection of
+// networks. It accepts a ListOpts struct, which allows you to filter and sort
+// the returned collection for greater efficiency.
func List(c *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
// Build query parameters
q := make(map[string]string)
@@ -61,11 +68,8 @@
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)
+ if opts.Marker != "" {
+ q["marker"] = opts.Marker
}
if opts.Limit != 0 {
q["limit"] = strconv.Itoa(opts.Limit)
@@ -77,15 +81,16 @@
q["sort_dir"] = opts.SortDir
}
- u := ListURL(c) + utils.BuildQuery(q)
+ u := listURL(c) + utils.BuildQuery(q)
return pagination.NewPager(c, u, func(r pagination.LastHTTPResponse) pagination.Page {
return NetworkPage{pagination.LinkedPageBase(r)}
})
}
+// Get retrieves a specific network based on its unique ID.
func Get(c *gophercloud.ServiceClient, id string) (*Network, error) {
var n Network
- _, err := perigee.Request("GET", GetURL(c, id), perigee.Options{
+ _, err := perigee.Request("GET", getURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
Results: &struct {
Network *Network `json:"network"`
@@ -98,13 +103,21 @@
return &n, nil
}
+// CreateOpts represents the attributes used when creating a new network.
type CreateOpts networkOpts
+// Create accepts a CreateOpts struct and creates a new network using the values
+// provided. This operation does not actually require a request body, i.e. the
+// CreateOpts struct argument can be empty.
+//
+// The tenant ID that is contained in the URI is the tenant that creates the
+// network. An admin user, however, has the option of specifying another tenant
+// ID in the CreateOpts struct.
func Create(c *gophercloud.ServiceClient, opts CreateOpts) (*NetworkCreateResult, error) {
// Define structures
type network struct {
- AdminStateUp bool `json:"admin_state_up"`
- Name string `json:"name"`
+ AdminStateUp bool `json:"admin_state_up,omitempty"`
+ Name string `json:"name,omitempty"`
Shared *bool `json:"shared,omitempty"`
TenantID *string `json:"tenant_id,omitempty"`
}
@@ -115,11 +128,6 @@
Network *NetworkCreateResult `json:"network"`
}
- // Validate
- if opts.Name == "" {
- return nil, ErrNameRequired
- }
-
// Populate request body
reqBody := request{Network: network{
AdminStateUp: opts.AdminStateUp,
@@ -133,7 +141,7 @@
// Send request to API
var res response
- _, err := perigee.Request("POST", CreateURL(c), perigee.Options{
+ _, err := perigee.Request("POST", createURL(c), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &res,
@@ -146,8 +154,11 @@
return res.Network, nil
}
+// UpdateOpts represents the attributes used when updating an existing network.
type UpdateOpts networkOpts
+// Update accepts a UpdateOpts struct and updates an existing network using the
+// values provided. For more information, see the Create function.
func Update(c *gophercloud.ServiceClient, networkID string, opts UpdateOpts) (*Network, error) {
// Define structures
type network struct {
@@ -172,7 +183,7 @@
// Send request to API
var res response
- _, err := perigee.Request("PUT", GetURL(c, networkID), perigee.Options{
+ _, err := perigee.Request("PUT", getURL(c, networkID), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
Results: &res,
@@ -185,8 +196,9 @@
return res.Network, nil
}
+// Delete accepts a unique ID and deletes the network associated with it.
func Delete(c *gophercloud.ServiceClient, networkID string) error {
- _, err := perigee.Request("DELETE", DeleteURL(c, networkID), perigee.Options{
+ _, err := perigee.Request("DELETE", deleteURL(c, networkID), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
OkCodes: []int{204},
})