Feature/filestorage sharenetworks list (#124)
* sfs: Add list for share networks
* sfs: Add acceptance tests for share network List
* sfs: Add more fields for filtering List requests
* sfs: Add pagination for share network List
* sfs: Change pagination to use MarkerPage
* sfs: Add acceptance tests for share network pagination
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/requests.go b/openstack/sharedfilesystems/v2/sharenetworks/requests.go
index ad29404..0c7c5d3 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/requests.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/requests.go
@@ -1,6 +1,9 @@
package sharenetworks
-import "github.com/gophercloud/gophercloud"
+import (
+ "github.com/gophercloud/gophercloud"
+ "github.com/gophercloud/gophercloud/pagination"
+)
// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
@@ -50,3 +53,66 @@
_, r.Err = client.Delete(deleteURL(client, id), nil)
return
}
+
+// ListOptsBuilder allows extensions to add additional parameters to the List
+// request.
+type ListOptsBuilder interface {
+ ToShareNetworkListQuery() (string, error)
+}
+
+// ListOpts holds options for listing ShareNetworks. It is passed to the
+// sharenetworks.List function.
+type ListOpts struct {
+ // admin-only option. Set it to true to see all tenant share networks.
+ AllTenants bool `q:"all_tenants"`
+ // The UUID of the project where the share network was created
+ ProjectID string `q:"project_id"`
+ // The neutron network ID
+ NeutronNetID string `q:"neutron_net_id"`
+ // The neutron subnet ID
+ NeutronSubnetID string `q:"neutron_subnet_id"`
+ // The nova network ID
+ NovaNetID string `q:"nova_net_id"`
+ // The network type. A valid value is VLAN, VXLAN, GRE or flat
+ NetworkType string `q:"network_type"`
+ // The Share Network name
+ Name string `q:"name"`
+ // The Share Network description
+ Description string `q:"description"`
+ // The Share Network IP version
+ IPVersion gophercloud.IPVersion `q:"ip_version"`
+ // The Share Network segmentation ID
+ SegmentationID int `q:"segmentation_id"`
+ // List all share networks created after the given date
+ CreatedSince string `q:"created_since"`
+ // List all share networks created before the given date
+ CreatedBefore string `q:"created_before"`
+ // Limit specifies the page size.
+ Limit int `q:"limit"`
+ // Limit specifies the page number.
+ Offset int `q:"offset"`
+}
+
+// ToShareNetworkListQuery formats a ListOpts into a query string.
+func (opts ListOpts) ToShareNetworkListQuery() (string, error) {
+ q, err := gophercloud.BuildQueryString(opts)
+ return q.String(), err
+}
+
+// ListDetail returns ShareNetworks optionally limited by the conditions provided in ListOpts.
+func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
+ url := listDetailURL(client)
+ if opts != nil {
+ query, err := opts.ToShareNetworkListQuery()
+ if err != nil {
+ return pagination.Pager{Err: err}
+ }
+ url += query
+ }
+
+ return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
+ p := ShareNetworkPage{pagination.MarkerPageBase{PageResult: r}}
+ p.MarkerPageBase.Owner = p
+ return p
+ })
+}